Skip to content

Commit

Permalink
Use JUnit4 style for all tests
Browse files Browse the repository at this point in the history
Prior to this commit the tests had a mixture of JUnit4 and JUnit3 style
of writing. With this commit all tests are using JUnit4 style with
annotations.

With this commit the Spring part has also been polished to use the
updated runner and cleanup the tests to remove the deprecation warnings
due to deprecated annotations.
  • Loading branch information
mdeinum committed Dec 1, 2017
1 parent 410b1e9 commit 7384bde
Show file tree
Hide file tree
Showing 34 changed files with 560 additions and 317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import org.openqa.selenium.WebDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriverBuilder;
import org.springframework.web.context.WebApplicationContext;

import se.citerus.dddsample.Application;

@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public abstract class AbstractAcceptanceTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
package se.citerus.dddsample.application;

import junit.framework.TestCase;
import static org.assertj.core.api.Assertions.assertThat;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.isA;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static se.citerus.dddsample.domain.model.location.SampleLocations.CHICAGO;
import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;

import java.util.Date;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import se.citerus.dddsample.application.impl.BookingServiceImpl;
import se.citerus.dddsample.domain.model.cargo.Cargo;
import se.citerus.dddsample.domain.model.cargo.CargoRepository;
Expand All @@ -9,27 +23,22 @@
import se.citerus.dddsample.domain.model.location.UnLocode;
import se.citerus.dddsample.domain.service.RoutingService;

import java.util.Date;

import static org.assertj.core.api.Assertions.assertThat;
import static org.easymock.EasyMock.*;
import static se.citerus.dddsample.domain.model.location.SampleLocations.CHICAGO;
import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;

