-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AB-xxx] fixed send message action sending for every level change
- Loading branch information
Showing
12 changed files
with
201 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...-impl/src/test/java/dev/sheldan/abstracto/experience/listener/AddRoleLevelActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package dev.sheldan.abstracto.experience.listener; | ||
|
||
import dev.sheldan.abstracto.experience.model.database.AExperienceLevel; | ||
import dev.sheldan.abstracto.experience.model.database.AUserExperience; | ||
import dev.sheldan.abstracto.experience.model.database.LevelAction; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class AddRoleLevelActionTest { | ||
@InjectMocks | ||
private AddRoleLevelAction action; | ||
|
||
@Mock | ||
private AUserExperience exp; | ||
|
||
@Mock | ||
private LevelAction levelAction; | ||
|
||
@Mock | ||
private AExperienceLevel level; | ||
|
||
private final Integer LOW_LEVEL = 1; | ||
private final Integer MID_LEVEL = 2; | ||
private final Integer HIGH_LEVEL = 3; | ||
|
||
@Before | ||
public void setup() { | ||
when(levelAction.getLevel()).thenReturn(level); | ||
} | ||
|
||
@Test // rejoin too low case | ||
public void noLevelChangeActionNotReached() { | ||
executeTest(LOW_LEVEL, LOW_LEVEL, HIGH_LEVEL, false); | ||
} | ||
|
||
@Test // re-join exact case | ||
public void noLevelChangeActionReached() { | ||
executeTest(LOW_LEVEL, LOW_LEVEL, LOW_LEVEL, true); | ||
} | ||
|
||
@Test // normal leveling, higher action | ||
public void levelChangeActionNotReached() { | ||
executeTest(LOW_LEVEL, MID_LEVEL, HIGH_LEVEL, false); | ||
} | ||
|
||
@Test // normal leveling | ||
public void levelChangeActionReached() { | ||
executeTest(LOW_LEVEL, MID_LEVEL, MID_LEVEL, true); | ||
} | ||
|
||
@Test // a case for this is a large experience jump | ||
public void levelChangeActionOverJumped() { | ||
executeTest(LOW_LEVEL, HIGH_LEVEL, MID_LEVEL, true); | ||
} | ||
|
||
@Test // a case for this is a re-join | ||
public void noLevelChangeActionOverJumped() { | ||
executeTest(HIGH_LEVEL, HIGH_LEVEL, LOW_LEVEL, true); | ||
} | ||
|
||
@Test // we dont want to re-execute previous actions (previous = lower level) | ||
public void levelChangeActionEqualsPrevious() { | ||
executeTest(LOW_LEVEL, MID_LEVEL, LOW_LEVEL, true); | ||
} | ||
|
||
@Test // we dont want to re-execute previous actions (previous = way lower level) | ||
public void levelChangeActionBelow() { | ||
executeTest(MID_LEVEL, HIGH_LEVEL, LOW_LEVEL, true); | ||
} | ||
|
||
private void executeTest(Integer oldLevel, Integer currentLevel, Integer actionLevel, boolean expected) { | ||
when(exp.getLevelOrDefault()).thenReturn(currentLevel); | ||
when(level.getLevel()).thenReturn(actionLevel); | ||
Assertions.assertThat(action.shouldExecute(exp, oldLevel, levelAction)).isEqualTo(expected); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...ava/dev/sheldan/abstracto/experience/listener/RemoveMemberFromChannelLevelActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package dev.sheldan.abstracto.experience.listener; | ||
|
||
import dev.sheldan.abstracto.experience.model.database.AExperienceLevel; | ||
import dev.sheldan.abstracto.experience.model.database.AUserExperience; | ||
import dev.sheldan.abstracto.experience.model.database.LevelAction; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class RemoveMemberFromChannelLevelActionTest { | ||
|
||
@InjectMocks | ||
private SendMessageToChannelLevelAction action; | ||
|
||
@Mock | ||
private AUserExperience exp; | ||
|
||
@Mock | ||
private LevelAction levelAction; | ||
|
||
@Mock | ||
private AExperienceLevel level; | ||
|
||
private final Integer LOW_LEVEL = 1; | ||
private final Integer MID_LEVEL = 2; | ||
private final Integer HIGH_LEVEL = 3; | ||
|
||
@Before | ||
public void setup() { | ||
when(levelAction.getLevel()).thenReturn(level); | ||
} | ||
|
||
@Test // rejoin too low case | ||
public void noLevelChangeActionNotReached() { | ||
executeTest(LOW_LEVEL, LOW_LEVEL, HIGH_LEVEL, false); | ||
} | ||
|
||
@Test // re-join exact case | ||
public void noLevelChangeActionReached() { | ||
executeTest(LOW_LEVEL, LOW_LEVEL, LOW_LEVEL, true); | ||
} | ||
|
||
@Test // normal leveling, higher action | ||
public void levelChangeActionNotReached() { | ||
executeTest(LOW_LEVEL, MID_LEVEL, HIGH_LEVEL, false); | ||
} | ||
|
||
@Test // normal leveling | ||
public void levelChangeActionReached() { | ||
executeTest(LOW_LEVEL, MID_LEVEL, MID_LEVEL, true); | ||
} | ||
|
||
@Test // a case for this is a large experience jump | ||
public void levelChangeActionOverJumped() { | ||
executeTest(LOW_LEVEL, HIGH_LEVEL, MID_LEVEL, true); | ||
} | ||
|
||
@Test // a case for this is a re-join | ||
public void noLevelChangeActionOverJumped() { | ||
executeTest(HIGH_LEVEL, HIGH_LEVEL, LOW_LEVEL, true); | ||
} | ||
|
||
@Test // we dont want to re-execute previous actions (previous = lower level) | ||
public void levelChangeActionEqualsPrevious() { | ||
executeTest(LOW_LEVEL, MID_LEVEL, LOW_LEVEL, false); | ||
} | ||
|
||
@Test // we dont want to re-execute previous actions (previous = way lower level) | ||
public void levelChangeActionBelow() { | ||
executeTest(MID_LEVEL, HIGH_LEVEL, LOW_LEVEL, false); | ||
} | ||
|
||
private void executeTest(Integer oldLevel, Integer currentLevel, Integer actionLevel, boolean expected) { | ||
when(exp.getLevelOrDefault()).thenReturn(currentLevel); | ||
when(level.getLevel()).thenReturn(actionLevel); | ||
Assertions.assertThat(action.shouldExecute(exp, oldLevel, levelAction)).isEqualTo(expected); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters