Skip to content

Commit 7384bde

Browse files
committed
Use JUnit4 style for all tests
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.
1 parent 410b1e9 commit 7384bde

34 files changed

+560
-317
lines changed

src/test/java/se/citerus/dddsample/acceptance/AbstractAcceptanceTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
import org.openqa.selenium.WebDriver;
77
import org.springframework.beans.factory.annotation.Autowired;
88
import org.springframework.boot.test.context.SpringBootTest;
9-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9+
import org.springframework.test.context.junit4.SpringRunner;
1010
import org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriverBuilder;
1111
import org.springframework.web.context.WebApplicationContext;
12+
1213
import se.citerus.dddsample.Application;
1314

14-
@RunWith(SpringJUnit4ClassRunner.class)
15+
@RunWith(SpringRunner.class)
1516
@SpringBootTest(classes = Application.class)
1617
public abstract class AbstractAcceptanceTest {
1718

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
package se.citerus.dddsample.application;
22

3-
import junit.framework.TestCase;
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.easymock.EasyMock.createMock;
5+
import static org.easymock.EasyMock.expect;
6+
import static org.easymock.EasyMock.isA;
7+
import static org.easymock.EasyMock.replay;
8+
import static org.easymock.EasyMock.verify;
9+
import static se.citerus.dddsample.domain.model.location.SampleLocations.CHICAGO;
10+
import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
11+
12+
import java.util.Date;
13+
14+
import org.junit.After;
15+
import org.junit.Before;
16+
import org.junit.Test;
17+
418
import se.citerus.dddsample.application.impl.BookingServiceImpl;
519
import se.citerus.dddsample.domain.model.cargo.Cargo;
620
import se.citerus.dddsample.domain.model.cargo.CargoRepository;
@@ -9,27 +23,22 @@
923
import se.citerus.dddsample.domain.model.location.UnLocode;
1024
import se.citerus.dddsample.domain.service.RoutingService;
1125

12-
import java.util.Date;
13-
14-
import static org.assertj.core.api.Assertions.assertThat;
15-
import static org.easymock.EasyMock.*;
16-
import static se.citerus.dddsample.domain.model.location.SampleLocations.CHICAGO;
17-
import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
18-
19-
public class BookingServiceTest extends TestCase {
26+
public class BookingServiceTest {
2027

2128
BookingServiceImpl bookingService;
2229
CargoRepository cargoRepository;
2330
LocationRepository locationRepository;
2431
RoutingService routingService;
2532

26-
protected void setUp() throws Exception {
33+
@Before
34+
public void setUp() {
2735
cargoRepository = createMock(CargoRepository.class);
2836
locationRepository = createMock(LocationRepository.class);
2937
routingService = createMock(RoutingService.class);
3038
bookingService = new BookingServiceImpl(cargoRepository, locationRepository, routingService);
3139
}
3240

41+
@Test
3342
public void testRegisterNew() {
3443
TrackingId expectedTrackingId = new TrackingId("TRK1");
3544
UnLocode fromUnlocode = new UnLocode("USCHI");
@@ -47,7 +56,8 @@ public void testRegisterNew() {
4756
assertThat(trackingId).isEqualTo(expectedTrackingId);
4857
}
4958

50-
protected void tearDown() throws Exception {
59+
@After
60+
public void tearDown() {
5161
verify(cargoRepository, locationRepository);
5262
}
5363
}

src/test/java/se/citerus/dddsample/application/HandlingEventServiceTest.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
package se.citerus.dddsample.application;
22

3-
import junit.framework.TestCase;
4-
import static org.easymock.EasyMock.*;
3+
import static org.easymock.EasyMock.createMock;
4+
import static org.easymock.EasyMock.expect;
5+
import static org.easymock.EasyMock.isA;
6+
import static org.easymock.EasyMock.replay;
7+
import static org.easymock.EasyMock.verify;
8+
import static se.citerus.dddsample.domain.model.location.SampleLocations.HAMBURG;
9+
import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
10+
import static se.citerus.dddsample.domain.model.location.SampleLocations.TOKYO;
11+
import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
12+
13+
import java.util.Date;
14+
15+
import org.junit.After;
16+
import org.junit.Before;
17+
import org.junit.Test;
18+
519
import se.citerus.dddsample.application.impl.HandlingEventServiceImpl;
620
import se.citerus.dddsample.domain.model.cargo.Cargo;
721
import se.citerus.dddsample.domain.model.cargo.CargoRepository;
@@ -11,13 +25,9 @@
1125
import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
1226
import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
1327
import se.citerus.dddsample.domain.model.location.LocationRepository;
14-
import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
15-
import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
1628
import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
1729

18-
import java.util.Date;
19-
20-
public class HandlingEventServiceTest extends TestCase {
30+
public class HandlingEventServiceTest {
2131
private HandlingEventServiceImpl service;
2232
private ApplicationEvents applicationEvents;
2333
private CargoRepository cargoRepository;
@@ -27,7 +37,8 @@ public class HandlingEventServiceTest extends TestCase {
2737

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

30-
protected void setUp() throws Exception{
40+
@Before
41+
public void setUp() {
3142
cargoRepository = createMock(CargoRepository.class);
3243
voyageRepository = createMock(VoyageRepository.class);
3344
handlingEventRepository = createMock(HandlingEventRepository.class);
@@ -38,10 +49,12 @@ protected void setUp() throws Exception{
3849
service = new HandlingEventServiceImpl(handlingEventRepository, applicationEvents, handlingEventFactory);
3950
}
4051

41-
protected void tearDown() throws Exception {
52+
@After
53+
public void tearDown() {
4254
verify(cargoRepository, voyageRepository, handlingEventRepository, applicationEvents);
4355
}
4456

57+
@Test
4558
public void testRegisterEvent() throws Exception {
4659
expect(cargoRepository.find(cargo.trackingId())).andReturn(cargo);
4760
expect(voyageRepository.find(CM001.voyageNumber())).andReturn(CM001);

src/test/java/se/citerus/dddsample/domain/model/cargo/CargoTest.java

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,47 @@
11
package se.citerus.dddsample.domain.model.cargo;
22

3-
import junit.framework.TestCase;
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.MISROUTED;
5+
import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.NOT_ROUTED;
6+
import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.ROUTED;
7+
import static se.citerus.dddsample.domain.model.cargo.TransportStatus.NOT_RECEIVED;
8+
import static se.citerus.dddsample.domain.model.location.SampleLocations.GOTHENBURG;
9+
import static se.citerus.dddsample.domain.model.location.SampleLocations.HAMBURG;
10+
import static se.citerus.dddsample.domain.model.location.SampleLocations.HANGZOU;
11+
import static se.citerus.dddsample.domain.model.location.SampleLocations.HONGKONG;
12+
import static se.citerus.dddsample.domain.model.location.SampleLocations.MELBOURNE;
13+
import static se.citerus.dddsample.domain.model.location.SampleLocations.NEWYORK;
14+
import static se.citerus.dddsample.domain.model.location.SampleLocations.ROTTERDAM;
15+
import static se.citerus.dddsample.domain.model.location.SampleLocations.SHANGHAI;
16+
import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
17+
import static se.citerus.dddsample.domain.model.location.SampleLocations.TOKYO;
18+
19+
import java.text.DateFormat;
20+
import java.text.ParseException;
21+
import java.text.SimpleDateFormat;
22+
import java.util.ArrayList;
23+
import java.util.Arrays;
24+
import java.util.Collection;
25+
import java.util.Date;
26+
import java.util.List;
27+
28+
import org.junit.Before;
29+
import org.junit.Test;
30+
431
import se.citerus.dddsample.application.util.DateTestUtil;
532
import se.citerus.dddsample.domain.model.handling.HandlingEvent;
633
import se.citerus.dddsample.domain.model.handling.HandlingHistory;
734
import se.citerus.dddsample.domain.model.location.Location;
835
import se.citerus.dddsample.domain.model.voyage.Voyage;
936
import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
1037

11-
import java.text.DateFormat;
12-
import java.text.ParseException;
13-
import java.text.SimpleDateFormat;
14-
import java.util.*;
15-
16-
import static org.assertj.core.api.Assertions.assertThat;
17-
import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.*;
18-
import static se.citerus.dddsample.domain.model.cargo.TransportStatus.NOT_RECEIVED;
19-
import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
20-
21-
public class CargoTest extends TestCase {
38+
public class CargoTest {
2239

2340
private List<HandlingEvent> events;
2441
private Voyage voyage;
2542

26-
protected void setUp() throws Exception {
43+
@Before
44+
public void setUp() {
2745
events = new ArrayList<HandlingEvent>();
2846

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

36-
public void testConstruction() throws Exception {
54+
@Test
55+
public void testConstruction() {
3756
final TrackingId trackingId = new TrackingId("XYZ");
3857
final Date arrivalDeadline = DateTestUtil.toDate("2009-03-13");
3958
final RouteSpecification routeSpecification = new RouteSpecification(
@@ -48,7 +67,8 @@ public void testConstruction() throws Exception {
4867
assertThat(cargo.delivery().currentVoyage()).isEqualTo(Voyage.NONE);
4968
}
5069

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

73-
public void testlastKnownLocationUnknownWhenNoEvents() throws Exception {
93+
@Test
94+
public void testlastKnownLocationUnknownWhenNoEvents() {
7495
Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
7596

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

100+
@Test
79101
public void testlastKnownLocationReceived() throws Exception {
80102
Cargo cargo = populateCargoReceivedStockholm();
81103

82104
assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(STOCKHOLM);
83105
}
84106

107+
@Test
85108
public void testlastKnownLocationClaimed() throws Exception {
86109
Cargo cargo = populateCargoClaimedMelbourne();
87110

88111
assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(MELBOURNE);
89112
}
90113

114+
@Test
91115
public void testlastKnownLocationUnloaded() throws Exception {
92116
Cargo cargo = populateCargoOffHongKong();
93117

94118
assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(HONGKONG);
95119
}
96120

121+
@Test
97122
public void testlastKnownLocationloaded() throws Exception {
98123
Cargo cargo = populateCargoOnHamburg();
99124

100125
assertThat(cargo.delivery().lastKnownLocation()).isEqualTo(HAMBURG);
101126
}
102127

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

117-
public void testIsUnloadedAtFinalDestination() throws Exception {
143+
@Test
144+
public void testIsUnloadedAtFinalDestination() {
118145
Cargo cargo = setUpCargoWithItinerary(HANGZOU, TOKYO, NEWYORK);
119146
assertThat(cargo.delivery().isUnloadedAtDestination()).isFalse();
120147

@@ -223,7 +250,8 @@ private Cargo populateCargoOnHongKong() throws Exception {
223250
return cargo;
224251
}
225252

226-
public void testIsMisdirected() throws Exception {
253+
@Test
254+
public void testIsMisdirected() {
227255
//A cargo with no itinerary is not misdirected
228256
Cargo cargo = new Cargo(new TrackingId("TRKID"), new RouteSpecification(SHANGHAI, GOTHENBURG, new Date()));
229257
assertThat(cargo.delivery().isMisdirected()).isFalse();

src/test/java/se/citerus/dddsample/domain/model/cargo/DeliveryTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package se.citerus.dddsample.domain.model.cargo;
22

3-
import junit.framework.TestCase;
4-
5-
import java.util.Date;
6-
73
import static org.assertj.core.api.Assertions.assertThat;
84
import static se.citerus.dddsample.domain.model.location.SampleLocations.HONGKONG;
95
import static se.citerus.dddsample.domain.model.location.SampleLocations.NEWYORK;
106

11-
public class DeliveryTest extends TestCase {
7+
import java.util.Date;
8+
9+
import org.junit.Test;
10+
11+
public class DeliveryTest {
1212

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

15-
public void testToSilenceWarnings() throws Exception {
15+
@Test
16+
public void testToSilenceWarnings() {
1617
assertThat(true).isTrue();
1718
}
1819

src/test/java/se/citerus/dddsample/domain/model/cargo/ItineraryTest.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11
package se.citerus.dddsample.domain.model.cargo;
22

3-
import junit.framework.TestCase;
4-
import se.citerus.dddsample.domain.model.handling.HandlingEvent;
5-
import se.citerus.dddsample.domain.model.voyage.CarrierMovement;
6-
import se.citerus.dddsample.domain.model.voyage.Voyage;
7-
import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.Assertions.fail;
5+
import static se.citerus.dddsample.domain.model.location.SampleLocations.GOTHENBURG;
6+
import static se.citerus.dddsample.domain.model.location.SampleLocations.HANGZOU;
7+
import static se.citerus.dddsample.domain.model.location.SampleLocations.HELSINKI;
8+
import static se.citerus.dddsample.domain.model.location.SampleLocations.NEWYORK;
9+
import static se.citerus.dddsample.domain.model.location.SampleLocations.ROTTERDAM;
10+
import static se.citerus.dddsample.domain.model.location.SampleLocations.SHANGHAI;
11+
import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
812

913
import java.util.ArrayList;
1014
import java.util.Arrays;
1115
import java.util.Date;
1216
import java.util.List;
1317

14-
import static org.assertj.core.api.Assertions.assertThat;
15-
import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
18+
import org.junit.Before;
19+
import org.junit.Test;
1620

17-
public class ItineraryTest extends TestCase {
21+
import se.citerus.dddsample.domain.model.handling.HandlingEvent;
22+
import se.citerus.dddsample.domain.model.voyage.CarrierMovement;
23+
import se.citerus.dddsample.domain.model.voyage.Voyage;
24+
import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
25+
26+
public class ItineraryTest {
1827
private final CarrierMovement abc = new CarrierMovement(SHANGHAI, ROTTERDAM, new Date(), new Date());
1928
private final CarrierMovement def = new CarrierMovement(ROTTERDAM, GOTHENBURG, new Date(), new Date());
2029
private final CarrierMovement ghi = new CarrierMovement(ROTTERDAM, NEWYORK, new Date(), new Date());
2130
private final CarrierMovement jkl = new CarrierMovement(SHANGHAI, HELSINKI, new Date(), new Date());
2231

2332
Voyage voyage, wrongVoyage;
2433

25-
protected void setUp() throws Exception {
34+
@Before
35+
public void setUp() {
2636
voyage = new Voyage.Builder(new VoyageNumber("0123"), SHANGHAI).
2737
addMovement(ROTTERDAM, new Date(), new Date()).
2838
addMovement(GOTHENBURG, new Date(), new Date()).
@@ -34,7 +44,8 @@ protected void setUp() throws Exception {
3444
build();
3545
}
3646

37-
public void testCargoOnTrack() throws Exception {
47+
@Test
48+
public void testCargoOnTrack() {
3849

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

8899
}
89-
90-
public void testNextExpectedEvent() throws Exception {
100+
@Test
101+
public void testNextExpectedEvent() {
91102

92103
}
93-
94-
public void testCreateItinerary() throws Exception {
104+
@Test
105+
public void testCreateItinerary() {
95106
try {
96-
new Itinerary(new ArrayList<Leg>());
107+
new Itinerary(new ArrayList<>());
97108
fail("An empty itinerary is not OK");
98109
} catch (IllegalArgumentException iae) {
99110
//Expected

0 commit comments

Comments
 (0)