public class BookingServiceTest extends TestCase {
public class BookingServiceTest {

BookingServiceImpl bookingService;
CargoRepository cargoRepository;
LocationRepository locationRepository;
RoutingService routingService;

protected void setUp() throws Exception {
@Before
public void setUp() {
cargoRepository = createMock(CargoRepository.class);
locationRepository = createMock(LocationRepository.class);
routingService = createMock(RoutingService.class);
bookingService = new BookingServiceImpl(cargoRepository, locationRepository, routingService);
}

@Test
public void testRegisterNew() {
TrackingId expectedTrackingId = new TrackingId("TRK1");
UnLocode fromUnlocode = new UnLocode("USCHI");
Expand All @@ -47,7 +56,8 @@ public void testRegisterNew() {
assertThat(trackingId).isEqualTo(expectedTrackingId);
}

protected void tearDown() throws Exception {
@After
public void tearDown() {
verify(cargoRepository, locationRepository);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
package se.citerus.dddsample.application;

import junit.framework.TestCase;
import static org.easymock.EasyMock.*;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.isA;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static se.citerus.dddsample.domain.model.location.SampleLocations.HAMBURG;
import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
import static se.citerus.dddsample.domain.model.location.SampleLocations.TOKYO;
import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;

import java.util.Date;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import se.citerus.dddsample.application.impl.HandlingEventServiceImpl;
import se.citerus.dddsample.domain.model.cargo.Cargo;
import se.citerus.dddsample.domain.model.cargo.CargoRepository;
Expand All @@ -11,13 +25,9 @@
import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
import se.citerus.dddsample.domain.model.location.LocationRepository;
import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
import se.citerus.dddsample.domain.model.voyage.VoyageRepository;

import java.util.Date;

public class HandlingEventServiceTest extends TestCase {
public class HandlingEventServiceTest {
private HandlingEventServiceImpl service;
private ApplicationEvents applicationEvents;
private CargoRepository cargoRepository;
Expand All @@ -27,7 +37,8 @@ public class HandlingEventServiceTest extends TestCase {

private final Cargo cargo = new Cargo(new TrackingId("ABC"), new RouteSpecification(HAMBURG, TOKYO, new Date()));

protected void setUp() throws Exception{
@Before
public void setUp() {
cargoRepository = createMock(CargoRepository.class);
voyageRepository = createMock(VoyageRepository.class);
handlingEventRepository = createMock(HandlingEventRepository.class);
Expand All @@ -38,10 +49,12 @@ protected void setUp() throws Exception{
service = new HandlingEventServiceImpl(handlingEventRepository, applicationEvents, handlingEventFactory);
}

protected void tearDown() throws Exception {
@After
public void tearDown() {
verify(cargoRepository, voyageRepository, handlingEventRepository, applicationEvents);
}

@Test
public void testRegisterEvent() throws Exception {
expect(cargoRepository.find(cargo.trackingId())).andReturn(cargo);
expect(voyageRepository.find(CM001.voyageNumber())).andReturn(CM001);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,47 @@
package se.citerus.dddsample.domain.model.cargo;

import junit.framework.TestCase;
import static org.assertj.core.api.Assertions.assertThat;
import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.MISROUTED;
import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.NOT_ROUTED;
import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.ROUTED;
import static se.citerus.dddsample.domain.model.cargo.TransportStatus.NOT_RECEIVED;
import static se.citerus.dddsample.domain.model.location.SampleLocations.GOTHENBURG;
import static se.citerus.dddsample.domain.model.location.SampleLocations.HAMBURG;
import static se.citerus.dddsample.domain.model.location.SampleLocations.HANGZOU;
import static se.citerus.dddsample.domain.model.location.SampleLocations.HONGKONG;
import static se.citerus.dddsample.domain.model.location.SampleLocations.MELBOURNE;
import static se.citerus.dddsample.domain.model.location.SampleLocations.NEWYORK;
import static se.citerus.dddsample.domain.model.location.SampleLocations.ROTTERDAM;
import static se.citerus.dddsample.domain.model.location.SampleLocations.SHANGHAI;
import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
import static se.citerus.dddsample.domain.model.location.SampleLocations.TOKYO;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import se.citerus.dddsample.application.util.DateTestUtil;
import se.citerus.dddsample.domain.model.handling.HandlingEvent;
import se.citerus.dddsample.domain.model.handling.HandlingHistory;
import se.citerus.dddsample.domain.model.location.Location;
import se.citerus.dddsample.domain.model.voyage.Voyage;
import se.citerus.dddsample.domain.model.voyage.VoyageNumber;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import static org.assertj.core.api.Assertions.assertThat;
import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.*;
import static se.citerus.dddsample.domain.model.cargo.TransportStatus.NOT_RECEIVED;
import static se.citerus.dddsample.domain.model.location.SampleLocations.*;

public class CargoTest extends TestCase {
public class CargoTest {

private List<HandlingEvent> events;
private Voyage voyage;

protected void setUp() throws Exception {
@Before
public void setUp() {
events = new ArrayList<HandlingEvent>();

voyage = new Voyage.Builder(new VoyageNumber("0123"), STOCKHOLM).
Expand All @@ -33,7 +51,8 @@ protected void setUp() throws Exception {
build();
}

public void testConstruction() throws Exception {
@Test
public void testConstruction() {
final TrackingId trackingId = new TrackingId("XYZ");
final Date arrivalDeadline = DateTestUtil.toDate("2009-03-13");
final RouteSpecification routeSpecification = new RouteSpecification(
Expand All @@ -48,7 +67,8 @@ public void testConstruction() throws Exception {
assertThat(cargo.delivery().currentVoyage()).isEqualTo(Voyage.NONE);
}

public void testRoutingStatus() throws Exception {
@Test
public void testRoutingStatus() {
final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
final Itinerary good = new Itinerary();
final Itinerary bad = new Itinerary();
Expand All @@ -70,37 +90,43 @@ public boolean isSatisfiedBy(Itinerary itinerary) {
assertThat(cargo.delivery().routingStatus()).isEqualTo(ROUTED);
}

public void testlastKnownLocationUnknownWhenNoEvents() throws Exception {
@Test
public void testlastKnownLocationUnknownWhenNoEvents() {
Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));

assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(Location.UNKNOWN);
}

@Test
public void testlastKnownLocationReceived() throws Exception {
Cargo cargo = populateCargoReceivedStockholm();

assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(STOCKHOLM);
}

@Test
public void testlastKnownLocationClaimed() throws Exception {
Cargo cargo = populateCargoClaimedMelbourne();

assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(MELBOURNE);
}

@Test
public void testlastKnownLocationUnloaded() throws Exception {
Cargo cargo = populateCargoOffHongKong();

assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(HONGKONG);
}

@Test
public void testlastKnownLocationloaded() throws Exception {
Cargo cargo = populateCargoOnHamburg();

assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(HAMBURG);
}

public void testEquality() throws Exception {
@Test
public void testEquality() {
RouteSpecification spec1 = new RouteSpecification(STOCKHOLM, HONGKONG, new Date());
RouteSpecification spec2 = new RouteSpecification(STOCKHOLM, MELBOURNE, new Date());
Cargo c1 = new Cargo(new TrackingId("ABC"), spec1);
Expand All @@ -114,7 +140,8 @@ public void testEquality() throws Exception {
assertThat(c1.equals(c2)).as("Cargos are not equal when TrackingID differ").isFalse();
}

public void testIsUnloadedAtFinalDestination() throws Exception {
@Test
public void testIsUnloadedAtFinalDestination() {
Cargo cargo = setUpCargoWithItinerary(HANGZOU, TOKYO, NEWYORK);
assertThat(cargo.delivery().isUnloadedAtDestination()).isFalse();

Expand Down Expand Up @@ -223,7 +250,8 @@ private Cargo populateCargoOnHongKong() throws Exception {
return cargo;
}

public void testIsMisdirected() throws Exception {
@Test
public void testIsMisdirected() {
//A cargo with no itinerary is not misdirected
Cargo cargo = new Cargo(new TrackingId("TRKID"), new RouteSpecification(SHANGHAI, GOTHENBURG, new Date()));
assertThat(cargo.delivery().isMisdirected()).isFalse();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package se.citerus.dddsample.domain.model.cargo;

import junit.framework.TestCase;

import java.util.Date;

import static org.assertj.core.api.Assertions.assertThat;
import static se.citerus.dddsample.domain.model.location.SampleLocations.HONGKONG;
import static se.citerus.dddsample.domain.model.location.SampleLocations.NEWYORK;

public class DeliveryTest extends TestCase {
import java.util.Date;

import org.junit.Test;

public class DeliveryTest {

private Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(HONGKONG, NEWYORK, new Date()));

public void testToSilenceWarnings() throws Exception {
@Test
public void testToSilenceWarnings() {
assertThat(true).isTrue();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
package se.citerus.dddsample.domain.model.cargo;

import junit.framework.TestCase;
import se.citerus.dddsample.domain.model.handling.HandlingEvent;
import se.citerus.dddsample.domain.model.voyage.CarrierMovement;
import se.citerus.dddsample.domain.model.voyage.Voyage;
import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static se.citerus.dddsample.domain.model.location.SampleLocations.GOTHENBURG;
import static se.citerus.dddsample.domain.model.location.SampleLocations.HANGZOU;
import static se.citerus.dddsample.domain.model.location.SampleLocations.HELSINKI;
import static se.citerus.dddsample.domain.model.location.SampleLocations.NEWYORK;
import static se.citerus.dddsample.domain.model.location.SampleLocations.ROTTERDAM;
import static se.citerus.dddsample.domain.model.location.SampleLocations.SHANGHAI;
import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
import org.junit.Before;
import org.junit.Test;

public class ItineraryTest extends TestCase {
import se.citerus.dddsample.domain.model.handling.HandlingEvent;
import se.citerus.dddsample.domain.model.voyage.CarrierMovement;
import se.citerus.dddsample.domain.model.voyage.Voyage;
import se.citerus.dddsample.domain.model.voyage.VoyageNumber;

public class ItineraryTest {
private final CarrierMovement abc = new CarrierMovement(SHANGHAI, ROTTERDAM, new Date(), new Date());
private final CarrierMovement def = new CarrierMovement(ROTTERDAM, GOTHENBURG, new Date(), new Date());
private final CarrierMovement ghi = new CarrierMovement(ROTTERDAM, NEWYORK, new Date(), new Date());
private final CarrierMovement jkl = new CarrierMovement(SHANGHAI, HELSINKI, new Date(), new Date());

Voyage voyage, wrongVoyage;

protected void setUp() throws Exception {
@Before
public void setUp() {
voyage = new Voyage.Builder(new VoyageNumber("0123"), SHANGHAI).
addMovement(ROTTERDAM, new Date(), new Date()).
addMovement(GOTHENBURG, new Date(), new Date()).
Expand All @@ -34,7 +44,8 @@ protected void setUp() throws Exception {
build();
}

public void testCargoOnTrack() throws Exception {
@Test
public void testCargoOnTrack() {

TrackingId trackingId = new TrackingId("CARGO1");
RouteSpecification routeSpecification = new RouteSpecification(SHANGHAI, GOTHENBURG, new Date());
Expand Down Expand Up @@ -86,14 +97,14 @@ public void testCargoOnTrack() throws Exception {
assertThat(itinerary.isExpected(event)).isFalse();

}

public void testNextExpectedEvent() throws Exception {
@Test
public void testNextExpectedEvent() {

}

public void testCreateItinerary() throws Exception {
@Test
public void testCreateItinerary() {
try {
new Itinerary(new ArrayList<Leg>());
new Itinerary(new ArrayList<>());
fail("An empty itinerary is not OK");
} catch (IllegalArgumentException iae) {
//Expected
Expand Down
Loading

0 comments on commit 7384bde

Please sign in to comment.