-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: unit test for iso 8601 formatter
- Loading branch information
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
eno-core/src/test/java/fr/insee/eno/core/i18n/date/Iso8601FormatterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package fr.insee.eno.core.i18n.date; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class Iso8601FormatterTest { | ||
|
||
private final Iso8601Formatter formatter = new Iso8601Formatter(); | ||
|
||
@Test | ||
void convertYearMontDate_validDate_shouldReturnFormattedDate() { | ||
// Arrange | ||
String inputDate = "2024-12"; | ||
|
||
// Act | ||
DateFormatter.Result result = formatter.convertYearMontDate(inputDate); | ||
|
||
// Assert | ||
assertTrue(result.isValid()); | ||
assertEquals("2024-12", result.value()); | ||
} | ||
|
||
@Test | ||
void convertYearMontDate_invalidDate_shouldReturnFailure() { | ||
// Arrange | ||
String inputDate = "2024/12"; | ||
|
||
// Act | ||
DateFormatter.Result result = formatter.convertYearMontDate(inputDate); | ||
|
||
// Assert | ||
assertFalse(result.isValid()); | ||
assertTrue(result.errorMessage().contains("YYYY-MM")); | ||
} | ||
|
||
@Test | ||
void convertYearMontDate_emptyString_shouldReturnFailure() { | ||
// Arrange | ||
String inputDate = ""; | ||
|
||
// Act | ||
DateFormatter.Result result = formatter.convertYearMontDate(inputDate); | ||
|
||
// Assert | ||
assertFalse(result.isValid()); | ||
assertTrue(result.errorMessage().contains("YYYY-MM")); | ||
} | ||
|
||
@Test | ||
void convertYearMontDayDate_validDate_shouldReturnFormattedDate() { | ||
// Arrange | ||
String inputDate = "2024-12-17"; | ||
|
||
// Act | ||
DateFormatter.Result result = formatter.convertYearMontDayDate(inputDate); | ||
|
||
// Assert | ||
assertTrue(result.isValid()); | ||
assertEquals("2024-12-17", result.value()); | ||
} | ||
|
||
@Test | ||
void convertYearMontDayDate_invalidDate_shouldReturnFailure() { | ||
// Arrange | ||
String inputDate = "2024/12/17"; | ||
|
||
// Act | ||
DateFormatter.Result result = formatter.convertYearMontDayDate(inputDate); | ||
|
||
// Assert | ||
assertFalse(result.isValid()); | ||
assertTrue(result.errorMessage().contains("YYYY-MM-DD")); | ||
} | ||
|
||
@Test | ||
void convertYearMontDayDate_emptyString_shouldReturnFailure() { | ||
// Arrange | ||
String inputDate = ""; | ||
|
||
// Act | ||
DateFormatter.Result result = formatter.convertYearMontDayDate(inputDate); | ||
|
||
// Assert | ||
assertFalse(result.isValid()); | ||
assertTrue(result.errorMessage().contains("YYYY-MM-DD")); | ||
} | ||
|
||
} |