Skip to content

Commit a122214

Browse files
Replace assert by simpler but equivalent calls. (apache#69)
1 parent cf94289 commit a122214

8 files changed

Lines changed: 93 additions & 86 deletions

File tree

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ 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;
2021
import static org.junit.Assert.assertFalse;
2122
import static org.junit.Assert.assertTrue;
2223

@@ -42,7 +43,7 @@ public void testOption() throws Exception {
4243
final CommandLine cl = parser.parse(options, args);
4344
assertTrue("Confirm -p is set", cl.hasOption("p"));
4445
assertFalse("Confirm -attr is not set", cl.hasOption("attr"));
45-
assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0);
46+
assertEquals("Confirm all arguments recognized", 0, cl.getArgs().length);
4647
}
4748

4849
@Test
@@ -52,8 +53,8 @@ public void testOptionAndOptionWithArgument() throws Exception {
5253
final CommandLine cl = parser.parse(options, args);
5354
assertTrue("Confirm -p is set", cl.hasOption("p"));
5455
assertTrue("Confirm -attr is set", cl.hasOption("attr"));
55-
assertTrue("Confirm arg of -attr", cl.getOptionValue("attr").equals("p"));
56-
assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0);
56+
assertEquals("Confirm arg of -attr", "p", cl.getOptionValue("attr"));
57+
assertEquals("Confirm all arguments recognized", 0, cl.getArgs().length);
5758
}
5859

5960
@Test
@@ -63,7 +64,7 @@ public void testOptionWithArgument() throws Exception {
6364
final CommandLine cl = parser.parse(options, args);
6465
assertFalse("Confirm -p is set", cl.hasOption("p"));
6566
assertTrue("Confirm -attr is set", cl.hasOption("attr"));
66-
assertTrue("Confirm arg of -attr", cl.getOptionValue("attr").equals("p"));
67-
assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0);
67+
assertEquals("Confirm arg of -attr", "p", cl.getOptionValue("attr"));
68+
assertEquals("Confirm all arguments recognized", 0, cl.getArgs().length);
6869
}
6970
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
1818
package org.apache.commons.cli;
1919

2020
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertNull;
2122
import static org.junit.Assert.fail;
2223

