-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from BME-MIT-IET/strategy_unit_test_david
Strategy unit test David
- Loading branch information
Showing
23 changed files
with
883 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package virologist.model.strategy; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import virologist.model.Virologist; | ||
import virologist.model.agents.Bear; | ||
import virologist.model.map.Field; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
import java.util.ArrayList; | ||
|
||
class BearMoveTest { | ||
private BearMove bearMove; | ||
private Virologist virologist; | ||
private Field from; | ||
private Field to; | ||
private Field randomNeighbour; | ||
private ArrayList<Field> neighbours; | ||
private ArrayList<Virologist> virologists; | ||
private Virologist virologist1; | ||
private Virologist virologist2; | ||
|
||
@BeforeEach | ||
public void init() { | ||
virologist = mock(Virologist.class); | ||
from = mock(Field.class); | ||
to = mock(Field.class); | ||
randomNeighbour = mock(Field.class); | ||
neighbours = new ArrayList<>(); | ||
neighbours.add(randomNeighbour); | ||
virologists = new ArrayList<>(); | ||
virologist1 = mock(Virologist.class); | ||
virologist2 = mock(Virologist.class); | ||
virologists.add(virologist1); | ||
virologists.add(virologist2); | ||
bearMove = new BearMove(randomNeighbour); | ||
} | ||
|
||
@Test | ||
void moveTest() { | ||
// Arrange | ||
when(from.GetNeighbours()).thenReturn(neighbours); | ||
when(randomNeighbour.GetVirologists()).thenReturn(virologists); | ||
|
||
// Act | ||
bearMove.Move(virologist, from, to); | ||
|
||
// Assert | ||
verify(from, times(1)).RemoveVirologist(virologist); | ||
verify(randomNeighbour, times(1)).AddVirologist(virologist); | ||
verify(randomNeighbour, times(1)).DestroyMaterial(); | ||
verify(virologist1, times(1)).TargetedWith(any(Bear.class)); | ||
verify(virologist2, times(1)).TargetedWith(any(Bear.class)); | ||
verify(virologist, times(1)).DecreaseActions(); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/test/java/virologist/model/strategy/DefAttackTest.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,30 @@ | ||
package virologist.model.strategy; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import virologist.model.Virologist; | ||
import static org.mockito.Mockito.*; | ||
|
||
class DefAttackTest { | ||
private DefAttack defAttack; | ||
private Virologist attacker; | ||
private Virologist target; | ||
|
||
@BeforeEach | ||
public void init() { | ||
defAttack = new DefAttack(); | ||
attacker = mock(Virologist.class); | ||
target = mock(Virologist.class); | ||
} | ||
|
||
@Test | ||
void attackTest() { | ||
// Arrange | ||
|
||
// Act | ||
defAttack.Attack(attacker, target); | ||
|
||
// Assert | ||
verify(attacker, times(1)).DecreaseActions(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/test/java/virologist/model/strategy/DefCollectTest.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,36 @@ | ||
package virologist.model.strategy; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import virologist.model.Virologist; | ||
import virologist.model.map.Field; | ||
|
||
class DefCollectTest { | ||
private DefCollect defCollect; | ||
private Virologist virologist; | ||
private Field field; | ||
|
||
@BeforeEach | ||
public void init() { | ||
defCollect = new DefCollect(); | ||
virologist = mock(Virologist.class); | ||
field = mock(Field.class); | ||
} | ||
|
||
@Test | ||
void collectTest() { | ||
// Arrange | ||
|
||
// Act | ||
defCollect.Collect(virologist, field); | ||
|
||
// Assert | ||
verify(field, times(1)).CollectMaterial(virologist); | ||
verify(virologist, times(1)).DecreaseActions(); | ||
} | ||
} |
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,41 @@ | ||
package virologist.model.strategy; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import virologist.model.Virologist; | ||
import virologist.model.equipments.Equipment; | ||
import virologist.model.map.Field; | ||
|
||
class DefDropTest { | ||
private DefDrop defDrop; | ||
private Virologist virologist; | ||
private Field field; | ||
private Equipment equipment; | ||
|
||
@BeforeEach | ||
public void init() { | ||
defDrop = new DefDrop(); | ||
virologist = mock(Virologist.class); | ||
field = mock(Field.class); | ||
equipment = mock(Equipment.class); | ||
} | ||
|
||
@Test | ||
void dropTest() { | ||
// Arrange | ||
|
||
// Act | ||
defDrop.Drop(virologist, field, equipment); | ||
|
||
// Assert | ||
verify(equipment, times(1)).Disable(virologist); | ||
verify(field, times(1)).Drop(equipment); | ||
verify(virologist, times(1)).Reset(); | ||
verify(virologist, times(1)).DecreaseActions(); | ||
} | ||
} |
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,36 @@ | ||
package virologist.model.strategy; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import virologist.model.Virologist; | ||
import virologist.model.map.Field; | ||
|
||
class DefEquipTest { | ||
private DefEquip defEquip; | ||
private Virologist virologist; | ||
private Field field; | ||
|
||
@BeforeEach | ||
public void init() { | ||
defEquip = new DefEquip(); | ||
virologist = mock(Virologist.class); | ||
field = mock(Field.class); | ||
} | ||
|
||
@Test | ||
void equipTest() { | ||
// Arrange | ||
|
||
// Act | ||
defEquip.Equip(virologist, field); | ||
|
||
// Assert | ||
(verify(field, times(1))).PickUpEquipment(virologist); | ||
verify(virologist, times(1)).DecreaseActions(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/test/java/virologist/model/strategy/DefInjectTest.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,58 @@ | ||
package virologist.model.strategy; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import virologist.model.Virologist; | ||
import virologist.model.agents.Agent; | ||
import virologist.model.codes.GeneticCode; | ||
|
||
class DefInjectTest { | ||
private DefInject defInject; | ||
private Virologist attacker; | ||
private Virologist target; | ||
private GeneticCode geneticCode; | ||
private Agent agent; | ||
|
||
@BeforeEach | ||
public void init() { | ||
defInject = new DefInject(); | ||
attacker = mock(Virologist.class); | ||
target = mock(Virologist.class); | ||
geneticCode = mock(GeneticCode.class); | ||
agent = mock(Agent.class); | ||
} | ||
|
||
@Test | ||
void injectTest_enough_material() throws Exception { | ||
// Arrange | ||
doNothing().when(target).TargetedWith(attacker, agent); | ||
when(geneticCode.Create(attacker)).thenReturn(agent); | ||
|
||
// Act and Assert | ||
assertDoesNotThrow(() -> defInject.Inject(attacker, target, geneticCode)); | ||
verify(attacker, times(1)).DecreaseActions(); | ||
verify(geneticCode, times(1)).Create(attacker); | ||
verify(target, times(1)).TargetedWith(attacker, agent); | ||
} | ||
|
||
@Test | ||
void injectTest_not_enough_material() throws Exception { | ||
// Arrange | ||
doThrow(new Exception("I don't have enough material!")).when(geneticCode).Create(attacker); | ||
|
||
// Act and Assert | ||
assertDoesNotThrow(() -> defInject.Inject(attacker, target, geneticCode)); | ||
verify(attacker, times(1)).DecreaseActions(); | ||
verify(geneticCode, times(1)).Create(attacker); | ||
verify(target, times(0)).TargetedWith(attacker, agent); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/test/java/virologist/model/strategy/DefInjectedTest.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,48 @@ | ||
package virologist.model.strategy; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import virologist.model.Virologist; | ||
import virologist.model.agents.Agent; | ||
import static org.mockito.Mockito.*; | ||
|
||
class DefInjectedTest { | ||
private DefInjected defInjected; | ||
private Virologist by; | ||
private Virologist injected; | ||
private Agent agent; | ||
|
||
@BeforeEach | ||
public void init() { | ||
defInjected = new DefInjected(); | ||
by = mock(Virologist.class); | ||
injected = mock(Virologist.class); | ||
agent = mock(Agent.class); | ||
} | ||
|
||
@Test | ||
void injectedTestSelf() { | ||
// Arrange | ||
|
||
// Act | ||
defInjected.Injected(injected, agent); | ||
|
||
// Assert | ||
verify(agent, times(1)).Apply(injected); | ||
verify(injected, times(1)).AddAgent(agent); | ||
verify(agent, times(1)).ApplyStrategy(injected); | ||
} | ||
|
||
@Test | ||
void injectedTestBy() { | ||
// Arrange | ||
|
||
// Act | ||
defInjected.Injected(by, injected, agent); | ||
|
||
// Assert | ||
verify(agent, times(1)).Apply(injected); | ||
verify(injected, times(1)).AddAgent(agent); | ||
verify(agent, times(1)).ApplyStrategy(injected); | ||
} | ||
} |
Oops, something went wrong.