Skip to content

Commit

Permalink
Improve tests naming & asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
skywall committed Dec 18, 2019
1 parent 9dfdbb5 commit 6c3ba12
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ import org.junit.Test
class CoroutineScopeOwnerTest : BaseCoroutineScopeOwnerTest() {

@Test
fun previousExecutionCanceled() {
fun `given 1s delay use case when executed two times then first execution cancelled`() {
val testUseCase = TestUseCase()
var count = 0
var executionCount = 0

testUseCase.execute(1) {
onSuccess { count++ }
onSuccess { executionCount++ }
onError { Assert.fail("Exception thrown where shouldn't") }
}
coroutineScope.advanceTimeBy(500)

testUseCase.execute(1) {
onSuccess { count++ }
onSuccess { executionCount++ }
onError { Assert.fail("Exception thrown where shouldn't") }
}
coroutineScope.advanceTimeBy(1000)

Assert.assertEquals("Previous execution canceled", 1, count)
Assert.assertEquals(1, executionCount)
}

@Test
fun onErrorCalled() {
fun `given failing test use case when executed then indicates onError`() {
val testFailureUseCase = TestFailureUseCase()
var resultError: Throwable? = null

Expand All @@ -43,7 +43,7 @@ class CoroutineScopeOwnerTest : BaseCoroutineScopeOwnerTest() {
}

@Test
fun flowPreviousExecutionCanceled() {
fun `given test flow use case when executed two times then first execution cancelled`() {
val testFlowUseCase = TestFlowUseCase()
val testingList = listOfNotNull(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
val resultList = mutableListOf<Int>()
Expand All @@ -60,11 +60,11 @@ class CoroutineScopeOwnerTest : BaseCoroutineScopeOwnerTest() {
}
coroutineScope.advanceTimeBy(10000)

Assert.assertEquals("Previous execution canceled", testingList, resultList)
Assert.assertEquals(testingList, resultList)
}

@Test
fun flowOnCompleteCalled() {
fun `given test flow use case when executed and all items emitted then completes`() {
val testFlowUseCase = TestFlowUseCase()
var completed = false
val testingList = listOfNotNull(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
Expand All @@ -75,11 +75,11 @@ class CoroutineScopeOwnerTest : BaseCoroutineScopeOwnerTest() {
}
coroutineScope.advanceTimeBy(10000)

Assert.assertEquals("Execution completed successfully", true, completed)
Assert.assertEquals(true, completed)
}

@Test
fun flowOnErrorCalled() {
fun `given failing flow use case when executed then indicates onError`() {
val testFlowFailureUseCase = TestFailureFlowUseCase()
var resultError: Throwable? = null

Expand Down

0 comments on commit 6c3ba12

Please sign in to comment.