Skip to content

Commit

Permalink
Revert test
Browse files Browse the repository at this point in the history
  • Loading branch information
Morten Haraldsen committed Feb 15, 2025
1 parent b7f064f commit 5b3505c
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/test/java/com/ethlo/time/ExternalParameterizedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ void testAll(TestParam param)
}
else
{
logger.info("Evaluating test: {}", param.getNote());
result = ITU.parseDateTime(param.getInput());
}

Expand All @@ -78,32 +77,22 @@ void testAll(TestParam param)
}

// Compare to Java's parser result
final Instant expected = param.getExpected();
final Instant expected = getExpected(param);
if (result instanceof DateTime)
{
assertEqualInstant(param.getNote(), ((DateTime) result).toInstant(), expected);
assertEqualInstant(((DateTime) result).toInstant(), expected);
}
else
{
assertEqualInstant(param.getNote(), ((OffsetDateTime) result).toInstant(), expected);
assertEqualInstant(((OffsetDateTime) result).toInstant(), expected);
}
}
catch (DateTimeException exc)
{
String errorMessage = exc.getMessage();
if (exc instanceof LeapSecondException)
{
final boolean isValid = ((LeapSecondException) exc).isVerifiedValidLeapYearMonth();
if (!isValid)
{
errorMessage = "Invalid leap second";
}
}

if (param.getError() != null)
{
// expected an error, check if matching
assertThat(errorMessage).isEqualTo(param.getError());
assertThat(exc).hasMessage(param.getError());

if (param.getErrorIndex() != -1)
{
Expand All @@ -120,15 +109,32 @@ void testAll(TestParam param)

}

private void assertEqualInstant(final String name, Instant result, Instant expected)
private void assertEqualInstant(Instant result, Instant expected)
{
assertThat(result)
.overridingErrorMessage("Expected %s (%s), was %s (%s) in test '%s'", expected, asTs(expected), result, asTs(result), name)
.overridingErrorMessage("Expected %s (%s), was %s (%s)", expected, asTs(expected), result, asTs(result))
.isEqualTo(expected);
}

private String asTs(Instant instant)
{
return instant.getEpochSecond() + "," + instant.getNano();
}

private Instant getExpected(TestParam testParam)
{
if (testParam.getExpected() != null)
{
return testParam.getExpected();
}

try
{
return Instant.parse(testParam.getInput());
}
catch (DateTimeException exc)
{
throw new IllegalArgumentException("Cannot parse using Instant: " + testParam.getInput() + ": " + exc.getMessage(), exc);
}
}
}

0 comments on commit 5b3505c

Please sign in to comment.