Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
JUnit5 assertThrows OptionTest
  • Loading branch information
nhojpatrick committed Nov 11, 2022
commit 0e37434942288d40df044110cdf7c52041de7175
32 changes: 20 additions & 12 deletions src/test/java/org/apache/commons/cli/OptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.commons.cli;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
Expand All @@ -27,6 +28,7 @@
import org.junit.Test;

public class OptionTest {

private static class DefaultOption extends Option {
private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -71,34 +73,40 @@ private static void checkOption(final Option option, final String opt, final Str
assertEquals(cls, option.getType());
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testBuilderInsufficientParams1() {
Option.builder().desc("desc").build();
assertThrows(IllegalArgumentException.class, () ->
Option.builder().desc("desc").build());
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testBuilderInsufficientParams2() {
Option.builder(null).desc("desc").build();
assertThrows(IllegalArgumentException.class, () ->
Option.builder(null).desc("desc").build());
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testBuilderInvalidOptionName1() {
Option.builder().option("invalid?");
assertThrows(IllegalArgumentException.class, () ->
Option.builder().option("invalid?"));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testBuilderInvalidOptionName2() {
Option.builder().option("invalid@");
assertThrows(IllegalArgumentException.class, () ->
Option.builder().option("invalid@"));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testBuilderInvalidOptionName3() {
Option.builder("invalid?");
assertThrows(IllegalArgumentException.class, () ->
Option.builder("invalid?"));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testBuilderInvalidOptionName4() {
Option.builder("invalid@");
assertThrows(IllegalArgumentException.class, () ->
Option.builder("invalid@"));
}

@Test
Expand Down