From 25f38ed01dd1dfc73298dd9df431ac87509367dc Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Fri, 12 Jul 2024 08:58:44 +0200 Subject: [PATCH 1/2] Kotlin Unittest tools --- .../org/matomo/sdk/tools/BuildInfoTest.java | 39 ------------- .../org/matomo/sdk/tools/BuildInfoTest.kt | 36 ++++++++++++ .../org/matomo/sdk/tools/ChecksumTest.java | 35 ------------ .../java/org/matomo/sdk/tools/ChecksumTest.kt | 31 +++++++++++ .../matomo/sdk/tools/DeviceHelperTest.java | 53 ------------------ .../org/matomo/sdk/tools/DeviceHelperTest.kt | 55 +++++++++++++++++++ 6 files changed, 122 insertions(+), 127 deletions(-) delete mode 100644 tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.java create mode 100644 tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.kt delete mode 100644 tracker/src/test/java/org/matomo/sdk/tools/ChecksumTest.java create mode 100644 tracker/src/test/java/org/matomo/sdk/tools/ChecksumTest.kt delete mode 100644 tracker/src/test/java/org/matomo/sdk/tools/DeviceHelperTest.java create mode 100644 tracker/src/test/java/org/matomo/sdk/tools/DeviceHelperTest.kt diff --git a/tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.java b/tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.java deleted file mode 100644 index a3e6bf64..00000000 --- a/tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.matomo.sdk.tools; - -import android.os.Build; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; - -import testhelpers.BaseTest; - -import static org.junit.Assert.assertEquals; - -@RunWith(MockitoJUnitRunner.class) -public class BuildInfoTest extends BaseTest { - - private BuildInfo mBuildInfo; - - @Before - public void setup() throws Exception { - super.setup(); - mBuildInfo = new BuildInfo(); - } - - @Test - public void testGetRelease() { - assertEquals(Build.VERSION.RELEASE, mBuildInfo.getRelease()); - } - - @Test - public void testGetModel() { - assertEquals(Build.MODEL, mBuildInfo.getModel()); - } - - @Test - public void testGetBuildId() { - assertEquals(Build.ID, mBuildInfo.getBuildId()); - } -} diff --git a/tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.kt b/tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.kt new file mode 100644 index 00000000..cf1576c1 --- /dev/null +++ b/tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.kt @@ -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 mBuildInfo: BuildInfo? = null + + @Before + @Throws(Exception::class) + override fun setup() { + super.setup() + mBuildInfo = BuildInfo() + } + + @Test + fun testGetRelease() { + Assert.assertEquals(Build.VERSION.RELEASE, mBuildInfo!!.release) + } + + @Test + fun testGetModel() { + Assert.assertEquals(Build.MODEL, mBuildInfo!!.model) + } + + @Test + fun testGetBuildId() { + Assert.assertEquals(Build.ID, mBuildInfo!!.buildId) + } +} diff --git a/tracker/src/test/java/org/matomo/sdk/tools/ChecksumTest.java b/tracker/src/test/java/org/matomo/sdk/tools/ChecksumTest.java deleted file mode 100644 index db2e5911..00000000 --- a/tracker/src/test/java/org/matomo/sdk/tools/ChecksumTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.matomo.sdk.tools; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; - -import java.io.File; - -import testhelpers.BaseTest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -@RunWith(MockitoJUnitRunner.class) -public class ChecksumTest extends BaseTest { - - @Test - public void testgetMD5Checksum() throws Exception { - String md5 = Checksum.getMD5Checksum("foo"); - assertEquals(md5, "ACBD18DB4CC2F85CEDEF654FCCC4A4D8"); - } - - @Test - public void testHex() { - assertNull(Checksum.getHex(null)); - } - - @Test - public void testgetMD5ChecksumDir() throws Exception { - File directory = new File(".", ""); - String md5 = Checksum.getMD5Checksum(directory); - assertNull(md5); - } - -} diff --git a/tracker/src/test/java/org/matomo/sdk/tools/ChecksumTest.kt b/tracker/src/test/java/org/matomo/sdk/tools/ChecksumTest.kt new file mode 100644 index 00000000..4922134c --- /dev/null +++ b/tracker/src/test/java/org/matomo/sdk/tools/ChecksumTest.kt @@ -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) + } +} diff --git a/tracker/src/test/java/org/matomo/sdk/tools/DeviceHelperTest.java b/tracker/src/test/java/org/matomo/sdk/tools/DeviceHelperTest.java deleted file mode 100644 index 4c79699f..00000000 --- a/tracker/src/test/java/org/matomo/sdk/tools/DeviceHelperTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.matomo.sdk.tools; - - -import android.content.Context; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -import testhelpers.BaseTest; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class DeviceHelperTest extends BaseTest { - @Mock PropertySource mPropertySource; - @Mock BuildInfo mBuildInfo; - @Mock Context mContext; - private DeviceHelper mDeviceHelper; - - @Before - public void setup() throws Exception { - super.setup(); - when(mBuildInfo.getBuildId()).thenReturn("ABCDEF"); - when(mBuildInfo.getModel()).thenReturn("UnitTest"); - when(mBuildInfo.getRelease()).thenReturn("8.0.0"); - when(mPropertySource.getJVMVersion()).thenReturn("2.2.0"); - mDeviceHelper = new DeviceHelper(mContext, mPropertySource, mBuildInfo); - } - - @Test - public void testGetHttpAgent_normal() { - when(mPropertySource.getHttpAgent()).thenReturn("testagent"); - assertEquals("testagent", mDeviceHelper.getUserAgent()); - } - - @Test - public void testGetHttpAgent_badAgent() { - when(mPropertySource.getHttpAgent()).thenReturn("Apache-HttpClient/UNAVAILABLE (java 1.4)"); - assertEquals("Dalvik/2.2.0 (Linux; U; Android 8.0.0; UnitTest Build/ABCDEF)", mDeviceHelper.getUserAgent()); - verify(mBuildInfo).getBuildId(); - verify(mBuildInfo).getModel(); - verify(mBuildInfo).getRelease(); - verify(mPropertySource).getJVMVersion(); - - when(mPropertySource.getJVMVersion()).thenReturn(null); - assertEquals("Dalvik/0.0.0 (Linux; U; Android 8.0.0; UnitTest Build/ABCDEF)", mDeviceHelper.getUserAgent()); - } -} diff --git a/tracker/src/test/java/org/matomo/sdk/tools/DeviceHelperTest.kt b/tracker/src/test/java/org/matomo/sdk/tools/DeviceHelperTest.kt new file mode 100644 index 00000000..042010b9 --- /dev/null +++ b/tracker/src/test/java/org/matomo/sdk/tools/DeviceHelperTest.kt @@ -0,0 +1,55 @@ +package org.matomo.sdk.tools + +import android.content.Context +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 DeviceHelperTest : BaseTest() { + @Mock + var mPropertySource: PropertySource? = null + + @Mock + var mBuildInfo: BuildInfo? = null + + @Mock + var mContext: Context? = null + private var mDeviceHelper: DeviceHelper? = null + + @Before + @Throws(Exception::class) + override fun setup() { + super.setup() + Mockito.`when`(mBuildInfo!!.buildId).thenReturn("ABCDEF") + Mockito.`when`(mBuildInfo!!.model).thenReturn("UnitTest") + Mockito.`when`(mBuildInfo!!.release).thenReturn("8.0.0") + Mockito.`when`(mPropertySource!!.jvmVersion).thenReturn("2.2.0") + mDeviceHelper = DeviceHelper(mContext, mPropertySource, mBuildInfo) + } + + @Test + fun testGetHttpAgent_normal() { + Mockito.`when`(mPropertySource!!.httpAgent).thenReturn("testagent") + Assert.assertEquals("testagent", mDeviceHelper!!.userAgent) + } + + @Test + fun testGetHttpAgent_badAgent() { + Mockito.`when`(mPropertySource!!.httpAgent).thenReturn("Apache-HttpClient/UNAVAILABLE (java 1.4)") + Assert.assertEquals("Dalvik/2.2.0 (Linux; U; Android 8.0.0; UnitTest Build/ABCDEF)", mDeviceHelper!!.userAgent) + Mockito.verify(mBuildInfo)?.buildId + Mockito.verify(mBuildInfo)?.model + Mockito.verify(mBuildInfo)?.release + Mockito.verify(mPropertySource)?.jvmVersion + + Mockito.`when`(mPropertySource!!.jvmVersion).thenReturn(null) + Assert.assertEquals("Dalvik/0.0.0 (Linux; U; Android 8.0.0; UnitTest Build/ABCDEF)", mDeviceHelper!!.userAgent) + } +} From d1cf46ba75f1a710b11895f8c3261f85557d6618 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Fri, 12 Jul 2024 09:00:57 +0200 Subject: [PATCH 2/2] More Kotlin tools conversions --- .../org/matomo/sdk/tools/BuildInfoTest.kt | 10 ++-- .../matomo/sdk/tools/ConnectivityTest.java | 54 ------------------ .../org/matomo/sdk/tools/ConnectivityTest.kt | 55 +++++++++++++++++++ .../sdk/tools/CurrencyFormatterTest.java | 28 ---------- .../matomo/sdk/tools/CurrencyFormatterTest.kt | 20 +++++++ .../org/matomo/sdk/tools/DeviceHelperTest.kt | 40 +++++++------- .../matomo/sdk/tools/PropertySourceTest.java | 30 ---------- .../matomo/sdk/tools/PropertySourceTest.kt | 26 +++++++++ 8 files changed, 126 insertions(+), 137 deletions(-) delete mode 100644 tracker/src/test/java/org/matomo/sdk/tools/ConnectivityTest.java create mode 100644 tracker/src/test/java/org/matomo/sdk/tools/ConnectivityTest.kt delete mode 100644 tracker/src/test/java/org/matomo/sdk/tools/CurrencyFormatterTest.java create mode 100644 tracker/src/test/java/org/matomo/sdk/tools/CurrencyFormatterTest.kt delete mode 100644 tracker/src/test/java/org/matomo/sdk/tools/PropertySourceTest.java create mode 100644 tracker/src/test/java/org/matomo/sdk/tools/PropertySourceTest.kt diff --git a/tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.kt b/tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.kt index cf1576c1..c4fdb0ff 100644 --- a/tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.kt +++ b/tracker/src/test/java/org/matomo/sdk/tools/BuildInfoTest.kt @@ -10,27 +10,27 @@ import testhelpers.BaseTest @RunWith(MockitoJUnitRunner::class) class BuildInfoTest : BaseTest() { - private var mBuildInfo: BuildInfo? = null + private var buildInfo: BuildInfo? = null @Before @Throws(Exception::class) override fun setup() { super.setup() - mBuildInfo = BuildInfo() + buildInfo = BuildInfo() } @Test fun testGetRelease() { - Assert.assertEquals(Build.VERSION.RELEASE, mBuildInfo!!.release) + Assert.assertEquals(Build.VERSION.RELEASE, buildInfo!!.release) } @Test fun testGetModel() { - Assert.assertEquals(Build.MODEL, mBuildInfo!!.model) + Assert.assertEquals(Build.MODEL, buildInfo!!.model) } @Test fun testGetBuildId() { - Assert.assertEquals(Build.ID, mBuildInfo!!.buildId) + Assert.assertEquals(Build.ID, buildInfo!!.buildId) } } diff --git a/tracker/src/test/java/org/matomo/sdk/tools/ConnectivityTest.java b/tracker/src/test/java/org/matomo/sdk/tools/ConnectivityTest.java deleted file mode 100644 index 1cea548c..00000000 --- a/tracker/src/test/java/org/matomo/sdk/tools/ConnectivityTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.matomo.sdk.tools; - -import android.content.Context; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -import testhelpers.BaseTest; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class ConnectivityTest extends BaseTest { - @Mock Context mContext; - @Mock ConnectivityManager mConnectivityManager; - @Mock NetworkInfo mNetworkInfo; - - @Before - public void setup() { - when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(mConnectivityManager); - } - - @Test - public void testGetType_none() { - Connectivity connectivity = new Connectivity(mContext); - assertEquals(Connectivity.Type.NONE, connectivity.getType()); - verify(mConnectivityManager).getActiveNetworkInfo(); - } - - @Test - public void testGetType_wifi() { - Connectivity connectivity = new Connectivity(mContext); - when(mConnectivityManager.getActiveNetworkInfo()).thenReturn(mNetworkInfo); - when(mNetworkInfo.getType()).thenReturn(ConnectivityManager.TYPE_WIFI); - assertEquals(Connectivity.Type.WIFI, connectivity.getType()); - verify(mConnectivityManager).getActiveNetworkInfo(); - } - - @Test - public void testGetType_else() { - Connectivity connectivity = new Connectivity(mContext); - when(mConnectivityManager.getActiveNetworkInfo()).thenReturn(mNetworkInfo); - when(mNetworkInfo.getType()).thenReturn(ConnectivityManager.TYPE_WIMAX); - assertEquals(Connectivity.Type.MOBILE, connectivity.getType()); - verify(mConnectivityManager).getActiveNetworkInfo(); - } -} diff --git a/tracker/src/test/java/org/matomo/sdk/tools/ConnectivityTest.kt b/tracker/src/test/java/org/matomo/sdk/tools/ConnectivityTest.kt new file mode 100644 index 00000000..cb87136b --- /dev/null +++ b/tracker/src/test/java/org/matomo/sdk/tools/ConnectivityTest.kt @@ -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 + } +} diff --git a/tracker/src/test/java/org/matomo/sdk/tools/CurrencyFormatterTest.java b/tracker/src/test/java/org/matomo/sdk/tools/CurrencyFormatterTest.java deleted file mode 100644 index 8828b0c1..00000000 --- a/tracker/src/test/java/org/matomo/sdk/tools/CurrencyFormatterTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.matomo.sdk.tools; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; - -import testhelpers.BaseTest; - -import static org.junit.Assert.assertEquals; - -@RunWith(MockitoJUnitRunner.class) -public class CurrencyFormatterTest extends BaseTest { - - @Test - public void testCurrencyFormat() { - assertEquals("10.00", CurrencyFormatter.priceString(1000)); - - assertEquals("39.50", CurrencyFormatter.priceString(3950)); - - assertEquals("0.01", CurrencyFormatter.priceString(1)); - - assertEquals("250.34", CurrencyFormatter.priceString(25034)); - - assertEquals("1747.20", CurrencyFormatter.priceString(174720)); - - assertEquals("1234567.89", CurrencyFormatter.priceString(123456789)); - } -} diff --git a/tracker/src/test/java/org/matomo/sdk/tools/CurrencyFormatterTest.kt b/tracker/src/test/java/org/matomo/sdk/tools/CurrencyFormatterTest.kt new file mode 100644 index 00000000..2c6ea8fe --- /dev/null +++ b/tracker/src/test/java/org/matomo/sdk/tools/CurrencyFormatterTest.kt @@ -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)) + } +} diff --git a/tracker/src/test/java/org/matomo/sdk/tools/DeviceHelperTest.kt b/tracker/src/test/java/org/matomo/sdk/tools/DeviceHelperTest.kt index 042010b9..ce8e3590 100644 --- a/tracker/src/test/java/org/matomo/sdk/tools/DeviceHelperTest.kt +++ b/tracker/src/test/java/org/matomo/sdk/tools/DeviceHelperTest.kt @@ -14,42 +14,42 @@ import testhelpers.BaseTest @RunWith(MockitoJUnitRunner::class) class DeviceHelperTest : BaseTest() { @Mock - var mPropertySource: PropertySource? = null + var propertySource: PropertySource? = null @Mock - var mBuildInfo: BuildInfo? = null + var buildInfo: BuildInfo? = null @Mock - var mContext: Context? = null - private var mDeviceHelper: DeviceHelper? = null + var context: Context? = null + private var deviceHelper: DeviceHelper? = null @Before @Throws(Exception::class) override fun setup() { super.setup() - Mockito.`when`(mBuildInfo!!.buildId).thenReturn("ABCDEF") - Mockito.`when`(mBuildInfo!!.model).thenReturn("UnitTest") - Mockito.`when`(mBuildInfo!!.release).thenReturn("8.0.0") - Mockito.`when`(mPropertySource!!.jvmVersion).thenReturn("2.2.0") - mDeviceHelper = DeviceHelper(mContext, mPropertySource, mBuildInfo) + Mockito.`when`(buildInfo!!.buildId).thenReturn("ABCDEF") + Mockito.`when`(buildInfo!!.model).thenReturn("UnitTest") + Mockito.`when`(buildInfo!!.release).thenReturn("8.0.0") + Mockito.`when`(propertySource!!.jvmVersion).thenReturn("2.2.0") + deviceHelper = DeviceHelper(context, propertySource, buildInfo) } @Test fun testGetHttpAgent_normal() { - Mockito.`when`(mPropertySource!!.httpAgent).thenReturn("testagent") - Assert.assertEquals("testagent", mDeviceHelper!!.userAgent) + Mockito.`when`(propertySource!!.httpAgent).thenReturn("testagent") + Assert.assertEquals("testagent", deviceHelper!!.userAgent) } @Test fun testGetHttpAgent_badAgent() { - Mockito.`when`(mPropertySource!!.httpAgent).thenReturn("Apache-HttpClient/UNAVAILABLE (java 1.4)") - Assert.assertEquals("Dalvik/2.2.0 (Linux; U; Android 8.0.0; UnitTest Build/ABCDEF)", mDeviceHelper!!.userAgent) - Mockito.verify(mBuildInfo)?.buildId - Mockito.verify(mBuildInfo)?.model - Mockito.verify(mBuildInfo)?.release - Mockito.verify(mPropertySource)?.jvmVersion - - Mockito.`when`(mPropertySource!!.jvmVersion).thenReturn(null) - Assert.assertEquals("Dalvik/0.0.0 (Linux; U; Android 8.0.0; UnitTest Build/ABCDEF)", mDeviceHelper!!.userAgent) + Mockito.`when`(propertySource!!.httpAgent).thenReturn("Apache-HttpClient/UNAVAILABLE (java 1.4)") + Assert.assertEquals("Dalvik/2.2.0 (Linux; U; Android 8.0.0; UnitTest Build/ABCDEF)", deviceHelper!!.userAgent) + Mockito.verify(buildInfo)?.buildId + Mockito.verify(buildInfo)?.model + Mockito.verify(buildInfo)?.release + Mockito.verify(propertySource)?.jvmVersion + + Mockito.`when`(propertySource!!.jvmVersion).thenReturn(null) + Assert.assertEquals("Dalvik/0.0.0 (Linux; U; Android 8.0.0; UnitTest Build/ABCDEF)", deviceHelper!!.userAgent) } } diff --git a/tracker/src/test/java/org/matomo/sdk/tools/PropertySourceTest.java b/tracker/src/test/java/org/matomo/sdk/tools/PropertySourceTest.java deleted file mode 100644 index 92806047..00000000 --- a/tracker/src/test/java/org/matomo/sdk/tools/PropertySourceTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.matomo.sdk.tools; - -import org.junit.Test; - -import testhelpers.BaseTest; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; - - -public class PropertySourceTest extends BaseTest { - @Test - public void testGetHttpAgent() { - PropertySource propertySource = spy(new PropertySource()); - propertySource.getHttpAgent(); - verify(propertySource).getSystemProperty("http.agent"); - - assertEquals(propertySource.getHttpAgent(), propertySource.getSystemProperty("http.agent")); - } - - @Test - public void testGetJVMVersion() { - PropertySource propertySource = spy(new PropertySource()); - propertySource.getJVMVersion(); - verify(propertySource).getSystemProperty("java.vm.version"); - - assertEquals(propertySource.getJVMVersion(), propertySource.getSystemProperty("java.vm.version")); - } -} diff --git a/tracker/src/test/java/org/matomo/sdk/tools/PropertySourceTest.kt b/tracker/src/test/java/org/matomo/sdk/tools/PropertySourceTest.kt new file mode 100644 index 00000000..aa2204bb --- /dev/null +++ b/tracker/src/test/java/org/matomo/sdk/tools/PropertySourceTest.kt @@ -0,0 +1,26 @@ +package org.matomo.sdk.tools + +import org.junit.Assert +import org.junit.Test +import org.mockito.Mockito +import testhelpers.BaseTest + +class PropertySourceTest : BaseTest() { + @Test + fun testGetHttpAgent() { + val propertySource = Mockito.spy(PropertySource()) + propertySource.httpAgent + Mockito.verify(propertySource).getSystemProperty("http.agent") + + Assert.assertEquals(propertySource.httpAgent, propertySource.getSystemProperty("http.agent")) + } + + @Test + fun testGetJVMVersion() { + val propertySource = Mockito.spy(PropertySource()) + propertySource.jvmVersion + Mockito.verify(propertySource).getSystemProperty("java.vm.version") + + Assert.assertEquals(propertySource.jvmVersion, propertySource.getSystemProperty("java.vm.version")) + } +}