-
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 #33 from BME-MIT-IET/java_unit_test
java unit tests
- Loading branch information
Showing
5 changed files
with
153 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.jupiter.api.Test; | ||
import temalab.model.ControlPoint; | ||
import temalab.model.Position; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
||
public class ControlPointTest { | ||
@Test | ||
public void controlPointIdIsIncremental() { | ||
ControlPoint controlPoint1 = new ControlPoint(new Position(0, 0), 0, 0, null); | ||
ControlPoint controlPoint2 = new ControlPoint(new Position(0, 1), 0, 0, null); | ||
ControlPoint controlPoint3 = new ControlPoint(new Position(0, 2), 0, 0, null); | ||
Assert.assertTrue(controlPoint1.getId() != controlPoint3.getId()); | ||
Assert.assertTrue(controlPoint1.getId() != controlPoint2.getId()); | ||
Assert.assertTrue(controlPoint2.getId() != controlPoint3.getId()); | ||
assertNotEquals(controlPoint1.getId(), controlPoint3.getId()); | ||
assertNotEquals(controlPoint1.getId(), controlPoint2.getId()); | ||
assertNotEquals(controlPoint2.getId(), controlPoint3.getId()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
import org.junit.jupiter.api.Test; | ||
import temalab.model.Position; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
|
||
class PositionTest { | ||
private final Position p1 = new Position(-1, 2); | ||
private final Position p2 = new Position(3, 5); | ||
private final Position p3 = new Position(0, 2); | ||
|
||
@Test | ||
void test_inDistance_true() { | ||
assertTrue(p1.inDistance(p3, 2f)); | ||
} | ||
|
||
@Test | ||
void test_inDistance_false() { | ||
assertFalse(p1.inDistance(p2, 2f)); | ||
} | ||
|
||
@Test | ||
void test_isNeighbouring_true() { | ||
assertTrue(p1.isNeighbouring(p3)); | ||
} | ||
|
||
@Test | ||
void test_isNeighbouring_false() { | ||
assertFalse(p1.isNeighbouring(p2)); | ||
} | ||
} |
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,107 @@ | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import temalab.common.MainModel; | ||
import temalab.model.Field; | ||
import temalab.model.Position; | ||
import temalab.model.Team; | ||
import temalab.model.Unit; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class TeamTest { | ||
private Team team; | ||
|
||
@Mock | ||
private MainModel mockMainModel; | ||
@Mock | ||
private Unit mockUnit; | ||
@Mock | ||
private Position mockPos; | ||
@Mock | ||
private Field mockField; | ||
|
||
@BeforeEach | ||
public void init() { | ||
team = new Team("red", "", 100, mockMainModel); | ||
} | ||
|
||
@Test | ||
void test_addUnit_canAfford() { | ||
when(mockUnit.price()).thenReturn(40); | ||
team.addUnit(mockUnit); | ||
assertFalse(team.units().isEmpty()); | ||
} | ||
|
||
@Test | ||
void test_addUnit_canNotAfford() { | ||
when(mockUnit.price()).thenReturn(120); | ||
team.addUnit(mockUnit); | ||
assertTrue(team.units().isEmpty()); | ||
} | ||
|
||
void addMockUnitWithId(int id) { | ||
when(mockUnit.getUUID()).thenReturn(id); | ||
when(mockUnit.price()).thenReturn(40); | ||
team.addUnit((mockUnit)); | ||
} | ||
|
||
@Test | ||
void test_moveUnit_OK() { | ||
addMockUnitWithId(1); | ||
|
||
when(mockMainModel.getField(mockPos)).thenReturn(mockField); | ||
team.moveUnit(1, mockPos); | ||
verify(mockUnit, times(1)).move(mockField); | ||
} | ||
|
||
@Test | ||
void test_moveUnit_fieldMissing() { | ||
addMockUnitWithId(1); | ||
|
||
when(mockMainModel.getField(mockPos)).thenReturn(null); | ||
team.moveUnit(1, mockPos); | ||
verify(mockUnit, times(0)).move(mockField); | ||
} | ||
|
||
@Test | ||
void test_moveUnit_unitMissing() { | ||
addMockUnitWithId(1); | ||
|
||
when(mockMainModel.getField(mockPos)).thenReturn(mockField); | ||
team.moveUnit(2, mockPos); | ||
verify(mockUnit, times(0)).move(mockField); | ||
} | ||
|
||
@Test | ||
void test_fireUnit_OK() { | ||
addMockUnitWithId(1); | ||
|
||
when(mockMainModel.getField(any(Position.class))).thenReturn(mockField); | ||
team.fireUnit(1, mockPos); | ||
verify(mockUnit, times(1)).shoot(mockField); | ||
} | ||
|
||
@Test | ||
void test_fireUnit_fieldMissing() { | ||
addMockUnitWithId(1); | ||
|
||
when(mockMainModel.getField(any(Position.class))).thenReturn(null); | ||
team.fireUnit(1, mockPos); | ||
verify(mockUnit, times(0)).shoot(mockField); | ||
} | ||
|
||
@Test | ||
void test_fireUnit_unitMissing() { | ||
addMockUnitWithId(1); | ||
|
||
when(mockMainModel.getField(any(Position.class))).thenReturn(mockField); | ||
team.fireUnit(2, mockPos); | ||
verify(mockUnit, times(0)).shoot(mockField); | ||
} | ||
} |