Skip to content

Commit 1e98376

Browse files
committed
Testing TypeHandler.createDate() should not have been removed
1 parent 57e3d45 commit 1e98376

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
3232
import java.nio.file.Paths;
3333
import java.text.DateFormat;
3434
import java.text.SimpleDateFormat;
35+
import java.time.Instant;
3536
import java.util.ArrayList;
3637
import java.util.Date;
3738
import java.util.List;
@@ -68,6 +69,11 @@ private NotInstantiable() {
6869
/** Always returns the same Path. */
6970
private static final Converter<Path, InvalidPathException> PATH_CONVERTER = s -> Paths.get("foo");
7071

72+
static Stream<Date> createDateFixtures() {
73+
return Stream.of(Date.from(Instant.EPOCH), Date.from(Instant.ofEpochSecond(0)), Date.from(Instant.ofEpochSecond(40_000)));
74+
75+
}
76+
7177
private static Stream<Arguments> createValueTestParameters() {
7278
// force the PatternOptionBuilder to load / modify the TypeHandler table.
7379
@SuppressWarnings("unused")
@@ -77,10 +83,8 @@ private static Stream<Arguments> createValueTestParameters() {
7783
final List<Arguments> lst = new ArrayList<>();
7884

7985
/*
80-
* Dates calculated from strings are dependent upon configuration and environment settings for the
81-
* machine on which the test is running. To avoid this problem, convert the time into a string
82-
* and then unparse that using the converter. This produces strings that always match the correct
83-
* time zone.
86+
* Dates calculated from strings are dependent upon configuration and environment settings for the machine on which the test is running. To avoid this
87+
* problem, convert the time into a string and then unparse that using the converter. This produces strings that always match the correct time zone.
8488
*/
8589
final Date date = new Date(1023400137000L);
8690
final DateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
@@ -148,8 +152,7 @@ private static Stream<Arguments> createValueTestParameters() {
148152
lst.add(Arguments.of("not a number", PatternOptionBuilder.NUMBER_VALUE, ParseException.class));
149153

150154
lst.add(Arguments.of(Instantiable.class.getName(), PatternOptionBuilder.OBJECT_VALUE, new Instantiable()));
151-
lst.add(Arguments.of(NotInstantiable.class.getName(), PatternOptionBuilder.OBJECT_VALUE,
152-
ParseException.class));
155+
lst.add(Arguments.of(NotInstantiable.class.getName(), PatternOptionBuilder.OBJECT_VALUE, ParseException.class));
153156
lst.add(Arguments.of("unknown", PatternOptionBuilder.OBJECT_VALUE, ParseException.class));
154157

155158
lst.add(Arguments.of("String", PatternOptionBuilder.STRING_VALUE, "String"));
@@ -189,10 +192,15 @@ public void testClear() {
189192
}
190193
}
191194

195+
@ParameterizedTest
196+
@MethodSource("createDateFixtures")
197+
public void testCreateDate(final Date date) {
198+
assertEquals(date, TypeHandler.createDate(date.toString()));
199+
}
200+
192201
@Test
193202
public void testCreateValueExistingFile() throws Exception {
194-
try (FileInputStream result = TypeHandler.createValue(
195-
"src/test/resources/org/apache/commons/cli/existing-readable.file",
203+
try (FileInputStream result = TypeHandler.createValue("src/test/resources/org/apache/commons/cli/existing-readable.file",
196204
PatternOptionBuilder.EXISTING_FILE_VALUE)) {
197205
assertNotNull(result);
198206
}

0 commit comments

Comments
 (0)