Skip to content

Commit 1388a4d

Browse files
authored
Move from TestNG to JUnit 5 and AssertJ (#134)
This commit was mostly created via the conversion tool
1 parent e59082b commit 1388a4d

12 files changed

Lines changed: 319 additions & 254 deletions

File tree

modules/common/pom.xml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,23 @@
3636

3737
<!-- Testing -->
3838
<dependency>
39-
<groupId>org.testng</groupId>
40-
<artifactId>testng</artifactId>
39+
<groupId>org.junit.jupiter</groupId>
40+
<artifactId>junit-jupiter-api</artifactId>
41+
<scope>test</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.junit.jupiter</groupId>
45+
<artifactId>junit-jupiter-params</artifactId>
46+
<scope>test</scope>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.junit.jupiter</groupId>
50+
<artifactId>junit-jupiter-engine</artifactId>
51+
<scope>test</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.assertj</groupId>
55+
<artifactId>assertj-core</artifactId>
4156
<scope>test</scope>
4257
</dependency>
4358
<dependency>

modules/common/src/test/java/com/opengamma/sdk/common/BasicTest.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
package com.opengamma.sdk.common;
77

88
import static com.opengamma.sdk.common.ServiceInvoker.SERVICE_URL;
9-
import static org.testng.Assert.assertEquals;
10-
import static org.testng.Assert.assertFalse;
11-
import static org.testng.Assert.assertThrows;
12-
import static org.testng.Assert.assertTrue;
9+
import static org.assertj.core.api.Assertions.assertThat;
10+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
1311

14-
import org.testng.annotations.Test;
12+
import org.junit.jupiter.api.Test;
1513

1614
import com.opengamma.sdk.common.auth.AuthClient;
1715
import com.opengamma.sdk.common.auth.AuthenticationException;
@@ -23,62 +21,66 @@
2321
/**
2422
* Test.
2523
*/
26-
@Test
2724
public class BasicTest {
2825

2926
private static final Credentials CREDENTIALS = Credentials.ofApiKey("user", "pw");
3027
private static final Credentials BAD_CREDENTIALS = Credentials.ofApiKey("bad", "pw");
3128

29+
@Test
3230
public void testBasics() {
33-
assertThrows(NullPointerException.class, () -> ServiceInvoker.of(null));
31+
assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> ServiceInvoker.of(null));
3432
}
3533

34+
@Test
3635
public void testAuthGood() {
3736
AuthClient mockAuth = new TestingAuthClient();
3837
@SuppressWarnings("resource")
3938
ServiceInvoker invoker = ServiceInvoker.builder(CREDENTIALS)
4039
.authClientFactory(inv -> mockAuth)
4140
.build();
42-
assertEquals(invoker.getServiceUrl(), SERVICE_URL);
43-
assertEquals(invoker.getHttpClient().interceptors().size(), 4);
44-
assertTrue(invoker.getHttpClient().followRedirects());
45-
assertFalse(invoker.getExecutor().isShutdown());
41+
assertThat(invoker.getServiceUrl()).isEqualTo(SERVICE_URL);
42+
assertThat(invoker.getHttpClient().interceptors()).hasSize(4);
43+
assertThat(invoker.getHttpClient().followRedirects()).isTrue();
44+
assertThat(invoker.getExecutor().isShutdown()).isFalse();
4645
invoker.close();
47-
assertTrue(invoker.getExecutor().isShutdown());
46+
assertThat(invoker.getExecutor().isShutdown()).isTrue();
4847
}
4948

49+
@Test
5050
public void testAuthGoodHttpFactory() {
5151
AuthClient mockAuth = new TestingAuthClient();
5252
try (ServiceInvoker invoker = ServiceInvoker.builder(CREDENTIALS)
5353
.httpClientFactory(
5454
builder -> builder.addInterceptor(chain -> chain.proceed(chain.request())).followRedirects(false).build())
5555
.authClientFactory(inv -> mockAuth)
5656
.build()) {
57-
assertEquals(invoker.getServiceUrl(), SERVICE_URL);
58-
assertEquals(invoker.getHttpClient().interceptors().size(), 5); // logging, user-agent & auth& retry plus one from test
59-
assertFalse(invoker.getHttpClient().followRedirects());
57+
assertThat(invoker.getServiceUrl()).isEqualTo(SERVICE_URL);
58+
assertThat(invoker.getHttpClient().interceptors()).hasSize(5); // logging, user-agent & auth& retry plus one from test
59+
assertThat(invoker.getHttpClient().followRedirects()).isFalse();
6060
}
6161
}
6262

63+
@Test
6364
public void testAuthGoodHttpClient() {
6465
AuthClient mockAuth = new TestingAuthClient();
6566
try (ServiceInvoker invoker = ServiceInvoker.builder(CREDENTIALS)
6667
.httpClient(new OkHttpClient())
6768
.authClientFactory(inv -> mockAuth)
6869
.build()) {
69-
assertEquals(invoker.getServiceUrl(), SERVICE_URL);
70-
assertEquals(invoker.getHttpClient().interceptors().size(), 3); // user-agent & auth & retry
70+
assertThat(invoker.getServiceUrl()).isEqualTo(SERVICE_URL);
71+
assertThat(invoker.getHttpClient().interceptors()).hasSize(3); // user-agent & auth & retry
7172
}
7273
}
7374

75+
@Test
7476
public void testAuthBad() {
7577
AuthClient mockAuth = new TestingAuthClient();
7678
try (ServiceInvoker serviceInvoker = ServiceInvoker.builder(BAD_CREDENTIALS).authClientFactory(inv -> mockAuth).build()) {
7779
Request testRequest = new Request.Builder()
7880
.url(serviceInvoker.getServiceUrl().resolve("/test"))
7981
.get()
8082
.build();
81-
assertThrows(AuthenticationException.class, () -> serviceInvoker.getHttpClient().newCall(testRequest).execute());
83+
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() -> serviceInvoker.getHttpClient().newCall(testRequest).execute());
8284
}
8385
}
8486

