-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from brianwernick/enum_converter_nullability
Updated the `EnumValueConverter` to be nullable & added tests
- Loading branch information
Showing
3 changed files
with
92 additions
and
17 deletions.
There are no files selected for viewing
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
72 changes: 72 additions & 0 deletions
72
...rc/test/kotlin/com/devbrackets/android/datastore/converter/core/EnumValueConverterTest.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,72 @@ | ||
package com.devbrackets.android.datastore.converter.core | ||
|
||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
class EnumValueConverterTest { | ||
|
||
@Test | ||
fun toConvertedNull() { | ||
// Given | ||
val converter = EnumValueConverter(TestEnum::class) | ||
|
||
// When | ||
val actual = converter.toConverted(null) | ||
|
||
// Then | ||
Assert.assertNull(actual) | ||
} | ||
|
||
@Test | ||
fun toConvertedExists() { | ||
// Given | ||
val converter = EnumValueConverter(TestEnum::class) | ||
|
||
// When | ||
val actual = converter.toConverted(TestEnum.FIRST) | ||
|
||
// Then | ||
Assert.assertEquals("FIRST", actual) | ||
} | ||
|
||
@Test | ||
fun toOriginalNull() { | ||
// Given | ||
val converter = EnumValueConverter(TestEnum::class) | ||
|
||
// When | ||
val actual = converter.toOriginal(null) | ||
|
||
// Then | ||
Assert.assertNull(actual) | ||
} | ||
|
||
@Test | ||
fun toOriginalExists() { | ||
// Given | ||
val converter = EnumValueConverter(TestEnum::class) | ||
|
||
// When | ||
val actual = converter.toOriginal(TestEnum.SECOND.name) | ||
|
||
// Then | ||
Assert.assertEquals(TestEnum.SECOND, actual) | ||
} | ||
|
||
@Test | ||
fun toOriginalNotExists() { | ||
// Given | ||
val converter = EnumValueConverter(TestEnum::class) | ||
|
||
// When / Then | ||
Assert.assertThrows(IllegalArgumentException::class.java) { | ||
converter.toOriginal("FOURTH") | ||
} | ||
} | ||
|
||
private enum class TestEnum { | ||
FIRST, | ||
SECOND, | ||
THIRD | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
ARTIFACT_ID = datastore | ||
GROUP_ID = com.devbrackets.android | ||
|
||
VERSION_MAJOR = 0 | ||
VERSION_MAJOR = 1 | ||
VERSION_MINOR = 0 | ||
VERSION_PATCH = 1 | ||
VERSION_PRE_RELEASE = preview01 | ||
VERSION_PATCH = 0 | ||
VERSION_PRE_RELEASE = preview01 |