2324
import java.io.ByteArrayOutputStream;
@@ -559,7 +560,7 @@ public void testRenderWrappedTextWordCut() {
559560
public void testRtrim() {
560561
final HelpFormatter formatter = new HelpFormatter();
561562

562-
assertEquals(null, formatter.rtrim(null));
563+
assertNull(formatter.rtrim(null));
563564
assertEquals("", formatter.rtrim(""));
564565
assertEquals(" foo", formatter.rtrim(" foo "));
565566
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
1818
package org.apache.commons.cli;
1919

2020
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertFalse;
2122
import static org.junit.Assert.assertNull;
2223
import static org.junit.Assert.assertTrue;
2324
import static org.junit.Assert.fail;
@@ -32,7 +33,7 @@ public void testBaseOptionCharOpt() {
3233

3334
assertEquals("o", base.getOpt());
3435
assertEquals("option description", base.getDescription());
35-
assertTrue(!base.hasArg());
36+
assertFalse(base.hasArg());
3637
}
3738

3839
@Test
@@ -41,7 +42,7 @@ public void testBaseOptionStringOpt() {
4142

4243
assertEquals("o", base.getOpt());
4344
assertEquals("option description", base.getDescription());
44-
assertTrue(!base.hasArg());
45+
assertFalse(base.hasArg());
4546
}
4647

4748
@Test
@@ -185,7 +186,7 @@ public void testTwoCompleteOptions() {
185186
assertEquals("this is a dimple option", simple.getDescription());
186187
assertEquals(String.class, simple.getType());
187188
assertTrue(simple.hasArg());
188-
assertTrue(!simple.isRequired());
189-
assertTrue(!simple.hasArgs());
189+
assertFalse(simple.isRequired());
190+
assertFalse(simple.hasArgs());
190191
}
191192
}

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

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
1818
package org.apache.commons.cli;
1919

2020
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertFalse;
2122
import static org.junit.Assert.assertNotNull;
2223
import static org.junit.Assert.assertTrue;
2324
import static org.junit.Assert.fail;
@@ -77,12 +78,12 @@ public void testNoOptionsExtraArgs() throws Exception {
7778

7879
final CommandLine cl = parser.parse(options, args);
7980

80-
assertTrue("Confirm -r is NOT set", !cl.hasOption("r"));
81-
assertTrue("Confirm -f is NOT set", !cl.hasOption("f"));
82-
assertTrue("Confirm -d is NOT set", !cl.hasOption("d"));
83-
assertTrue("Confirm -s is NOT set", !cl.hasOption("s"));
84-
assertTrue("Confirm -c is NOT set", !cl.hasOption("c"));
85-
assertTrue("Confirm TWO extra args", cl.getArgList().size() == 2);
81+
assertFalse("Confirm -r is NOT set", cl.hasOption("r"));
82+
assertFalse("Confirm -f is NOT set", cl.hasOption("f"));
83+
assertFalse("Confirm -d is NOT set", cl.hasOption("d"));
84+
assertFalse("Confirm -s is NOT set", cl.hasOption("s"));
85+
assertFalse("Confirm -c is NOT set", cl.hasOption("c"));
86+
assertEquals("Confirm TWO extra args", 2, cl.getArgList().size());
8687
}
8788

8889
@Test
@@ -91,11 +92,11 @@ public void testSingleLongOption() throws Exception {
9192

9293
final CommandLine cl = parser.parse(options, args);
9394

94-
assertTrue("Confirm -r is NOT set", !cl.hasOption("r"));
95+
assertFalse("Confirm -r is NOT set", cl.hasOption("r"));
9596
assertTrue("Confirm -f is set", cl.hasOption("f"));
96-
assertTrue("Confirm -d is NOT set", !cl.hasOption("d"));
97-
assertTrue("Confirm -s is NOT set", !cl.hasOption("s"));
98-
assertTrue("Confirm -c is NOT set", !cl.hasOption("c"));
97+
assertFalse("Confirm -d is NOT set", cl.hasOption("d"));
98+
assertFalse("Confirm -s is NOT set", cl.hasOption("s"));
99+
assertFalse("Confirm -c is NOT set", cl.hasOption("c"));
99100
assertTrue("Confirm no extra args", cl.getArgList().isEmpty());
100101
}
101102

@@ -106,10 +107,10 @@ public void testSingleOption() throws Exception {
106107
final CommandLine cl = parser.parse(options, args);
107108

108109
assertTrue("Confirm -r is set", cl.hasOption("r"));
109-
assertTrue("Confirm -f is NOT set", !cl.hasOption("f"));
110-
assertTrue("Confirm -d is NOT set", !cl.hasOption("d"));
111-
assertTrue("Confirm -s is NOT set", !cl.hasOption("s"));
112-
assertTrue("Confirm -c is NOT set", !cl.hasOption("c"));
110+
assertFalse("Confirm -f is NOT set", cl.hasOption("f"));
111+
assertFalse("Confirm -d is NOT set", cl.hasOption("d"));
112+
assertFalse("Confirm -s is NOT set", cl.hasOption("s"));
113+
assertFalse("Confirm -c is NOT set", cl.hasOption("c"));
113114
assertTrue("Confirm no extra args", cl.getArgList().isEmpty());
114115
}
115116

@@ -119,11 +120,11 @@ public void testSingleOptionFromGroup() throws Exception {
119120

120121
final CommandLine cl = parser.parse(options, args);
121122

122-
assertTrue("Confirm -r is NOT set", !cl.hasOption("r"));
123+
assertFalse("Confirm -r is NOT set", cl.hasOption("r"));
123124
assertTrue("Confirm -f is set", cl.hasOption("f"));
124-
assertTrue("Confirm -d is NOT set", !cl.hasOption("d"));
125-
assertTrue("Confirm -s is NOT set", !cl.hasOption("s"));
126-
assertTrue("Confirm -c is NOT set", !cl.hasOption("c"));
125+
assertFalse("Confirm -d is NOT set", cl.hasOption("d"));
126+
assertFalse("Confirm -s is NOT set", cl.hasOption("s"));
127+
assertFalse("Confirm -c is NOT set", cl.hasOption("c"));
127128
assertTrue("Confirm no extra args", cl.getArgList().isEmpty());
128129
}
129130

@@ -165,11 +166,11 @@ public void testTwoOptionsFromDifferentGroup() throws Exception {
165166
final String[] args = {"-f", "-s"};
166167

167168
final CommandLine cl = parser.parse(options, args);
168-
assertTrue("Confirm -r is NOT set", !cl.hasOption("r"));
169+
assertFalse("Confirm -r is NOT set", cl.hasOption("r"));
169170
assertTrue("Confirm -f is set", cl.hasOption("f"));
170-
assertTrue("Confirm -d is NOT set", !cl.hasOption("d"));
171+
assertFalse("Confirm -d is NOT set", cl.hasOption("d"));
171172
assertTrue("Confirm -s is set", cl.hasOption("s"));
172-
assertTrue("Confirm -c is NOT set", !cl.hasOption("c"));
173+
assertFalse("Confirm -c is NOT set", cl.hasOption("c"));
173174
assertTrue("Confirm NO extra args", cl.getArgList().isEmpty());
174175
}
175176

@@ -196,7 +197,7 @@ public void testTwoOptionsFromGroupWithProperties() throws Exception {
196197

197198
final CommandLine cl = parser.parse(options, args, properties);
198199
assertTrue(cl.hasOption("f"));
199-
assertTrue(!cl.hasOption("d"));
200+
assertFalse(cl.hasOption("d"));
200201
}
201202

202203
@Test
@@ -207,9 +208,9 @@ public void testTwoValidLongOptions() throws Exception {
207208

208209
assertTrue("Confirm -r is set", cl.hasOption("r"));
209210
assertTrue("Confirm -f is set", cl.hasOption("f"));
210-
assertTrue("Confirm -d is NOT set", !cl.hasOption("d"));
211-
assertTrue("Confirm -s is NOT set", !cl.hasOption("s"));
212-
assertTrue("Confirm -c is NOT set", !cl.hasOption("c"));
211+
assertFalse("Confirm -d is NOT set", cl.hasOption("d"));
212+
assertFalse("Confirm -s is NOT set", cl.hasOption("s"));
213+
assertFalse("Confirm -c is NOT set", cl.hasOption("c"));
213214
assertTrue("Confirm no extra args", cl.getArgList().isEmpty());
214215
}
215216

@@ -221,9 +222,9 @@ public void testTwoValidOptions() throws Exception {
221222

222223
assertTrue("Confirm -r is set", cl.hasOption("r"));
223224
assertTrue("Confirm -f is set", cl.hasOption("f"));
224-
assertTrue("Confirm -d is NOT set", !cl.hasOption("d"));
225-
assertTrue("Confirm -s is NOT set", !cl.hasOption("s"));
226-
assertTrue("Confirm -c is NOT set", !cl.hasOption("c"));
225+
assertFalse("Confirm -d is NOT set", cl.hasOption("d"));
226+
assertFalse("Confirm -s is NOT set", cl.hasOption("s"));
227+
assertFalse("Confirm -c is NOT set", cl.hasOption("c"));
227228
assertTrue("Confirm no extra args", cl.getArgList().isEmpty());
228229
}
229230

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.junit.Assert.assertFalse;
2222
import static org.junit.Assert.assertNotEquals;
2323
import static org.junit.Assert.assertNotSame;
24+
import static org.junit.Assert.assertNull;
2425
import static org.junit.Assert.assertTrue;
2526

2627
import org.junit.Test;
@@ -143,7 +144,7 @@ public void testGetValue() {
143144
option.setArgs(Option.UNLIMITED_VALUES);
144145

145146
assertEquals("default", option.getValue("default"));
146-
assertEquals(null, option.getValue(0));
147+
assertNull(option.getValue(0));
147148

148149
option.addValueForProcessing("foo");
149150

0 commit comments

Comments
 (0)