Skip to content

Commit 255cca4

Browse files
committed
Update the tests to JUnit 5
This removes references to JUnit 4 test constructions and switches all tests to JUnit 5. Unfortunately, JUnit 5's assertions have swapped the optional "message" argument from first to last, this makes the diff bigger than it would have otherwise been.
1 parent a175b2d commit 255cca4

31 files changed

Lines changed: 510 additions & 510 deletions

src/test/java/org/apache/commons/cli/AbstractParserTestCase.java

Lines changed: 128 additions & 128 deletions
Large diffs are not rendered by default.

src/test/java/org/apache/commons/cli/ApplicationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Licensed to the Apache Software Foundation (ASF) under one or more
1717

1818
package org.apache.commons.cli;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import java.io.PrintWriter;
2424
import java.io.StringWriter;
2525

26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727

2828
/**
2929
* This is a collection of tests that test real world applications command lines.

src/test/java/org/apache/commons/cli/ArgumentIsOptionTest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ Licensed to the Apache Software Foundation (ASF) under one or more
1717

1818
package org.apache.commons.cli;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
2323

24-
import org.junit.Before;
25-
import org.junit.Test;
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Test;
2626

2727
@SuppressWarnings("deprecation") // tests some deprecated classes
2828
public class ArgumentIsOptionTest {
2929

3030
private Options options;
3131
private CommandLineParser parser;
3232

33-
@Before
33+
@BeforeEach
3434
public void setUp() {
3535
options = new Options().addOption("p", false, "Option p").addOption("attr", true, "Option accepts argument");
3636
parser = new PosixParser();
@@ -41,30 +41,30 @@ public void testOption() throws Exception {
4141
final String[] args = {"-p"};
4242

4343
final CommandLine cl = parser.parse(options, args);
44-
assertTrue("Confirm -p is set", cl.hasOption("p"));
45-
assertFalse("Confirm -attr is not set", cl.hasOption("attr"));
46-
assertEquals("Confirm all arguments recognized", 0, cl.getArgs().length);
44+
assertTrue(cl.hasOption("p"), "Confirm -p is set");
45+
assertFalse(cl.hasOption("attr"), "Confirm -attr is not set");
46+
assertEquals(0, cl.getArgs().length, "Confirm all arguments recognized");
4747
}
4848

4949
@Test
5050
public void testOptionAndOptionWithArgument() throws Exception {
5151
final String[] args = {"-p", "-attr", "p"};
5252

5353
final CommandLine cl = parser.parse(options, args);
54-
assertTrue("Confirm -p is set", cl.hasOption("p"));
55-
assertTrue("Confirm -attr is set", cl.hasOption("attr"));
56-
assertEquals("Confirm arg of -attr", "p", cl.getOptionValue("attr"));
57-
assertEquals("Confirm all arguments recognized", 0, cl.getArgs().length);
54+
assertTrue(cl.hasOption("p"), "Confirm -p is set");
55+
assertTrue(cl.hasOption("attr"), "Confirm -attr is set");
56+
assertEquals("p", cl.getOptionValue("attr"), "Confirm arg of -attr");
57+
assertEquals(0, cl.getArgs().length, "Confirm all arguments recognized");
5858
}
5959

6060
@Test
6161
public void testOptionWithArgument() throws Exception {
6262
final String[] args = {"-attr", "p"};
6363

6464
final CommandLine cl = parser.parse(options, args);
65-
assertFalse("Confirm -p is set", cl.hasOption("p"));
66-
assertTrue("Confirm -attr is set", cl.hasOption("attr"));
67-
assertEquals("Confirm arg of -attr", "p", cl.getOptionValue("attr"));
68-
assertEquals("Confirm all arguments recognized", 0, cl.getArgs().length);
65+
assertFalse(cl.hasOption("p"), "Confirm -p is set");
66+
assertTrue(cl.hasOption("attr"), "Confirm -attr is set");
67+
assertEquals("p", cl.getOptionValue("attr"), "Confirm arg of -attr");
68+
assertEquals(0, cl.getArgs().length, "Confirm all arguments recognized");
6969
}
7070
}

src/test/java/org/apache/commons/cli/BasicParserTest.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,178 +17,178 @@ Licensed to the Apache Software Foundation (ASF) under one or more
1717

1818
package org.apache.commons.cli;
1919

20-
import org.junit.Before;
21-
import org.junit.Ignore;
22-
import org.junit.Test;
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.junit.jupiter.api.Disabled;
22+
import org.junit.jupiter.api.Test;
2323

2424
@SuppressWarnings("deprecation") // tests some deprecated classes
2525
public class BasicParserTest extends AbstractParserTestCase {
2626
@Override
27-
@Before
27+
@BeforeEach
2828
public void setUp() {
2929
super.setUp();
3030
parser = new BasicParser();
3131
}
3232

3333
@Override
3434
@Test
35-
@Ignore("not supported by the BasicParser")
35+
@Disabled("not supported by the BasicParser")
3636
public void testAmbiguousLongWithoutEqualSingleDash() throws Exception {
3737
}
3838

3939
@Override
4040
@Test
41-
@Ignore("not supported by the BasicParser")
41+
@Disabled("not supported by the BasicParser")
4242
public void testAmbiguousLongWithoutEqualSingleDash2() throws Exception {
4343
}
4444

4545
@Override
4646
@Test
47-
@Ignore("not supported by the BasicParser")
47+
@Disabled("not supported by the BasicParser")
4848
public void testAmbiguousPartialLongOption1() throws Exception {
4949
}
5050

5151
@Override
5252
@Test
53-
@Ignore("not supported by the BasicParser")
53+
@Disabled("not supported by the BasicParser")
5454
public void testAmbiguousPartialLongOption2() throws Exception {
5555
}
5656

5757
@Override
5858
@Test
59-
@Ignore("not supported by the BasicParser")
59+
@Disabled("not supported by the BasicParser")
6060
public void testAmbiguousPartialLongOption3() throws Exception {
6161
}
6262

6363
@Override
6464
@Test
65-
@Ignore("not supported by the BasicParser")
65+
@Disabled("not supported by the BasicParser")
6666
public void testAmbiguousPartialLongOption4() throws Exception {
6767
}
6868

6969
@Override
7070
@Test
71-
@Ignore("not supported by the BasicParser")
71+
@Disabled("not supported by the BasicParser")
7272
public void testBursting() throws Exception {
7373
}
7474

7575
@Override
7676
@Test
77-
@Ignore("not supported by the BasicParser")
77+
@Disabled("not supported by the BasicParser")
7878
public void testDoubleDash2() throws Exception {
7979
}
8080

8181
@Override
8282
@Test
83-
@Ignore("not supported by the BasicParser")
83+
@Disabled("not supported by the BasicParser")
8484
public void testLongOptionWithEqualsQuoteHandling() throws Exception {
8585
}
8686

8787
@Override
8888
@Test
89-
@Ignore("not supported by the BasicParser")
89+
@Disabled("not supported by the BasicParser")
9090
public void testLongWithEqualDoubleDash() throws Exception {
9191
}
9292

9393
@Override
9494
@Test
95-
@Ignore("not supported by the BasicParser")
95+
@Disabled("not supported by the BasicParser")
9696
public void testLongWithEqualSingleDash() throws Exception {
9797
}
9898

9999
@Override
100100
@Test
101-
@Ignore("not supported by the BasicParser")
101+
@Disabled("not supported by the BasicParser")
102102
public void testLongWithoutEqualSingleDash() throws Exception {
103103
}
104104

105105
@Override
106106
@Test
107-
@Ignore("not supported by the BasicParser")
107+
@Disabled("not supported by the BasicParser")
108108
public void testMissingArgWithBursting() throws Exception {
109109
}
110110

111111
@Override
112112
@Test
113-
@Ignore("not supported by the BasicParser (CLI-184)")
113+
@Disabled("not supported by the BasicParser (CLI-184)")
114114
public void testNegativeOption() throws Exception {
115115
}
116116

117117
@Override
118118
@Test
119-
@Ignore("not supported by the BasicParser")
119+
@Disabled("not supported by the BasicParser")
120120
public void testPartialLongOptionSingleDash() throws Exception {
121121
}
122122

123123
@Override
124124
@Test
125-
@Ignore("not supported by the BasicParser")
125+
@Disabled("not supported by the BasicParser")
126126
public void testPropertiesOption1() throws Exception {
127127
}
128128

129129
@Override
130130
@Test
131-
@Ignore("not supported by the BasicParser")
131+
@Disabled("not supported by the BasicParser")
132132
public void testPropertiesOption2() throws Exception {
133133
}
134134

135135
@Override
136136
@Test
137-
@Ignore("not supported by the BasicParser")
137+
@Disabled("not supported by the BasicParser")
138138
public void testShortOptionConcatenatedQuoteHandling() throws Exception {
139139
}
140140

141141
@Override
142142
@Test
143-
@Ignore("not supported by the BasicParser")
143+
@Disabled("not supported by the BasicParser")
144144
public void testShortWithEqual() throws Exception {
145145
}
146146

147147
@Override
148148
@Test
149-
@Ignore("not supported by the BasicParser")
149+
@Disabled("not supported by the BasicParser")
150150
public void testShortWithoutEqual() throws Exception {
151151
}
152152

153153
@Override
154154
@Test
155-
@Ignore("not supported by the BasicParser")
155+
@Disabled("not supported by the BasicParser")
156156
public void testStopBursting() throws Exception {
157157
}
158158

159159
@Override
160160
@Test
161-
@Ignore("not supported by the BasicParser")
161+
@Disabled("not supported by the BasicParser")
162162
public void testStopBursting2() throws Exception {
163163
}
164164

165165
@Override
166166
@Test
167-
@Ignore("not supported by the BasicParser")
167+
@Disabled("not supported by the BasicParser")
168168
public void testUnambiguousPartialLongOption1() throws Exception {
169169
}
170170

171171
@Override
172172
@Test
173-
@Ignore("not supported by the BasicParser")
173+
@Disabled("not supported by the BasicParser")
174174
public void testUnambiguousPartialLongOption2() throws Exception {
175175
}
176176

177177
@Override
178178
@Test
179-
@Ignore("not supported by the BasicParser")
179+
@Disabled("not supported by the BasicParser")
180180
public void testUnambiguousPartialLongOption3() throws Exception {
181181
}
182182

183183
@Override
184184
@Test
185-
@Ignore("not supported by the BasicParser")
185+
@Disabled("not supported by the BasicParser")
186186
public void testUnambiguousPartialLongOption4() throws Exception {
187187
}
188188

189189
@Override
190190
@Test
191-
@Ignore("not supported by the BasicParser")
191+
@Disabled("not supported by the BasicParser")
192192
public void testUnrecognizedOptionWithBursting() throws Exception {
193193
}
194194
}

src/test/java/org/apache/commons/cli/CommandLineTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ Licensed to the Apache Software Foundation (ASF) under one or more
1717

1818
package org.apache.commons.cli;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertNotNull;
22-
import static org.junit.Assert.assertNull;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
22+
import static org.junit.jupiter.api.Assertions.assertNull;
2323

2424
import java.util.Properties;
2525
import java.util.function.Supplier;
2626

27-
import org.junit.Test;
27+
import org.junit.jupiter.api.Test;
2828

2929
@SuppressWarnings("deprecation") // tests some deprecated classes
3030
public class CommandLineTest {
@@ -78,14 +78,14 @@ public void testGetOptionProperties() throws Exception {
7878
final CommandLine cl = parser.parse(options, args);
7979

8080
final Properties props = cl.getOptionProperties("D");
81-
assertNotNull("null properties", props);
82-
assertEquals("number of properties in " + props, 4, props.size());
83-
assertEquals("property 1", "value1", props.getProperty("param1"));
84-
assertEquals("property 2", "value2", props.getProperty("param2"));
85-
assertEquals("property 3", "true", props.getProperty("param3"));
86-
assertEquals("property 4", "value4", props.getProperty("param4"));
87-
88-
assertEquals("property with long format", "bar", cl.getOptionProperties("property").getProperty("foo"));
81+
assertNotNull(props, "null properties");
82+
assertEquals(4, props.size(), "number of properties in " + props);
83+
assertEquals("value1", props.getProperty("param1"), "property 1");
84+
assertEquals("value2", props.getProperty("param2"), "property 2");
85+
assertEquals("true", props.getProperty("param3"), "property 3");
86+
assertEquals("value4", props.getProperty("param4"), "property 4");
87+
88+
assertEquals("bar", cl.getOptionProperties("property").getProperty("foo"), "property with long format");
8989
}
9090

9191
@Test
@@ -102,14 +102,14 @@ public void testGetOptionPropertiesWithOption() throws Exception {
102102
final CommandLine cl = parser.parse(options, args);
103103

104104
final Properties props = cl.getOptionProperties(optionD);
105-
assertNotNull("null properties", props);
106-
assertEquals("number of properties in " + props, 4, props.size());
107-
assertEquals("property 1", "value1", props.getProperty("param1"));
108-
assertEquals("property 2", "value2", props.getProperty("param2"));
109-
assertEquals("property 3", "true", props.getProperty("param3"));
110-
assertEquals("property 4", "value4", props.getProperty("param4"));
111-
112-
assertEquals("property with long format", "bar", cl.getOptionProperties(optionProperty).getProperty("foo"));
105+
assertNotNull(props, "null properties");
106+
assertEquals(4, props.size(), "number of properties in " + props);
107+
assertEquals("value1", props.getProperty("param1"), "property 1");
108+
assertEquals("value2", props.getProperty("param2"), "property 2");
109+
assertEquals("true", props.getProperty("param3"), "property 3");
110+
assertEquals("value4", props.getProperty("param4"), "property 4");
111+
112+
assertEquals("bar", cl.getOptionProperties(optionProperty).getProperty("foo"), "property with long format");
113113
}
114114

115115
@Test

src/test/java/org/apache/commons/cli/ConverterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
1616
*/
1717
package org.apache.commons.cli;
1818

19-
import static org.junit.Assert.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertNotNull;
2121
import static org.junit.jupiter.api.Assertions.assertThrows;
2222

0 commit comments

Comments
 (0)