@Test public void activateVehicleTest() throws Exception { // When vehicle.activate(); // Then List<Event> events = vehicle.getPendingEvents(); assertTrue(events.size() == 1); assertTrue(events.get(0).equals(new Activated(vehicle.id))); }
@Test(expected = IllegalStateException.class) public void activateActiveVehicle() throws Exception { // Given vehicle.applyEvent(new Activated(vehicle.id)); // When vehicle.activate(); // Should throw IllegalStateException }
@Test public void moveActiveVehicleTest() throws Exception { // Given vehicle.applyEvent(new Activated(vehicle.id)); // When vehicle.changeLocation(1f, 1f); // Then List<Event> events = vehicle.getPendingEvents(); assertTrue(events.size() == 2); assertTrue(events.get(1).equals(new LocationChanged(1f, 1f))); }
@Test(expected = IllegalStateException.class) public void moveInactiveVehicleTest() throws Exception { // When vehicle.changeLocation(1f, 1f); // Should throw IllegalStateException }
// ex09 test @Test public void testGetMaxID() { // setup Vehicle vehicle1 = new Vehicle(); Vehicle vehicle2 = new Vehicle(); // execute int actual = Vehicle.getMaxID(); // test assertEquals(1, actual); }
@Test public void testTurnBoolean() { // setup Vehicle vehicle = new Vehicle(); vehicle.setAngle(0); vehicle.setOwner("hoge"); vehicle.setSpeed(60); // execute vehicle.turn(Vehicle.TURN_LEFT); double actual = vehicle.getAngle(); // test assertEquals(90.0, actual, 0.1); }
@Test public void testStop() { // setup Vehicle vehicle = new Vehicle(); vehicle.setAngle(0); vehicle.setOwner("hoge"); vehicle.setSpeed(60); // execute vehicle.stop(); double actual = vehicle.getSpeed(); // test assertTrue(0.0 == actual); }
// ex15 test @Test public void testChangeSpeed() { // setup Vehicle vehicle = new Vehicle(); vehicle.setAngle(0); vehicle.setOwner("hoge"); vehicle.setSpeed(60); // execute vehicle.changeSpeed(12.34); double actual = vehicle.getSpeed(); // test assertEquals(12.34, actual, 0.01); }
// gasがない場合startできない @Test public void startTestZeroGas() { Vehicle v1 = new Vehicle(0, 10); assertFalse(v1.start()); }
// 両方ある場合startできる @Test public void startTest() { Vehicle v1 = new Vehicle(10, 10); assertTrue(v1.start()); }
// batteryがない場合startできない @Test public void startTestzeroBattery() { Vehicle v1 = new Vehicle(10, 0); assertFalse(v1.start()); }