-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for country code converter
- Loading branch information
1 parent
528894d
commit 79a9297
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...nsp/monitorfish/infrastructure/database/entities/converters/CountryCodeConverterUTests.kt
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,54 @@ | ||
package fr.gouv.cnsp.monitorfish.infrastructure.database.entities.converters | ||
|
||
import com.neovisionaries.i18n.CountryCode | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
|
||
class CountryCodeConverterUTests { | ||
private val converter = CountryCodeConverter() | ||
|
||
@Test | ||
fun `convertToDatabaseColumn should return enum name`() { | ||
// When | ||
val result = converter.convertToDatabaseColumn(CountryCode.US) | ||
|
||
// Then | ||
assertThat(result).isEqualTo("US") | ||
} | ||
|
||
@Test | ||
fun `convertToDatabaseColumn should return null for null attribute`() { | ||
// When | ||
val result = converter.convertToDatabaseColumn(null) | ||
|
||
// Then | ||
assertThat(result).isEqualTo(null) | ||
} | ||
|
||
@Test | ||
fun `convertToEntityAttribute should return enum for valid dbData`() { | ||
// When | ||
val result = converter.convertToEntityAttribute("US") | ||
|
||
// Then | ||
assertThat(result).isEqualTo(CountryCode.US) | ||
} | ||
|
||
@Test | ||
fun `convertToEntityAttribute should return UNDEFINED for invalid dbData`() { | ||
// When | ||
val result = converter.convertToEntityAttribute("INVALID_CODE") | ||
|
||
// Then | ||
assertThat(result).isEqualTo(CountryCode.UNDEFINED) | ||
} | ||
|
||
@Test | ||
fun `convertToEntityAttribute should return UNDEFINED for null dbData`() { | ||
// When | ||
val result = converter.convertToEntityAttribute(null) | ||
|
||
// Then | ||
assertThat(result).isEqualTo(CountryCode.UNDEFINED) | ||
} | ||
} |