Skip to content

Commit

Permalink
test: unit test for iso 8601 formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
nsenave committed Dec 17, 2024
1 parent 64529a8 commit 47cb9aa
Showing 1 changed file with 89 additions and 0 deletions.
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"));
}

}

0 comments on commit 47cb9aa

Please sign in to comment.