modules/common/src/test/java/com/opengamma/sdk/common/ServiceInvokerTest.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
*/
66
package com.opengamma.sdk.common;
77

8-
import static org.testng.Assert.assertEquals;
9-
import static org.testng.Assert.assertTrue;
8+
import static org.assertj.core.api.Assertions.assertThat;
109

11-
import org.testng.annotations.AfterMethod;
12-
import org.testng.annotations.BeforeMethod;
13-
import org.testng.annotations.Test;
10+
import org.junit.jupiter.api.AfterEach;
11+
import org.junit.jupiter.api.BeforeEach;
12+
import org.junit.jupiter.api.Test;
1413

1514
import com.opengamma.sdk.common.auth.Credentials;
1615

@@ -23,12 +22,11 @@
2322
/**
2423
* Test {@link ServiceInvoker}.
2524
*/
26-
@Test
2725
public class ServiceInvokerTest {
2826

2927
private MockWebServer server;
3028

31-
@BeforeMethod
29+
@BeforeEach
3230
public void setUp() throws Exception {
3331
server = new MockWebServer();
3432
server.start(18080);
@@ -46,7 +44,7 @@ public void setUp() throws Exception {
4644
server.enqueue(new MockResponse().setResponseCode(200).setBody("{}"));
4745
}
4846

49-
@AfterMethod
47+
@AfterEach
5048
public void tearDown() throws Exception {
5149
server.shutdown();
5250
}
@@ -63,9 +61,9 @@ public void testNewRequestWithReauthenticationSequence() throws Exception {
6361
.get()
6462
.build();
6563
Response response = invoker.getHttpClient().newCall(request).execute();
66-
assertEquals(response.code(), 200);
67-
assertEquals(response.message(), "OK");
68-
assertTrue(response.isSuccessful());
64+
assertThat(response.code()).isEqualTo(200);
65+
assertThat(response.message()).isEqualTo("OK");
66+
assertThat(response.isSuccessful()).isTrue();
6967
}
7068
}
7169
}

modules/common/src/test/java/com/opengamma/sdk/common/VersionTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
*/
66
package com.opengamma.sdk.common;
77

8-
import static org.testng.Assert.assertFalse;
8+
import static org.assertj.core.api.Assertions.assertThat;
99

10-
import org.testng.annotations.Test;
10+
import org.junit.jupiter.api.Test;
1111

