Skip to content

Commit

Permalink
Feature/fix unit tests (#81)
Browse files Browse the repository at this point in the history
* #FixUiTests: TODO: App && Domain

* Fix Launcher icon

* Fix App Unit Tests

* Fix Domain Unit Tests

* Undo libCore rename

* Arghhh
  • Loading branch information
Entreco authored Oct 4, 2021
1 parent 8d49e46 commit 548dbd0
Show file tree
Hide file tree
Showing 105 changed files with 1,242 additions and 1,156 deletions.
11 changes: 4 additions & 7 deletions android/DartsScorecard/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ android {
def config = rootProject.extensions.getByName("ext")
defaultConfig {
applicationId "nl.entreco.dartsscorecard"
resValue "string", "version", "${config.versionName}"
versionCode config.versionCode
versionName config.versionName

resValue "string", "version", "${config.versionName}"
ndk { abiFilters "armeabi", "armeabi-v7a", "x86", "mips" }
}
buildTypes {
Expand All @@ -23,19 +25,14 @@ android {
}
}

sourceSets.main {
jniLibs.srcDir 'libs'
jni.srcDirs = [] //disable automatic ndk-build call
}

dynamicFeatures = [':sounds']
}

dependencies {

implementation project(':domain')
implementation project(':data')
implementation project(":libcore")
implementation project(':libcore')
implementation project(':libLog')
implementation project(':libConsent')
implementation project(':libAds')
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions android/DartsScorecard/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
android:allowBackup="true"
android:banner="@drawable/tv_promo"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Expand All @@ -26,6 +27,7 @@
<activity
android:name=".splash.SplashActivity"
android:noHistory="true"
android:exported="true"
android:theme="@style/SplashTheme">

<intent-filter>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import javax.inject.Inject
/**
* Created by entreco on 08/02/2018.
*/
class DonateViewModel @Inject constructor(private val analytics: Analytics) : BaseViewModel(), LifecycleObserver {
class DonateViewModel @Inject constructor(
private val analytics: Analytics,
) : BaseViewModel(), LifecycleObserver {

val donations = ObservableArrayList<Donation>()
val loading = ObservableBoolean(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,29 @@ class LiveStatPageAnimator(private val size: Float) {

val statFactor = page.width - size
val animator = MatchStatPageAnimatorHandler(binding.player1, binding.player2, binding.name1,
binding.name2, binding.score,
binding.stat1, binding.stat2, binding.stat3, binding.stat4, binding.stat5,
binding.stat6, binding.stat7,
binding.stat8, binding.stat9, binding.stat10, binding.stat11, binding.setHolder,
statFactor)
binding.name2, binding.score,
binding.stat1, binding.stat2, binding.stat3, binding.stat4, binding.stat5,
binding.stat6, binding.stat7,
binding.stat8, binding.stat9, binding.stat10, binding.stat11, binding.setHolder,
statFactor)
animator.transform(page, position)
}

internal class MatchStatPageAnimatorHandler(private val player1: View,
private val player2: View,
private val name1: View, private val name2: View,
private val score: View,
private val stat1: View, private val stat2: View,
private val stat3: View,
private val stat4: View, private val stat5: View,
private val stat6: View,
private val stat7: View, private val stat8: View,
private val stat9: View,
private val stat10: View, private val stat11: View,
private val setHolder: ViewGroup,
private val statFactor: Float) {
internal class MatchStatPageAnimatorHandler(
private val player1: View,
private val player2: View,
private val name1: View, private val name2: View,
private val score: View,
private val stat1: View, private val stat2: View,
private val stat3: View,
private val stat4: View, private val stat5: View,
private val stat6: View,
private val stat7: View, private val stat8: View,
private val stat9: View,
private val stat10: View, private val stat11: View,
private val setHolder: ViewGroup,
private val statFactor: Float,
) {

// [-1. 1] range of position
fun transform(page: View, position: Float) {
Expand Down Expand Up @@ -82,7 +84,6 @@ class LiveStatPageAnimator(private val size: Float) {
}

private fun animateStat(view: View, position: Float, factor: Float) {
// val x: Float = factor * cos((position - 1) * 0.5 * Math.PI).toFloat()
val x: Float = factor * position
view.animate().translationX(x).setDuration(0).start()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class Setup01Navigator(private val activity: Setup01Activity) : PlayerEditor {
}

override fun onEditPlayer(
position: Int,
player: PlayerViewModel,
otherPlayers: List<Long>,
otherBots: List<Long>
position: Int,
player: PlayerViewModel,
otherPlayers: List<Long>,
otherBots: List<Long>,
) {
if (player.isHuman.get()) {
editPlayerRequest(activity, player.name.get()!!, player.teamIndex.get(), position, otherPlayers, otherBots)
Expand All @@ -43,12 +43,12 @@ class Setup01Navigator(private val activity: Setup01Activity) : PlayerEditor {
}

private fun editPlayerRequest(
activity: Activity,
suggestion: CharSequence,
teamIndex: Int,
positionInList: Int,
otherPlayers: List<Long>,
otherBots: List<Long>
activity: Activity,
suggestion: CharSequence,
teamIndex: Int,
positionInList: Int,
otherPlayers: List<Long>,
otherBots: List<Long>,
) {
val request = Intent(activity, EditPlayerActivity::class.java)
request.putExtra(EXTRA_SUGGESTION, suggestion)
Expand All @@ -75,7 +75,7 @@ class Setup01Navigator(private val activity: Setup01Activity) : PlayerEditor {
when {
botName.isNotEmpty() -> callback.onBotAdded(botName, botId)
suggestion.isEmpty() -> callback.onPlayerAdded(playerName, playerId)
else -> callback.onPlayerAdded(suggestion, playerId)
suggestion.lowercase().startsWith("player") -> callback.onPlayerAdded(suggestion, playerId)
}

} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#CB4105</color>
</resources>
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
package nl.entreco.dartsscorecard.base

import android.app.Activity
import android.content.Context
import android.content.SharedPreferences
import androidx.annotation.StyleRes
import nl.entreco.dartsscorecard.R
import org.junit.Assert.assertEquals
import org.junit.Test
import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import nl.entreco.dartsscorecard.R
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor
import org.mockito.Captor
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner

/**
* Created by Entreco on 10/12/2017.
*/
@RunWith(MockitoJUnitRunner::class)
class StylerTest {

@Mock private lateinit var mockPrefs: SharedPreferences
@Mock private lateinit var mockEditor: SharedPreferences.Editor
@Mock private lateinit var mockActivity: Activity
@InjectMocks private lateinit var subject: Styler

@Captor private lateinit var styleCaptor: ArgumentCaptor<String>
private val mockPrefs: SharedPreferences = mock()
private val mockEditor: SharedPreferences.Editor = mock()
private val mockActivity: Activity = mock{
on { getSharedPreferences("StylePrefs", Context.MODE_PRIVATE) } doReturn mockPrefs
}
private val subject: Styler = Styler(mockActivity)
private val styleCaptor = argumentCaptor<String>()

@Test
fun `it should return 'PDC' style`() {
Expand Down Expand Up @@ -99,7 +96,7 @@ class StylerTest {

subject.switch()
verify(mockEditor).putString(eq("currentStyle"), styleCaptor.capture())
givenStyle(styleCaptor.value)
givenStyle(styleCaptor.lastValue)

verify(mockActivity).recreate()
return subject.get()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package nl.entreco.dartsscorecard.beta.donate

import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import nl.entreco.domain.Analytics
import nl.entreco.domain.beta.Donation
import org.junit.Assert.assertEquals
import org.junit.Test
import org.mockito.kotlin.mock

/**
* Created by entreco on 09/02/2018.
Expand All @@ -18,61 +14,23 @@ class DonateViewModelTest {
private val mockAnalytics: Analytics = mock()
private lateinit var subject: DonateViewModel

private val failCaptor = argumentCaptor<(Throwable) -> Unit>()


@Test
fun `it should set loading(true) when making donations`() {
givenSubject()
whenMakingDonation("sku")
thenLoadingIs(true)
}

@Test
fun `it should set loading(false) when making donations fails`() {
givenSubject()
whenMakingDonationFails(RuntimeException("Alas"))
thenLoadingIs(false)
}

@Test
fun `it should set loading(false) when make donation fails`() {
givenSubject()
whenMakingDonationFails()
thenLoadingIs(false)
}

@Test
fun `it should track Purchase Failed when make donation fails`() {
givenSubject()
whenMakingDonationFails()
thenPurchaseFailedIstracked("Donation ActivityResult failed")
}


private fun givenSubject() {
subject = DonateViewModel(mockAnalytics)
}

private fun givenDonation(productId: String) {
subject.donations.add(Donation("title", "desc", productId, "price", 3, "EUR", 7900000))
}

private fun whenMakingDonation(sku: String) {
val donation = Donation("donation", "desc", sku, "price", 4, "asf", 122222)
subject.onDonate(donation)
}

private fun whenMakingDonationFails(err: Throwable = IllegalStateException("doh")) {
whenMakingDonation("some sku")
failCaptor.lastValue.invoke(err)
}

private fun thenLoadingIs(expected: Boolean) {
assertEquals(expected, subject.loading.get())
}

private fun thenPurchaseFailedIstracked(step: String) {
verify(mockAnalytics).trackPurchaseFailed(any(), eq(step))
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
package nl.entreco.dartsscorecard.di.play

import android.content.Context
import com.google.android.play.core.splitinstall.SplitInstallManager
import nl.entreco.dartsscorecard.play.Play01Activity
import nl.entreco.domain.beta.donations.MakePurchaseResponse
import nl.entreco.domain.repository.AudioPrefRepository
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner
import org.mockito.kotlin.mock

/**
* Created by Entreco on 02/01/2018.
*/
@RunWith(MockitoJUnitRunner::class)
class Play01ModuleTest {

@Mock private lateinit var mockListener: (MakePurchaseResponse) -> Unit
@Mock private lateinit var mockContext: Context
@Mock private lateinit var mockActivity: Play01Activity
private val mockPrefs: AudioPrefRepository = mock()
private val mockSplitInstallManager: SplitInstallManager = mock()
private val mockListener: (MakePurchaseResponse) -> Unit = mock()
private val mockContext: Context = mock()
private val mockActivity: Play01Activity = mock()

@Test
fun `it should not be null`() {
Expand All @@ -30,9 +34,9 @@ class Play01ModuleTest {
assertEquals(mockActivity, subject().provide01Activity())
}

@Test(expected = NullPointerException::class) // SoundPool.Builder
@Test
fun `it should provide SoundRepository`() {
assertNotNull(subject().provideSoundRepository())
assertNotNull(subject().provideSoundRepository(mockContext, mockSplitInstallManager, mockPrefs))
}

@Test
Expand Down
Loading

0 comments on commit 548dbd0

Please sign in to comment.