Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@
</contributors>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
Expand Down
65 changes: 38 additions & 27 deletions src/test/java/org/apache/commons/cli/TypeHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more

package org.apache.commons.cli;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand All @@ -43,14 +44,16 @@ public void testCreateValueClass() throws Exception {
assertEquals(Instantiable.class, clazz);
}

@Test(expected = ParseException.class)
public void testCreateValueClass_notFound() throws Exception {
TypeHandler.createValue("what ever", PatternOptionBuilder.CLASS_VALUE);
@Test
public void testCreateValueClass_notFound() {
assertThrows(ParseException.class, () ->
TypeHandler.createValue("what ever", PatternOptionBuilder.CLASS_VALUE));
}

@Test(expected = UnsupportedOperationException.class)
public void testCreateValueDate() throws Exception {
TypeHandler.createValue("what ever", PatternOptionBuilder.DATE_VALUE);
@Test
public void testCreateValueDate() {
assertThrows(UnsupportedOperationException.class, () ->
TypeHandler.createValue("what ever", PatternOptionBuilder.DATE_VALUE));
}

@Test
Expand All @@ -61,9 +64,10 @@ public void testCreateValueExistingFile() throws Exception {
}
}

@Test(expected = ParseException.class)
public void testCreateValueExistingFile_nonExistingFile() throws Exception {
TypeHandler.createValue("non-existing.file", PatternOptionBuilder.EXISTING_FILE_VALUE);
@Test
public void testCreateValueExistingFile_nonExistingFile() {
assertThrows(ParseException.class, () ->
TypeHandler.createValue("non-existing.file", PatternOptionBuilder.EXISTING_FILE_VALUE));
}

@Test
Expand All @@ -72,14 +76,16 @@ public void testCreateValueFile() throws Exception {
assertEquals("some-file.txt", result.getName());
}

@Test(expected = UnsupportedOperationException.class)
public void testCreateValueFiles() throws Exception {
TypeHandler.createValue("some.files", PatternOptionBuilder.FILES_VALUE);
@Test
public void testCreateValueFiles() {
assertThrows(UnsupportedOperationException.class, () ->
TypeHandler.createValue("some.files", PatternOptionBuilder.FILES_VALUE));
}

@Test(expected = ParseException.class)
public void testCreateValueInteger_failure() throws Exception {
TypeHandler.createValue("just-a-string", Integer.class);
@Test
public void testCreateValueInteger_failure() {
assertThrows(ParseException.class, () ->
TypeHandler.createValue("just-a-string", Integer.class));
}

@Test
Expand All @@ -92,9 +98,10 @@ public void testCreateValueNumber_Long() throws Exception {
assertEquals(Long.valueOf(15), TypeHandler.createValue("15", PatternOptionBuilder.NUMBER_VALUE));
}

@Test(expected = ParseException.class)
public void testCreateValueNumber_noNumber() throws Exception {
TypeHandler.createValue("not a number", PatternOptionBuilder.NUMBER_VALUE);
@Test
public void testCreateValueNumber_noNumber() {
assertThrows(ParseException.class, () ->
TypeHandler.createValue("not a number", PatternOptionBuilder.NUMBER_VALUE));
}

@Test
Expand All @@ -103,14 +110,16 @@ public void testCreateValueObject_InstantiableClass() throws Exception {
assertTrue(result instanceof Instantiable);
}

@Test(expected = ParseException.class)
public void testCreateValueObject_notInstantiableClass() throws Exception {
TypeHandler.createValue(NotInstantiable.class.getName(), PatternOptionBuilder.OBJECT_VALUE);
@Test
public void testCreateValueObject_notInstantiableClass() {
assertThrows(ParseException.class, () ->
TypeHandler.createValue(NotInstantiable.class.getName(), PatternOptionBuilder.OBJECT_VALUE));
}

@Test(expected = ParseException.class)
public void testCreateValueObject_unknownClass() throws Exception {
TypeHandler.createValue("unknown", PatternOptionBuilder.OBJECT_VALUE);
@Test
public void testCreateValueObject_unknownClass() {
assertThrows(ParseException.class, () ->
TypeHandler.createValue("unknown", PatternOptionBuilder.OBJECT_VALUE));
}

@Test
Expand All @@ -125,8 +134,10 @@ public void testCreateValueURL() throws Exception {
assertEquals(urlString, result.toString());
}

@Test(expected = ParseException.class)
public void testCreateValueURL_malformed() throws Exception {
TypeHandler.createValue("malformed-url", PatternOptionBuilder.URL_VALUE);
@Test
public void testCreateValueURL_malformed() {
assertThrows(ParseException.class, () ->
TypeHandler.createValue("malformed-url", PatternOptionBuilder.URL_VALUE));
}

}