|
| 1 | +package co.kyash.vtl.validators |
| 2 | + |
| 3 | +import android.content.Context |
| 4 | +import co.kyash.vtl.testing.RxImmediateSchedulerRule |
| 5 | +import junit.framework.Assert.assertEquals |
| 6 | +import org.junit.Before |
| 7 | +import org.junit.Rule |
| 8 | +import org.junit.Test |
| 9 | +import org.junit.runner.RunWith |
| 10 | +import org.robolectric.ParameterizedRobolectricTestRunner |
| 11 | +import org.robolectric.RuntimeEnvironment |
| 12 | + |
| 13 | +@RunWith(ParameterizedRobolectricTestRunner::class) |
| 14 | +class NoSpecialCharacterValidatorTest( |
| 15 | + private val text: String?, |
| 16 | + private val result: Boolean, |
| 17 | + private val errorMessage: String? |
| 18 | +) { |
| 19 | + companion object { |
| 20 | + private const val ERROR_MESSAGE = "This contains special characters" |
| 21 | + |
| 22 | + @JvmStatic |
| 23 | + @ParameterizedRobolectricTestRunner.Parameters |
| 24 | + fun data(): List<Array<out Any?>> = |
| 25 | + listOf( |
| 26 | + // CJK Unified Ideographs Extension B |
| 27 | + arrayOf("\uD844\uDE3D", false, ERROR_MESSAGE), |
| 28 | + // Folded Hands |
| 29 | + arrayOf("\uD83D\uDE4F", false, ERROR_MESSAGE), |
| 30 | + // Grinning Face |
| 31 | + arrayOf("\uD83D\uDE00", false, ERROR_MESSAGE), |
| 32 | + // Telephone |
| 33 | + arrayOf("\u260E\uFE0F", false, ERROR_MESSAGE), |
| 34 | + // Telephone |
| 35 | + arrayOf("\u260E\uFE0E", false, ERROR_MESSAGE), |
| 36 | + // Man Astronaut |
| 37 | + arrayOf("\uD83D\uDC68\u200D\uD83D\uDE80", false, ERROR_MESSAGE), |
| 38 | + // Skin Tone |
| 39 | + arrayOf("\uD83C\uDFFD", false, ERROR_MESSAGE), |
| 40 | + // Keycap Digit 1 |
| 41 | + arrayOf("1\uFE0F\u20E3", false, ERROR_MESSAGE), |
| 42 | + arrayOf(null, true, null), |
| 43 | + arrayOf(" ", true, null), |
| 44 | + arrayOf("ABCD", true, null), |
| 45 | + arrayOf("あいうえお", true, null), |
| 46 | + arrayOf("Aaあ文1!@#$%^&*()_=-+\";:'{}|\\[]<>?,.", true, null), |
| 47 | + // CJK Unified Ideographs Extension A |
| 48 | + arrayOf("\u4DB5", true, null) |
| 49 | + ) |
| 50 | + } |
| 51 | + |
| 52 | + @get:Rule |
| 53 | + val rxImmediateSchedulerRule = RxImmediateSchedulerRule() |
| 54 | + |
| 55 | + private lateinit var validator: VtlValidator |
| 56 | + |
| 57 | + private val context: Context = RuntimeEnvironment.application |
| 58 | + |
| 59 | + @Before |
| 60 | + fun setUp() { |
| 61 | + validator = NoSpecialCharacterValidator(ERROR_MESSAGE) |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + fun validate() { |
| 66 | + assertEquals(result, validator.validate(text)) |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + fun validateAsCompletable() { |
| 71 | + if (errorMessage == null) { |
| 72 | + validator.validateAsCompletable(context, text).test().assertNoErrors().assertComplete() |
| 73 | + } else { |
| 74 | + validator.validateAsCompletable(context, text).test().assertErrorMessage(errorMessage) |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments