Skip to content

Commit 2a4f7a5

Browse files
Migrate tests to JUnit5 (#181)
* Migrate annotations and imports * Migrate assertions * Remove public visibility for test classes and methods * Minor code cleanup
1 parent 9ff5620 commit 2a4f7a5

File tree

8 files changed

+61
-85
lines changed

8 files changed

+61
-85
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@
8181
<optional>true</optional>
8282
</dependency>
8383
<dependency>
84-
<groupId>junit</groupId>
85-
<artifactId>junit</artifactId>
86-
<version>4.13.2</version>
84+
<groupId>org.junit.jupiter</groupId>
85+
<artifactId>junit-jupiter</artifactId>
86+
<version>5.13.2</version>
8787
<scope>test</scope>
8888
</dependency>
8989
<dependency>

src/test/java/com/cloudbees/syslog/SyslogMessageTest.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@
1717

1818
import java.util.Calendar;
1919
import java.util.TimeZone;
20-
21-
import org.junit.Test;
20+
import org.junit.jupiter.api.Test;
2221

2322
import static org.hamcrest.Matchers.is;
2423
import static org.hamcrest.MatcherAssert.assertThat;
2524

2625
/**
2726
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a>
2827
*/
29-
public class SyslogMessageTest {
28+
class SyslogMessageTest {
3029

3130
@Test
32-
public void testRfc5425Format() {
31+
void testRfc5425Format() {
3332
// GIVEN
3433
Calendar cal = Calendar.getInstance();
3534
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
@@ -39,7 +38,6 @@ public void testRfc5425Format() {
3938
System.out.println(SyslogMessage.rfc3339DateFormat.format(cal.getTime()));
4039
System.out.println(cal.getTimeInMillis());
4140

42-
4341
SyslogMessage message = new SyslogMessage()
4442
.withTimestamp(cal.getTimeInMillis())
4543
.withAppName("my_app")
@@ -58,8 +56,7 @@ public void testRfc5425Format() {
5856
}
5957

6058
@Test
61-
public void testRfc5424Format() {
62-
59+
void testRfc5424Format() {
6360
Calendar cal = Calendar.getInstance();
6461
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
6562
cal.set(2013, Calendar.DECEMBER, 5, 10, 30, 5);
@@ -68,7 +65,6 @@ public void testRfc5424Format() {
6865
System.out.println(SyslogMessage.rfc3339DateFormat.format(cal.getTime()));
6966
System.out.println(cal.getTimeInMillis());
7067

71-
7268
SyslogMessage message = new SyslogMessage()
7369
.withTimestamp(cal.getTimeInMillis())
7470
.withAppName("my_app")
@@ -82,11 +78,10 @@ public void testRfc5424Format() {
8278
String expected = "<14>1 2013-12-05T10:30:05.000Z myserver.example.com my_app - - - a syslog message";
8379

8480
assertThat(actual, is(expected));
85-
8681
}
8782

8883
@Test
89-
public void testRfc5424FormatWithStructuredData() {
84+
void testRfc5424FormatWithStructuredData() {
9085
Calendar cal = Calendar.getInstance();
9186
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
9287
cal.set(2013, Calendar.DECEMBER, 5, 10, 30, 5);
@@ -95,7 +90,6 @@ public void testRfc5424FormatWithStructuredData() {
9590
System.out.println(SyslogMessage.rfc3339DateFormat.format(cal.getTime()));
9691
System.out.println(cal.getTimeInMillis());
9792

98-
9993
SyslogMessage message = new SyslogMessage()
10094
.withTimestamp(cal.getTimeInMillis())
10195
.withAppName("my_app")
@@ -110,17 +104,16 @@ public void testRfc5424FormatWithStructuredData() {
110104
String expected = "<14>1 2013-12-05T10:30:05.000Z myserver.example.com my_app - - [exampleSDID@32473 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"] a syslog message";
111105

112106
assertThat(actual, is(expected));
113-
107+
114108
message.withSDElement(new SDElement("examplePriority@32473", new SDParam("class", "high")));
115109
actual = message.toRfc5424SyslogMessage();
116110
expected = "<14>1 2013-12-05T10:30:05.000Z myserver.example.com my_app - - [exampleSDID@32473 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"][examplePriority@32473 class=\"high\"] a syslog message";
117-
111+
118112
assertThat(actual, is(expected));
119113
}
120114

121115
@Test
122-
public void testRfc3164Format() {
123-
116+
void testRfc3164Format() {
124117
Calendar cal = Calendar.getInstance();
125118
cal.setTimeZone(TimeZone.getDefault());
126119
cal.set(2013, Calendar.DECEMBER, 5, 10, 30, 5);
@@ -129,7 +122,6 @@ public void testRfc3164Format() {
129122
System.out.println(SyslogMessage.rfc3339DateFormat.format(cal.getTime()));
130123
System.out.println(cal.getTimeInMillis());
131124

132-
133125
SyslogMessage message = new SyslogMessage()
134126
.withTimestamp(cal.getTimeInMillis())
135127
.withAppName("my_app")
@@ -143,6 +135,5 @@ public void testRfc3164Format() {
143135
String expected = "<14>Dec 05 10:30:05 myserver.example.com my_app: a syslog message";
144136

145137
assertThat(actual, is(expected));
146-
147138
}
148139
}

src/test/java/com/cloudbees/syslog/integration/jul/SyslogHandlerTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
/*
22
* Copyright (c) 2010-2013 the original author or authors
3-
*
3+
*
44
* Permission is hereby granted, free of charge, to any person obtaining
55
* a copy of this software and associated documentation files (the
66
* "Software"), to deal in the Software without restriction, including
77
* without limitation the rights to use, copy, modify, merge, publish,
88
* distribute, sublicense, and/or sell copies of the Software, and to
99
* permit persons to whom the Software is furnished to do so, subject to
1010
* the following conditions:
11-
*
11+
*
1212
* The above copyright notice and this permission notice shall be
1313
* included in all copies or substantial portions of the Software.
14-
*
14+
*
1515
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1616
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1717
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1818
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
1919
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2020
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2121
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22-
*
22+
*
2323
*/
2424
package com.cloudbees.syslog.integration.jul;
2525

2626
import com.cloudbees.syslog.sender.UdpSyslogMessageSender;
27-
import org.junit.Test;
2827

2928
import java.util.logging.Level;
3029
import java.util.logging.Logger;
30+
import org.junit.jupiter.api.Test;
3131

3232
/**
3333
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a>
3434
*/
35-
public class SyslogHandlerTest {
35+
class SyslogHandlerTest {
3636

3737
@Test
38-
public void test(){
38+
void test() {
3939
Logger logger = Logger.getLogger(getClass().getName());
4040
logger.setLevel(Level.FINEST);
4141

src/test/java/com/cloudbees/syslog/sender/TcpSyslogMessageSenderLoadTest.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,15 @@ public static void main(String[] args) throws Exception {
5353
for (int i = 0; i < THREADS_COUNT; i++) {
5454
final String prefix = "thread-" + i + "msg-";
5555

56-
Runnable command = new Runnable() {
57-
@Override
58-
public void run() {
59-
for (int j = 0; j < ITERATION_COUNT; j++) {
60-
try {
61-
messageSender.sendMessage(prefix + j);
62-
Thread.sleep(random.nextInt(3));
63-
} catch (IOException | InterruptedException e) {
64-
System.err.println("ERROR in " + prefix);
65-
e.printStackTrace();
66-
break;
67-
}
56+
Runnable command = () -> {
57+
for (int j = 0; j < ITERATION_COUNT; j++) {
58+
try {
59+
messageSender.sendMessage(prefix + j);
60+
Thread.sleep(random.nextInt(3));
61+
} catch (IOException | InterruptedException e) {
62+
System.err.println("ERROR in " + prefix);
63+
e.printStackTrace();
64+
break;
6865
}
6966
}
7067
};

src/test/java/com/cloudbees/syslog/sender/TcpSyslogMessageSenderTest.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,18 @@
1919
import com.cloudbees.syslog.MessageFormat;
2020
import com.cloudbees.syslog.Severity;
2121
import com.cloudbees.syslog.SyslogMessage;
22-
import org.junit.Ignore;
23-
import org.junit.Test;
24-
22+
import org.junit.jupiter.api.Disabled;
23+
import org.junit.jupiter.api.Test;
2524
import java.sql.Timestamp;
2625

2726
/**
2827
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a>
2928
*/
30-
public class TcpSyslogMessageSenderTest {
29+
class TcpSyslogMessageSenderTest {
3130

32-
// @Ignore
31+
// @Disabled
3332
@Test
34-
public void send() throws Exception {
33+
void send() throws Exception {
3534
TcpSyslogMessageSender messageSender = new TcpSyslogMessageSender();
3635
messageSender.setDefaultMessageHostname("mysecretkey");
3736
messageSender.setDefaultAppName("myapp");
@@ -44,10 +43,9 @@ public void send() throws Exception {
4443
messageSender.sendMessage("unit test message over tcp éèà " + getClass() + " - " + new Timestamp(System.currentTimeMillis()));
4544
}
4645

47-
@Ignore
46+
@Disabled
4847
@Test
49-
public void send2() throws Exception {
50-
48+
void send2() throws Exception {
5149
SyslogMessage msg = new SyslogMessage()
5250
.withAppName("my-app")
5351
.withFacility(Facility.USER)
@@ -67,11 +65,9 @@ public void send2() throws Exception {
6765
messageSender.sendMessage(msg);
6866
}
6967

70-
71-
@Ignore
68+
@Disabled
7269
@Test
73-
public void sendOverSSL() throws Exception {
74-
70+
void sendOverSSL() throws Exception {
7571
SyslogMessage msg = new SyslogMessage()
7672
.withAppName("my-app")
7773
.withFacility(Facility.USER)
@@ -91,12 +87,11 @@ public void sendOverSSL() throws Exception {
9187
messageSender.sendMessage(msg);
9288
}
9389

94-
9590
/**
9691
* https://github.com/CloudBees-community/syslog-java-client/issues/19
9792
*/
9893
@Test
99-
public void test_bug19_NullPointerException_In_ToString(){
94+
void test_bug19_NullPointerException_In_ToString(){
10095
TcpSyslogMessageSender tcpSyslogMessageSender = new TcpSyslogMessageSender();
10196
tcpSyslogMessageSender.toString();
10297
}

src/test/java/com/cloudbees/syslog/sender/UdpSyslogMessageSenderLoadTest.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,14 @@ public static void main(String[] args) throws Exception {
5050
for (int i = 0; i < THREADS_COUNT; i++) {
5151
final String prefix = "thread-" + i + "-udp-msg-";
5252

53-
Runnable command = new Runnable() {
54-
@Override
55-
public void run() {
56-
for (int j = 0; j < ITERATION_COUNT; j++) {
57-
try {
58-
messageSender.sendMessage(prefix + j);
59-
} catch (IOException e) {
60-
System.err.println("ERROR in " + prefix);
61-
e.printStackTrace();
62-
break;
63-
}
53+
Runnable command = () -> {
54+
for (int j = 0; j < ITERATION_COUNT; j++) {
55+
try {
56+
messageSender.sendMessage(prefix + j);
57+
} catch (IOException e) {
58+
System.err.println("ERROR in " + prefix);
59+
e.printStackTrace();
60+
break;
6461
}
6562
}
6663
};

src/test/java/com/cloudbees/syslog/sender/UpdSyslogMessageSenderTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717

1818
import com.cloudbees.syslog.Facility;
1919
import com.cloudbees.syslog.Severity;
20-
import org.junit.Test;
2120

2221
import java.sql.Timestamp;
22+
import org.junit.jupiter.api.Test;
2323

2424
/**
2525
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a>
2626
*/
27-
public class UpdSyslogMessageSenderTest {
27+
class UpdSyslogMessageSenderTest {
2828

29-
// @Ignore
29+
// @Disabled
3030
@Test
31-
public void send() throws Exception {
31+
void send() throws Exception {
3232
UdpSyslogMessageSender messageSender = new UdpSyslogMessageSender();
3333
messageSender.setDefaultMessageHostname("mysecretkey");
3434
messageSender.setDefaultAppName("myapp");
@@ -39,6 +39,4 @@ public void send() throws Exception {
3939
messageSender.setSyslogServerPort(18977);
4040
messageSender.sendMessage("unit test message éèà " + getClass() + " - " + new Timestamp(System.currentTimeMillis()));
4141
}
42-
43-
4442
}

src/test/java/com/cloudbees/syslog/util/CachingReferenceTest.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@
1616
package com.cloudbees.syslog.util;
1717

1818
import org.hamcrest.Matchers;
19-
import org.junit.Test;
20-
19+
import org.junit.jupiter.api.Test;
2120
import edu.umd.cs.findbugs.annotations.Nullable;
2221
import java.util.concurrent.TimeUnit;
2322

2423
import static org.hamcrest.MatcherAssert.assertThat;
24+
import static org.hamcrest.Matchers.equalTo;
25+
import static org.junit.jupiter.api.Assertions.assertThrows;
26+
27+
class CachingReferenceTest {
2528

26-
public class CachingReferenceTest {
2729
/**
2830
* Test that the locks are properly released.
2931
*/
3032
@Test
31-
public void test_return_value() {
32-
33-
CachingReference<String> cachingReference = new CachingReference<String>(5, TimeUnit.SECONDS) {
33+
void test_return_value() {
34+
CachingReference<String> cachingReference = new CachingReference<>(5, TimeUnit.SECONDS) {
3435
@Nullable
3536
@Override
3637
protected String newObject() {
@@ -39,27 +40,24 @@ protected String newObject() {
3940
};
4041

4142
String actual = cachingReference.get();
42-
assertThat(actual, Matchers.equalTo("value"));
43+
assertThat(actual, equalTo("value"));
4344
}
4445

4546
/**
4647
* Test that the locks are properly released.
4748
*/
48-
@Test(expected = MyRuntimeException.class)
49-
public void test_throw_exception_in_get_object() {
50-
51-
CachingReference<String> cachingReference = new CachingReference<String>(5, TimeUnit.SECONDS) {
49+
@Test
50+
void test_throw_exception_in_get_object() {
51+
CachingReference<String> cachingReference = new CachingReference<>(5, TimeUnit.SECONDS) {
5252
@Nullable
5353
@Override
5454
protected String newObject() {
5555
throw new MyRuntimeException();
5656
}
5757
};
58-
59-
cachingReference.get();
58+
assertThrows(MyRuntimeException.class, cachingReference::get);
6059
}
6160

62-
6361
private static class MyRuntimeException extends RuntimeException {
6462
public MyRuntimeException() {
6563
super();

0 commit comments

Comments
 (0)