Skip to content

Commit

Permalink
Merge pull request #530 from matomo-org/KotlinUnitTestTools
Browse files Browse the repository at this point in the history
Kotlin Unittest tools
  • Loading branch information
hannesa2 authored Jul 12, 2024
2 parents 763bd78 + d1cf46b commit 76676df
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 239 deletions.
39 changes: 0 additions & 39 deletions tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.java

This file was deleted.

36 changes: 36 additions & 0 deletions tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.matomo.sdk.tools

import android.os.Build
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.junit.MockitoJUnitRunner
import testhelpers.BaseTest

@RunWith(MockitoJUnitRunner::class)
class BuildInfoTest : BaseTest() {
private var buildInfo: BuildInfo? = null

@Before
@Throws(Exception::class)
override fun setup() {
super.setup()
buildInfo = BuildInfo()
}

@Test
fun testGetRelease() {
Assert.assertEquals(Build.VERSION.RELEASE, buildInfo!!.release)
}

@Test
fun testGetModel() {
Assert.assertEquals(Build.MODEL, buildInfo!!.model)
}

@Test
fun testGetBuildId() {
Assert.assertEquals(Build.ID, buildInfo!!.buildId)
}
}
35 changes: 0 additions & 35 deletions tracker/src/test/java/org/matomo/sdk/tools/ChecksumTest.java

This file was deleted.

31 changes: 31 additions & 0 deletions tracker/src/test/java/org/matomo/sdk/tools/ChecksumTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.matomo.sdk.tools

import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.junit.MockitoJUnitRunner
import testhelpers.BaseTest
import java.io.File

@RunWith(MockitoJUnitRunner::class)
class ChecksumTest : BaseTest() {
@Test
@Throws(Exception::class)
fun testgetMD5Checksum() {
val md5 = Checksum.getMD5Checksum("foo")
Assert.assertEquals(md5, "ACBD18DB4CC2F85CEDEF654FCCC4A4D8")
}

@Test
fun testHex() {
Assert.assertNull(Checksum.getHex(null))
}

@Test
@Throws(Exception::class)
fun testgetMD5ChecksumDir() {
val directory = File(".", "")
val md5 = Checksum.getMD5Checksum(directory)
Assert.assertNull(md5)
}
}
54 changes: 0 additions & 54 deletions tracker/src/test/java/org/matomo/sdk/tools/ConnectivityTest.java

This file was deleted.

55 changes: 55 additions & 0 deletions tracker/src/test/java/org/matomo/sdk/tools/ConnectivityTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.matomo.sdk.tools

import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkInfo
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.junit.MockitoJUnitRunner
import testhelpers.BaseTest

@RunWith(MockitoJUnitRunner::class)
class ConnectivityTest : BaseTest() {
@Mock
var context: Context? = null

@Mock
var connectivityManager: ConnectivityManager? = null

@Mock
var networkInfo: NetworkInfo? = null

@Before
override fun setup() {
Mockito.`when`(context!!.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManager)
}

@Test
fun testGetType_none() {
val connectivity = Connectivity(context)
Assert.assertEquals(Connectivity.Type.NONE, connectivity.type)
Mockito.verify(connectivityManager)?.activeNetworkInfo
}

@Test
fun testGetType_wifi() {
val connectivity = Connectivity(context)
Mockito.`when`(connectivityManager!!.activeNetworkInfo).thenReturn(networkInfo)
Mockito.`when`(networkInfo!!.type).thenReturn(ConnectivityManager.TYPE_WIFI)
Assert.assertEquals(Connectivity.Type.WIFI, connectivity.type)
Mockito.verify(connectivityManager)?.activeNetworkInfo
}

@Test
fun testGetType_else() {
val connectivity = Connectivity(context)
Mockito.`when`(connectivityManager!!.activeNetworkInfo).thenReturn(networkInfo)
Mockito.`when`(networkInfo!!.type).thenReturn(ConnectivityManager.TYPE_WIMAX)
Assert.assertEquals(Connectivity.Type.MOBILE, connectivity.type)
Mockito.verify(connectivityManager)?.activeNetworkInfo
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.matomo.sdk.tools

import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.junit.MockitoJUnitRunner
import testhelpers.BaseTest

@RunWith(MockitoJUnitRunner::class)
class CurrencyFormatterTest : BaseTest() {
@Test
fun testCurrencyFormat() {
Assert.assertEquals("10.00", CurrencyFormatter.priceString(1000))
Assert.assertEquals("39.50", CurrencyFormatter.priceString(3950))
Assert.assertEquals("0.01", CurrencyFormatter.priceString(1))
Assert.assertEquals("250.34", CurrencyFormatter.priceString(25034))
Assert.assertEquals("1747.20", CurrencyFormatter.priceString(174720))
Assert.assertEquals("1234567.89", CurrencyFormatter.priceString(123456789))
}
}
53 changes: 0 additions & 53 deletions tracker/src/test/java/org/matomo/sdk/tools/DeviceHelperTest.java

This file was deleted.

Loading

0 comments on commit 76676df

Please sign in to comment.