-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #530 from matomo-org/KotlinUnitTestTools
Kotlin Unittest tools
- Loading branch information
Showing
12 changed files
with
223 additions
and
239 deletions.
There are no files selected for viewing
39 changes: 0 additions & 39 deletions
39
tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.java
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
tracker/src/test/java/org/matomo/sdk/tools/ChecksumTest.java
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
tracker/src/test/java/org/matomo/sdk/tools/ChecksumTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
54
tracker/src/test/java/org/matomo/sdk/tools/ConnectivityTest.java
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
tracker/src/test/java/org/matomo/sdk/tools/ConnectivityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
tracker/src/test/java/org/matomo/sdk/tools/CurrencyFormatterTest.java
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
tracker/src/test/java/org/matomo/sdk/tools/CurrencyFormatterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
53
tracker/src/test/java/org/matomo/sdk/tools/DeviceHelperTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.