Skip to content

Commit

Permalink
#50: Update UnitTests
Browse files Browse the repository at this point in the history
  • Loading branch information
Entreco committed Jul 28, 2018
1 parent 72e4764 commit 5072d38
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class VoteViewModelTest {
givenSubject()
whenFeatureSelected(mockModel)
whenSubmittingDonationSucceeds()
thenViewFeatureIsTracked()
thenViewFeatureIsTracked(1)
}

@Test
Expand Down Expand Up @@ -176,8 +176,8 @@ class VoteViewModelTest {
assertFalse(subject.votes.contains(expected))
}

private fun thenViewFeatureIsTracked() {
verify(mockAnalytics).trackViewFeature(any(), amount)
private fun thenViewFeatureIsTracked(amount: Int) {
verify(mockAnalytics).trackViewFeature(any(), eq(amount))
}

private fun thenVideoIsLaunched() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package nl.entreco.data.wtf

import nl.entreco.data.api.beta.FeatureApiData
import org.junit.Assert.*
import org.junit.Test

class FaqApiDataTest{
private val subject = FaqApiData()

@Test
fun `video is empty initially`() {
assertEquals("", subject.video)
}

@Test
fun `image is empty initially`() {
assertEquals("", subject.image)
}

@Test
fun `title is empty initially`() {
assertEquals("", subject.title)
}

@Test
fun `desc is empty initially`() {
assertEquals("", subject.desc)
}

@Test
fun `viewed is zero initially`() {
assertEquals(0, subject.viewed)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package nl.entreco.domain.profile.fetch

import org.junit.Test

import org.junit.Assert.*

class FetchProfileStatRequestTest {

@Test
fun `should be equal`() {
val one = FetchProfileStatRequest(longArrayOf(1,2,34))
val two = FetchProfileStatRequest(longArrayOf(1,2,34))
assertEquals(one, two)
}

@Test
fun `should not be equal`() {
val one = FetchProfileStatRequest(longArrayOf(1,2,34))
val two = FetchProfileStatRequest(longArrayOf(1,2,3,4))
assertNotEquals(one, two)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package nl.entreco.domain.wtf

import com.nhaarman.mockito_kotlin.any
import com.nhaarman.mockito_kotlin.verify
import nl.entreco.domain.Analytics
import nl.entreco.domain.common.executors.TestBackground
import nl.entreco.domain.common.executors.TestForeground
import nl.entreco.domain.repository.WtfRepository
import org.junit.Test

import org.junit.Assert.*
import org.junit.Before
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner

@RunWith(MockitoJUnitRunner::class)
class SubmitViewedItemUsecaseTest {

private val bg = TestBackground()
private val fg = TestForeground()
@Mock private lateinit var mockRepo: WtfRepository
@Mock private lateinit var mockAnalytics: Analytics
private lateinit var subject : SubmitViewedItemUsecase


@Before
fun setUp() {
subject = SubmitViewedItemUsecase(mockRepo, mockAnalytics, bg, fg)
}

@Test
fun `it should use repo`() {
whenExecuting("some id")
verify(mockRepo).viewedItem("some id")
}

@Test
fun `it should track analytics`() {
whenExecuting("another Id")
verify(mockAnalytics).trackViewFaq(any())
}

private fun whenExecuting(docId: String) {
subject.exec(SubmitViewedItemRequest(WtfItem(docId, "tit", "desc", "img", "vid", 2)))
}
}

0 comments on commit 5072d38

Please sign in to comment.