1212
/**
1313
* Test {@link Version}.
1414
*/
15-
@Test
1615
public class VersionTest {
1716

17+
@Test
1818
public void test_version() {
19-
assertFalse(Version.getVersionString().isEmpty());
19+
assertThat(Version.getVersionString().isEmpty()).isFalse();
2020
// this line fails when tests are run in IntelliJ (works in Eclipse)
2121
// assertEquals(Version.getVersionString().contains("$"), false);
2222
}

modules/margin/pom.xml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,23 @@
4242

4343
<!-- Testing -->
4444
<dependency>
45-
<groupId>org.testng</groupId>
46-
<artifactId>testng</artifactId>
45+
<groupId>org.junit.jupiter</groupId>
46+
<artifactId>junit-jupiter-api</artifactId>
47+
<scope>test</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.junit.jupiter</groupId>
51+
<artifactId>junit-jupiter-params</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.junit.jupiter</groupId>
56+
<artifactId>junit-jupiter-engine</artifactId>
57+
<scope>test</scope>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.assertj</groupId>
61+
<artifactId>assertj-core</artifactId>
4762
<scope>test</scope>
4863
</dependency>
4964
<dependency>

modules/margin/src/test/java/com/opengamma/sdk/margin/MarginCalcRequestTest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66
package com.opengamma.sdk.margin;
77

88
import static com.opengamma.sdk.margin.MarginCalcRequestType.PARSE_INPUTS;
9-
import static org.testng.Assert.assertEquals;
9+
import static org.assertj.core.api.Assertions.assertThat;
1010

1111
import java.nio.file.Paths;
1212
import java.time.LocalDate;
1313
import java.util.Arrays;
1414

15-
import org.testng.annotations.Test;
15+
import org.junit.jupiter.api.Test;
1616

1717
/**
1818
* Test.
1919
*/
20-
@Test
2120
public class MarginCalcRequestTest {
2221

2322
private static final LocalDate VAL_DATE = LocalDate.of(2017, 6, 1);
2423
private static final PortfolioDataFile PORTFOLIO =
2524
PortfolioDataFile.of(Paths.get("src/test/resources/lch-trades.txt"));
2625

2726
//-------------------------------------------------------------------------
27+
@Test
2828
@SuppressWarnings("deprecation")
2929
public void test_of3() {
3030
MarginCalcRequest test = MarginCalcRequest.of(VAL_DATE, "GBP", Arrays.asList(PORTFOLIO));
@@ -35,10 +35,11 @@ public void test_of3() {
3535
.reportingCurrency("GBP")
3636
.portfolioData(PORTFOLIO)
3737
.build();
38-
assertEquals(test, expected);
39-
assertEquals(test.getType(), MarginCalcRequestType.STANDARD);
38+
assertThat(test).isEqualTo(expected);
39+
assertThat(test.getType()).isEqualTo(MarginCalcRequestType.STANDARD);
4040
}
4141

42+
@Test
4243
@SuppressWarnings("deprecation")
4344
public void test_of4() {
4445
MarginCalcRequest test = MarginCalcRequest.of(VAL_DATE, "GBP", Arrays.asList(PORTFOLIO), "MYPARTY");
@@ -50,10 +51,11 @@ public void test_of4() {
5051
.portfolioData(PORTFOLIO)
5152
.fpmlPartySelectionRegex("MYPARTY")
5253
.build();
53-
assertEquals(test, expected);
54-
assertEquals(test.getType(), MarginCalcRequestType.STANDARD);
54+
assertThat(test).isEqualTo(expected);
55+
assertThat(test.getType()).isEqualTo(MarginCalcRequestType.STANDARD);
5556
}
5657

58+
@Test
5759
@SuppressWarnings("deprecation")
5860
public void test_of5() {
5961
MarginCalcRequest test = MarginCalcRequest.of(VAL_DATE, "GBP", Arrays.asList(PORTFOLIO), PARSE_INPUTS, true);
@@ -65,8 +67,8 @@ public void test_of5() {
6567
.applyClientMultiplier(true)
6668
.portfolioData(PORTFOLIO)
6769
.build();
68-
assertEquals(test, expected);
69-
assertEquals(test.getType(), MarginCalcRequestType.PARSE_INPUTS);
70+
assertThat(test).isEqualTo(expected);
71+
assertThat(test.getType()).isEqualTo(MarginCalcRequestType.PARSE_INPUTS);
7072
}
7173

7274
}

0 commit comments

Comments
 (0)