|
|
@ -39,6 +39,8 @@ import org.mockito.Mockito.`when` |
|
|
|
import org.mockito.Mockito.mock |
|
|
|
import org.mockito.Mockito.mock |
|
|
|
import org.robolectric.Robolectric |
|
|
|
import org.robolectric.Robolectric |
|
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4 |
|
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4 |
|
|
|
|
|
|
|
import io.reactivex.Single |
|
|
|
|
|
|
|
import io.reactivex.SingleObserver |
|
|
|
import org.robolectric.annotation.Config |
|
|
|
import org.robolectric.annotation.Config |
|
|
|
import org.robolectric.fakes.RoboMenuItem |
|
|
|
import org.robolectric.fakes.RoboMenuItem |
|
|
|
import retrofit2.Call |
|
|
|
import retrofit2.Call |
|
|
@ -77,7 +79,7 @@ class ComposeActivityTest { |
|
|
|
notificationVibration = true, |
|
|
|
notificationVibration = true, |
|
|
|
notificationLight = true |
|
|
|
notificationLight = true |
|
|
|
) |
|
|
|
) |
|
|
|
var instanceResponseCallback: ((Call<Instance>?, Callback<Instance>?)->Unit)? = null |
|
|
|
var instanceResponseCallback: (()->Instance)? = null |
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
@Before |
|
|
|
fun setupActivity() { |
|
|
|
fun setupActivity() { |
|
|
@ -109,28 +111,14 @@ class ComposeActivityTest { |
|
|
|
|
|
|
|
|
|
|
|
override fun enqueue(callback: Callback<List<Emoji>>?) {} |
|
|
|
override fun enqueue(callback: Callback<List<Emoji>>?) {} |
|
|
|
}) |
|
|
|
}) |
|
|
|
`when`(apiMock.instance).thenReturn(object: Call<Instance> { |
|
|
|
`when`(apiMock.instance).thenReturn(object: Single<Instance>() { |
|
|
|
override fun isExecuted(): Boolean { |
|
|
|
override fun subscribeActual(observer: SingleObserver<in Instance>) { |
|
|
|
return false |
|
|
|
val instance = instanceResponseCallback?.invoke() |
|
|
|
} |
|
|
|
if (instance == null) { |
|
|
|
override fun clone(): Call<Instance> { |
|
|
|
observer.onError(Throwable()) |
|
|
|
throw Error("not implemented") |
|
|
|
} else { |
|
|
|
} |
|
|
|
observer.onSuccess(instance) |
|
|
|
override fun isCanceled(): Boolean { |
|
|
|
} |
|
|
|
throw Error("not implemented") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
override fun cancel() { |
|
|
|
|
|
|
|
throw Error("not implemented") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
override fun execute(): Response<Instance> { |
|
|
|
|
|
|
|
throw Error("not implemented") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
override fun request(): Request { |
|
|
|
|
|
|
|
throw Error("not implemented") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun enqueue(callback: Callback<Instance>?) { |
|
|
|
|
|
|
|
instanceResponseCallback?.invoke(this, callback) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -181,7 +169,7 @@ class ComposeActivityTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun whenMaximumTootCharsIsNull_defaultLimitIsUsed() { |
|
|
|
fun whenMaximumTootCharsIsNull_defaultLimitIsUsed() { |
|
|
|
instanceResponseCallback = getSuccessResponseCallbackWithMaximumTootCharacters(null) |
|
|
|
instanceResponseCallback = { getInstanceWithMaximumTootCharacters(null) } |
|
|
|
setupActivity() |
|
|
|
setupActivity() |
|
|
|
assertEquals(ComposeActivity.STATUS_CHARACTER_LIMIT, activity.maximumTootCharacters) |
|
|
|
assertEquals(ComposeActivity.STATUS_CHARACTER_LIMIT, activity.maximumTootCharacters) |
|
|
|
} |
|
|
|
} |
|
|
@ -189,23 +177,11 @@ class ComposeActivityTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun whenMaximumTootCharsIsPopulated_customLimitIsUsed() { |
|
|
|
fun whenMaximumTootCharsIsPopulated_customLimitIsUsed() { |
|
|
|
val customMaximum = 1000 |
|
|
|
val customMaximum = 1000 |
|
|
|
instanceResponseCallback = getSuccessResponseCallbackWithMaximumTootCharacters(customMaximum) |
|
|
|
instanceResponseCallback = { getInstanceWithMaximumTootCharacters(customMaximum) } |
|
|
|
setupActivity() |
|
|
|
setupActivity() |
|
|
|
assertEquals(customMaximum, activity.maximumTootCharacters) |
|
|
|
assertEquals(customMaximum, activity.maximumTootCharacters) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
fun whenInitialInstanceRequestFails_defaultValueIsUsed() { |
|
|
|
|
|
|
|
instanceResponseCallback = { |
|
|
|
|
|
|
|
call: Call<Instance>?, callback: Callback<Instance>? -> |
|
|
|
|
|
|
|
if (call != null) { |
|
|
|
|
|
|
|
callback?.onResponse(call, Response.error(400, ResponseBody.create(null, ""))) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
setupActivity() |
|
|
|
|
|
|
|
assertEquals(ComposeActivity.STATUS_CHARACTER_LIMIT, activity.maximumTootCharacters) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun whenTextContainsNoUrl_everyCharacterIsCounted() { |
|
|
|
fun whenTextContainsNoUrl_everyCharacterIsCounted() { |
|
|
|
val content = "This is test content please ignore thx " |
|
|
|
val content = "This is test content please ignore thx " |
|
|
@ -281,7 +257,8 @@ class ComposeActivityTest { |
|
|
|
emptyList(), |
|
|
|
emptyList(), |
|
|
|
emptyList() |
|
|
|
emptyList() |
|
|
|
), |
|
|
|
), |
|
|
|
maximumTootCharacters |
|
|
|
maximumTootCharacters, |
|
|
|
|
|
|
|
null |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|