Skip to content

Commit daba8b4

Browse files
authored
Junit5 migration (#16)
* Remove unused variables and thrown exception in ConfigurationIT Remove unnecessary throws from ServiceAndEventManagerIT.cleanup Fix badly used variable reassignment in AckManagerIT.getCurrentAckValueTest Remove all try-catches in AckManagerIT.java Remove all try-catches in ServiceAndEventManagerIT.java Use assertNotEquals in AckManagerIT.deleteAckTest instead of assertNotSame Fix unused test - Now in use Use assertDoesNotThrow in ServiceAndEventManagerIT.initialize instead of try-catch Remove duplicate property in AckManagerIT.java Update Apache Rat pattern and exclusions Run spotless:apply Update the copyright year and formatting Remove JUnit4 vintage-engine from dependencies Migrate JUnit4 assertions to JUnit5 in TokenManagerTests Migrate JUnit4 assertions to JUnit5 in SessionManagerTests Migrate JUnit4 assertions to JUnit5 in ConverterTests - Also includes minor enhancements to tests Migrate JUnit4 assertions to JUnit5 in ServiceAndEventManagerIT Fix tests in SendEventsIT Migrate JUnit4 assertions to JUnit5 in AckManagerIT * Delete empty file after rebase * Remove old JUnit 4 assertions - Removes the static imports - Changes the order of the assertion parameters to the new format with message being last * Fix the changed copyright in SyslogMessageSender - Noticed that the rebase container modifications to the copyright, so reverted those * Move import to correct position in SessionManagerTests after rebase
1 parent 95fce3f commit daba8b4

5 files changed

Lines changed: 116 additions & 135 deletions

File tree

pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,6 @@
173173
<version>${junit.version}</version>
174174
<scope>test</scope>
175175
</dependency>
176-
<dependency>
177-
<groupId>org.junit.vintage</groupId>
178-
<artifactId>junit-vintage-engine</artifactId>
179-
<version>${junit.version}</version>
180-
<scope>test</scope>
181-
</dependency>
182176
<dependency>
183177
<groupId>org.junit.jupiter</groupId>
184178
<artifactId>junit-jupiter-engine</artifactId>

src/test/java/com/teragrep/cfe_16/SessionManagerTests.java

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@
4747

4848
import com.teragrep.cfe_16.bo.Session;
4949
import com.teragrep.cfe_16.config.Configuration;
50+
import org.junit.jupiter.api.Assertions;
5051
import org.junit.jupiter.api.BeforeEach;
5152
import org.junit.jupiter.api.Test;
5253

53-
import static org.junit.Assert.*;
54-
5554
/*
5655
* Tests the functionality of SessionManager
5756
*/
@@ -80,35 +79,25 @@ public void createSessionAndGetItWithAuthTokenTest() {
8079

8180
Session session1 = sessionManager.createSession(authToken1);
8281
Session session2 = sessionManager.createSession(authToken2);
83-
assertSame(
84-
"Same session should be returned with the same authentication token", session1,
85-
sessionManager.getSession(authToken1)
86-
);
87-
assertSame(
88-
"Same session should be returned with the same authentication token", session2,
89-
sessionManager.getSession(authToken2)
90-
);
91-
assertNotSame(
92-
"Different session should be returned with a different authentication token", session1,
93-
sessionManager.getSession(authToken2)
94-
);
95-
assertNotSame(
96-
"Different session should be returned with a different authentication token", session2,
97-
sessionManager.getSession(authToken1)
98-
);
99-
assertNull(
100-
"Getting a session with an unused authentication token should return null",
101-
sessionManager.getSession(authToken3)
102-
);
82+
Assertions
83+
.assertSame(session1, sessionManager.getSession(authToken1), "Same session should be returned with the same authentication token");
84+
Assertions
85+
.assertSame(session2, sessionManager.getSession(authToken2), "Same session should be returned with the same authentication token");
86+
Assertions
87+
.assertNotSame(session1, sessionManager.getSession(authToken2), "Different session should be returned with a different authentication token");
88+
Assertions
89+
.assertNotSame(session2, sessionManager.getSession(authToken1), "Different session should be returned with a different authentication token");
90+
Assertions
91+
.assertNull(sessionManager.getSession(authToken3), "Getting a session with an unused authentication token should return null");
10392
}
10493

10594
@Test
106-
public void sessionCreaationAndDeletionTests() {
95+
public void sessionCreationAndDeletionTests() {
10796
Session session = sessionManager.createSession("AUTH");
108-
assertTrue(session.addChannel(Session.DEFAULT_CHANNEL));
109-
assertFalse(session.addChannel(Session.DEFAULT_CHANNEL));
110-
assertTrue(session.doesChannelExist(Session.DEFAULT_CHANNEL));
111-
assertTrue(session.removeChannel(Session.DEFAULT_CHANNEL));
112-
assertTrue(!session.doesChannelExist(Session.DEFAULT_CHANNEL));
97+
Assertions.assertTrue(session.addChannel(Session.DEFAULT_CHANNEL));
98+
Assertions.assertFalse(session.addChannel(Session.DEFAULT_CHANNEL));
99+
Assertions.assertTrue(session.doesChannelExist(Session.DEFAULT_CHANNEL));
100+
Assertions.assertTrue(session.removeChannel(Session.DEFAULT_CHANNEL));
101+
Assertions.assertFalse(session.doesChannelExist(Session.DEFAULT_CHANNEL));
113102
}
114103
}

src/test/java/com/teragrep/cfe_16/TokenManagerTests.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,11 @@
4545
*/
4646
package com.teragrep.cfe_16;
4747

48+
import java.util.Base64;
49+
import org.junit.jupiter.api.Assertions;
4850
import org.junit.jupiter.api.Test;
4951
import org.springframework.mock.web.MockHttpServletRequest;
5052

51-
import java.util.Base64;
52-
53-
import static org.junit.Assert.*;
54-
5553
/*
5654
* Tests the functionality of TokenManager
5755
*/
@@ -74,9 +72,10 @@ public void tokenCheckingTest() {
7472
requestWithHttpHeaderAuth.addHeader("Authorization", authToken);
7573
requestWithBasicAuth.addHeader("Authorization", "Basic x:" + authToken);
7674

77-
assertFalse("Token should be found from the request", manager.tokenIsMissing(requestWithHttpHeaderAuth));
78-
assertFalse("Token should be found from the request", manager.tokenIsMissing(requestWithBasicAuth));
79-
assertTrue("Token should not be found from the request", manager.tokenIsMissing(requestWithoutAuth));
75+
Assertions
76+
.assertFalse(manager.tokenIsMissing(requestWithHttpHeaderAuth), "Token should be found from the request");
77+
Assertions.assertFalse(manager.tokenIsMissing(requestWithBasicAuth), "Token should be found from the request");
78+
Assertions.assertTrue(manager.tokenIsMissing(requestWithoutAuth), "Token should not be found from the request");
8079
}
8180

8281
/*
@@ -89,11 +88,10 @@ public void basicAuthCheckingTest() {
8988
String authToken = "AUTH_TOKEN_11111";
9089
String basicAuthHeader = "Basic x:" + authToken;
9190

92-
assertTrue("Authorization header should be in basic format", manager.isTokenInBasic(basicAuthHeader));
93-
assertFalse(
94-
"Authorization should not be in basic format when querying with only the authentication token.",
95-
manager.isTokenInBasic(authToken)
96-
);
91+
Assertions
92+
.assertTrue(manager.isTokenInBasic(basicAuthHeader), "Authorization header should be in basic format");
93+
Assertions
94+
.assertFalse(manager.isTokenInBasic(authToken), "Authorization should not be in basic format when querying with only the " + "authentication token.");
9795
}
9896

9997
/*
@@ -107,10 +105,7 @@ public void getTokenFromBasicAuthTest() {
107105
String credentialsEncoded = Base64.getEncoder().encodeToString(basicAuthCredentials.getBytes());
108106
String basicAuthHeader = "Basic " + credentialsEncoded;
109107

110-
assertEquals(
111-
"Method should return the authentication token extracted from the Basic Authentication format",
112-
authToken, manager.getTokenFromBasic(basicAuthHeader)
113-
);
108+
Assertions
109+
.assertEquals(authToken, manager.getTokenFromBasic(basicAuthHeader), "Method should return the authentication token extracted from the Basic " + "Authentication format");
114110
}
115-
116111
}

src/test/java/com/teragrep/cfe_16/it/AcknowledgementsIT.java

Lines changed: 79 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@
7070
import java.util.Map;
7171
import tools.jackson.databind.exc.InvalidFormatException;
7272

73-
import static org.junit.Assert.*;
74-
7573
/*
7674
* Tests the functionality of Acknowledgements
7775
*/
@@ -154,14 +152,14 @@ public void getCurrentAckValueTest() {
154152
currentAckValue = acknowledgements.getCurrentAckValue(this.authToken1, this.channel1);
155153
acknowledgements.incrementAckValue(this.authToken1, this.channel1);
156154

157-
assertEquals("channel1 current ack value should be 3", 3, currentAckValue);
155+
Assertions.assertEquals(3, currentAckValue, "channel1 current ack value should be 3");
158156

159157
currentAckValue = acknowledgements.getCurrentAckValue(this.authToken1, this.channel1);
160158
acknowledgements.incrementAckValue(this.authToken1, this.channel1);
161-
assertEquals("channel1 current ack value should be 4", 4, currentAckValue);
159+
Assertions.assertEquals(4, currentAckValue, "channel1 current ack value should be 4");
162160

163161
currentAckValue = acknowledgements.getCurrentAckValue(this.authToken2, this.channel2);
164-
assertEquals("channel2 current ack value should be 0", 0, currentAckValue);
162+
Assertions.assertEquals(0, currentAckValue, "channel2 current ack value should be 0");
165163
}
166164

167165
/*
@@ -174,24 +172,28 @@ public void acknowledgeTest() {
174172
acknowledgements.initializeContext(this.authToken1, this.channel1);
175173
acknowledgements.addAck(this.authToken1, this.channel1, new Ack(0, false));
176174
acknowledgements.acknowledge(this.authToken1, this.channel1, 0);
177-
assertTrue(
178-
"ackId 0 should be acknowledged for channel 1",
179-
acknowledgements.isAckAcknowledged(this.authToken1, this.channel1, 0)
180-
);
181-
assertFalse(
182-
"ackId 1 should not be acknowledged for channel 1",
183-
acknowledgements.isAckAcknowledged(this.authToken1, this.channel1, 1)
184-
);
185-
assertFalse(
186-
"ackId 10 is not used yet for channel 1, so isAckAcknowledged should return false",
187-
acknowledgements.isAckAcknowledged(this.authToken1, this.channel1, 10)
188-
);
175+
Assertions
176+
.assertTrue(
177+
178+
acknowledgements.isAckAcknowledged(this.authToken1, this.channel1, 0), "ackId 0 should be acknowledged for channel 1"
179+
);
180+
Assertions
181+
.assertFalse(
182+
183+
acknowledgements.isAckAcknowledged(this.authToken1, this.channel1, 1), "ackId 1 should not be acknowledged for channel 1"
184+
);
185+
Assertions
186+
.assertFalse(
187+
188+
acknowledgements.isAckAcknowledged(this.authToken1, this.channel1, 10), "ackId 10 is not used yet for channel 1, so isAckAcknowledged should return false"
189+
);
189190
acknowledgements.incrementAckValue(this.authToken1, this.channel1);
190191
acknowledgements.initializeContext(this.authToken2, this.channel2);
191-
assertFalse(
192-
"ackId 0 is not used yet for channel 2 so isAckAcknowledged should return false",
193-
acknowledgements.isAckAcknowledged(this.authToken2, this.channel2, 0)
194-
);
192+
Assertions
193+
.assertFalse(
194+
195+
acknowledgements.isAckAcknowledged(this.authToken2, this.channel2, 0), "ackId 0 is not used yet for channel 2 so isAckAcknowledged should return false"
196+
);
195197
}
196198

197199
/*
@@ -214,44 +216,56 @@ public void getRequestedAckStatusesTest() {
214216
final JsonNode faultyNode;
215217
final JsonNode notIntNode;
216218
acknowledgements.initializeContext(this.authToken1, this.channel1);
217-
assertTrue(acknowledgements.addAck(this.authToken1, this.channel1, new Ack(1, false)));
218-
assertTrue(acknowledgements.acknowledge(this.authToken1, this.channel1, 1));
219+
Assertions.assertTrue(acknowledgements.addAck(this.authToken1, this.channel1, new Ack(1, false)));
220+
Assertions.assertTrue(acknowledgements.acknowledge(this.authToken1, this.channel1, 1));
219221

220222
queryNode = Assertions.assertDoesNotThrow(() -> mapper.readTree(requestAsString));
221223
faultyNode = Assertions.assertDoesNotThrow(() -> mapper.readTree(faultyRequestAsString));
222224
notIntNode = Assertions.assertDoesNotThrow(() -> mapper.readTree(notIntRequestAsString));
223225

224-
assertEquals(
225-
"getRequestedAckStatuses should return null, when providing a null value as a parameter", emptyJsonNode,
226-
acknowledgements.getRequestedAckStatuses(this.authToken1, "", null)
227-
);
226+
Assertions
227+
.assertEquals(emptyJsonNode, acknowledgements.getRequestedAckStatuses(this.authToken1, "", null), "getRequestedAckStatuses should return null, when providing a null value as a parameter");
228228

229-
assertEquals(
230-
"ackId 1 status should be true on channel1, others should be false.", supposedResponseAsStringOneTrue,
231-
acknowledgements.getRequestedAckStatuses(this.authToken1, this.channel1, queryNode).toString()
232-
);
229+
Assertions
230+
.assertEquals(
231+
supposedResponseAsStringOneTrue, acknowledgements
232+
.getRequestedAckStatuses(this.authToken1, this.channel1, queryNode)
233+
.toString(),
234+
"ackId 1 status should be true on channel1, others should be false."
235+
);
233236

234-
assertEquals(
235-
"ackId 1 status should be false on channel1 after requesting it's status once. All others should be false as well",
236-
supposedResponseAsStringAllFalse,
237-
acknowledgements.getRequestedAckStatuses(this.authToken1, this.channel1, queryNode).toString()
238-
);
237+
Assertions
238+
.assertEquals(
239+
240+
supposedResponseAsStringAllFalse, acknowledgements
241+
.getRequestedAckStatuses(this.authToken1, this.channel1, queryNode)
242+
.toString(),
243+
"ackId 1 status should be false on channel1 after requesting it's status once. All others should be false as well"
244+
);
239245

240246
acknowledgements.initializeContext(this.authToken2, this.channel2);
241-
assertEquals(
242-
"All ack statuses should be false for channel2", supposedResponseAsStringAllFalse,
243-
acknowledgements.getRequestedAckStatuses(this.authToken2, this.channel2, queryNode).toString()
244-
);
247+
Assertions
248+
.assertEquals(
249+
supposedResponseAsStringAllFalse, acknowledgements
250+
.getRequestedAckStatuses(this.authToken2, this.channel2, queryNode)
251+
.toString(),
252+
"All ack statuses should be false for channel2"
253+
);
245254

246-
assertEquals(
247-
"An empty JsonNode should be returned when querying with an empty JsonNode", emptyJsonNode,
248-
acknowledgements.getRequestedAckStatuses(this.authToken1, this.channel1, emptyJsonNode)
249-
);
255+
Assertions
256+
.assertEquals(
257+
emptyJsonNode, acknowledgements
258+
.getRequestedAckStatuses(this.authToken1, this.channel1, emptyJsonNode),
259+
"An empty JsonNode should be returned when querying with an empty JsonNode"
260+
);
250261

251-
assertEquals(
252-
"An empty JsonNode should be returned when querying with a JsonNode that has no \"acks\" field in it.",
253-
emptyJsonNode, acknowledgements.getRequestedAckStatuses(this.authToken1, this.channel1, faultyNode)
254-
);
262+
Assertions
263+
.assertEquals(
264+
265+
emptyJsonNode, acknowledgements
266+
.getRequestedAckStatuses(this.authToken1, this.channel1, faultyNode),
267+
"An empty JsonNode should be returned when querying with a JsonNode that has no \"acks\" field in it."
268+
);
255269

256270
Assertions
257271
.assertThrowsExactly(
@@ -264,25 +278,17 @@ public void getCurrentAckValueAndIncrementTest() {
264278
Acknowledgements acknowledgements1 = new Acknowledgements(new Configuration());
265279
Acknowledgements acknowledgements2 = new Acknowledgements(new Configuration());
266280

267-
assertEquals(
268-
"Acknowledgements 1 should return 0", 0,
269-
acknowledgements1.getCurrentAckValue(this.authToken1, Session.DEFAULT_CHANNEL)
270-
);
281+
Assertions
282+
.assertEquals(0, acknowledgements1.getCurrentAckValue(this.authToken1, Session.DEFAULT_CHANNEL), "Acknowledgements 1 should return 0");
271283
acknowledgements1.incrementAckValue(this.authToken1, Session.DEFAULT_CHANNEL);
272-
assertEquals(
273-
"Acknowledgements 1 should return 1", 1,
274-
acknowledgements1.getCurrentAckValue(this.authToken1, Session.DEFAULT_CHANNEL)
275-
);
276-
277-
assertEquals(
278-
"Acknowledgements 2 should return 0", 0,
279-
acknowledgements2.getCurrentAckValue(this.authToken1, Session.DEFAULT_CHANNEL)
280-
);
284+
Assertions
285+
.assertEquals(1, acknowledgements1.getCurrentAckValue(this.authToken1, Session.DEFAULT_CHANNEL), "Acknowledgements 1 should return 1");
286+
287+
Assertions
288+
.assertEquals(0, acknowledgements2.getCurrentAckValue(this.authToken1, Session.DEFAULT_CHANNEL), "Acknowledgements 2 should return 0");
281289
acknowledgements2.incrementAckValue(this.authToken1, Session.DEFAULT_CHANNEL);
282-
assertEquals(
283-
"Acknowledgements 2 should return 1", 1,
284-
acknowledgements2.getCurrentAckValue(this.authToken1, Session.DEFAULT_CHANNEL)
285-
);
290+
Assertions
291+
.assertEquals(1, acknowledgements2.getCurrentAckValue(this.authToken1, Session.DEFAULT_CHANNEL), "Acknowledgements 2 should return 1");
286292

287293
}
288294

@@ -299,28 +305,28 @@ public void deleteAckTest() {
299305
Acknowledgements acknowledgements2 = new Acknowledgements(new Configuration());
300306

301307
acknowledgements1.initializeContext(this.authToken1, this.channel1);
302-
assertTrue(acknowledgements1.addAck(this.authToken1, this.channel1, new Ack(0, false)));
303-
assertTrue(acknowledgements1.addAck(this.authToken1, this.channel1, new Ack(1, false)));
308+
Assertions.assertTrue(acknowledgements1.addAck(this.authToken1, this.channel1, new Ack(0, false)));
309+
Assertions.assertTrue(acknowledgements1.addAck(this.authToken1, this.channel1, new Ack(1, false)));
304310

305311
Map<Integer, Ack> list1 = acknowledgements1.getAckList(this.authToken1, this.channel1);
306312
int list1Size = acknowledgements1.getAckListSize(this.authToken1, this.channel1);
307-
assertEquals("Ack list 1 size should be 2.", 2, list1Size);
313+
Assertions.assertEquals(2, list1Size, "Ack list 1 size should be 2.");
308314

309315
Ack deletedAck = list1.values().iterator().next();
310316

311317
acknowledgements2.initializeContext(this.authToken2, this.channel2);
312-
assertTrue(acknowledgements2.addAck(this.authToken2, this.channel2, new Ack(0, false)));
318+
Assertions.assertTrue(acknowledgements2.addAck(this.authToken2, this.channel2, new Ack(0, false)));
313319

314320
acknowledgements2.initializeContext(this.authToken2, this.channel2);
315-
assertTrue(acknowledgements2.addAck(this.authToken2, this.channel2, new Ack(1, false)));
321+
Assertions.assertTrue(acknowledgements2.addAck(this.authToken2, this.channel2, new Ack(1, false)));
316322

317323
acknowledgements2.deleteAckFromList(this.authToken2, this.channel2, deletedAck);
318324
Map<Integer, Ack> list2 = acknowledgements2.getAckList(this.authToken2, this.channel2);
319325
int list2Size = list2.size();
320326

321-
assertNotSame("Ack lists should not be same", list1.toString(), list2.toString());
322-
assertEquals("list2 should be shorter by one index", list1Size - 1, list2Size);
323-
assertFalse("list2 should not contain the deleted ack", list2.containsKey(deletedAck.getId()));
327+
Assertions.assertNotSame(list1.toString(), list2.toString(), "Ack lists should not be same");
328+
Assertions.assertEquals(list1Size - 1, list2Size, "list2 should be shorter by one index");
329+
Assertions.assertFalse(list2.containsKey(deletedAck.getId()), "list2 should not contain the deleted ack");
324330
}
325331

326332
/*

0 commit comments

Comments
 (0)