Skip to content

Commit

Permalink
Clean up test warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mscwilson committed Apr 17, 2024
1 parent 55f5656 commit 5f86699
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.junit.runner.RunWith
class AbstractEventTest {

@Test
@Suppress("deprecation")
fun testAddsEntitiesUsingAllAPIs() {
val event = ScreenView("screen")
val entity1 = SelfDescribingJson("schema1", "data1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class DeepLinkReceivedTest {
val events = eventStore.getEmittableEvents(10)
eventStore.removeAllEvents()
Assert.assertEquals(1, events.size.toLong())
val payload = events[0]!!.payload
val payload = events[0].payload

// Check url and referrer fields for atomic table
val url = payload.map[Parameters.PAGE_URL] as String?
Expand Down Expand Up @@ -135,7 +135,7 @@ class DeepLinkReceivedTest {
Assert.assertEquals(2, events.size.toLong())
var screenViewPayload: Map<*, *>? = null
for (emitterEvent in events) {
if (emitterEvent!!.payload.map["eid"] == screenViewEventId.toString()) {
if (emitterEvent.payload.map["eid"] == screenViewEventId.toString()) {
screenViewPayload = emitterEvent.payload.map
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import org.junit.runner.RunWith
import java.lang.Exception

@RunWith(AndroidJUnit4::class)
@Suppress("deprecation")
class EcommerceItemTest {
// NB this event type has been deprecated

@Test
fun testExpectedForm() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@Suppress("deprecation")
class EcommerceTransactionTest {
// NB this event type has been deprecated

@Test
fun testExpectedForm() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class MessageNotificationTest {
@Test
@Suppress("unchecked_cast")
fun testExpectedForm() {
val event = MessageNotification("title", "body", MessageNotificationTrigger.push)
.notificationTimestamp("2020-12-31T15:59:60-08:00")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class RemoteConfigurationTest {
"{\"\$schema\":\"http://iglucentral.com/schemas/com.snowplowanalytics.mobile/remote_config/jsonschema/1-0-0\",\"configurationVersion\":12,\"configurationBundle\":[]}"
withMockServer(200, body) { _, endpoint ->

val expectation = Any() as Object
val expectation = Object()
val remoteConfig = RemoteConfiguration(endpoint, HttpMethod.GET)
RemoteConfigurationFetcher(
context,
Expand Down Expand Up @@ -180,7 +180,7 @@ class RemoteConfigurationTest {
) { _, endpoint ->

// test
val expectation = Any() as Object
val expectation = Object()
val expectationNotified = AtomicBoolean(false)
val remoteConfig = RemoteConfiguration(endpoint, HttpMethod.GET)
RemoteConfigurationFetcher(
Expand Down Expand Up @@ -333,7 +333,7 @@ class RemoteConfigurationTest {
cached.configurationVersion = 1
cached.configurationBundle = listOf(bundle)
cache.writeCache(context, cached)
val expectation = Any() as Object
val expectation = Object()
val provider = RemoteConfigurationProvider(remoteConfig)
provider.retrieveConfiguration(
context,
Expand Down Expand Up @@ -371,7 +371,7 @@ class RemoteConfigurationTest {
cached.configurationVersion = 1
cached.configurationBundle = listOf(bundle)
cache.writeCache(context, cached)
val expectation = Any() as Object
val expectation = Object()
val provider = RemoteConfigurationProvider(remoteConfig)
provider.retrieveConfiguration(
context,
Expand All @@ -387,7 +387,7 @@ class RemoteConfigurationTest {
mockWebServer.enqueue(mockResponse)

// test
val expectation2 = Any() as Object
val expectation2 = Object()
var numCallbackCalls = 0
provider.retrieveConfiguration(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ConfigurationTest {
@Test
@Throws(InterruptedException::class)
fun sessionConfigurationCallback() {
val expectation = Any() as Object
val expectation = Object()
val callbackExecuted = AtomicBoolean(false)
val context = InstrumentationRegistry.getInstrumentation().targetContext

Expand Down Expand Up @@ -148,8 +148,8 @@ class ConfigurationTest {
@Test
@Throws(InterruptedException::class)
fun sessionConfigurationCallbackAfterNewSession() {
val expectation1 = Any() as Object
val expectation2 = Any() as Object
val expectation1 = Object()
val expectation2 = Object()
val callbackExecuted = AtomicBoolean(false)
val sessionId = AtomicReference<String?>(null)
val context = InstrumentationRegistry.getInstrumentation().targetContext
Expand Down Expand Up @@ -264,7 +264,7 @@ class ConfigurationTest {
val events = eventStore.getEmittableEvents(10)
eventStore.removeAllEvents()
Assert.assertEquals(1, events.size.toLong())
val payload = events[0]!!.payload
val payload = events[0].payload

// Check v_tracker field
val versionTracker = payload.map["tv"] as String?
Expand Down Expand Up @@ -316,7 +316,7 @@ class ConfigurationTest {
var events = eventStore.getEmittableEvents(10)
eventStore.removeAllEvents()
Assert.assertEquals(1, events.size.toLong())
var payload = events[0]!!.payload
var payload = events[0].payload
var contexts = payload.map["co"] as String?
Assert.assertTrue(contexts!!.contains("\"basisForProcessing\":\"contract\""))
Assert.assertTrue(contexts.contains("\"documentId\":\"id1\""))
Expand All @@ -337,7 +337,7 @@ class ConfigurationTest {
events = eventStore.getEmittableEvents(10)
eventStore.removeAllEvents()
Assert.assertEquals(1, events.size.toLong())
payload = events[0]!!.payload
payload = events[0].payload
contexts = payload.map["co"] as String?
Assert.assertFalse(contexts!!.contains("\"basisForProcessing\":\"contract\""))
Assert.assertFalse(contexts.contains("\"documentId\":\"id1\""))
Expand Down Expand Up @@ -382,7 +382,7 @@ class ConfigurationTest {
var events = eventStore.getEmittableEvents(10)
eventStore.removeAllEvents()
Assert.assertEquals(1, events.size.toLong())
var payload = events[0]!!.payload
var payload = events[0].payload
var contexts = payload.map["co"] as String?
Assert.assertFalse(contexts!!.contains("\"basisForProcessing\""))

Expand All @@ -403,7 +403,7 @@ class ConfigurationTest {
events = eventStore.getEmittableEvents(10)
eventStore.removeAllEvents()
Assert.assertEquals(1, events.size.toLong())
payload = events[0]!!.payload
payload = events[0].payload
contexts = payload.map["co"] as String?
Assert.assertTrue(contexts!!.contains("\"basisForProcessing\":\"contract\""))
Assert.assertTrue(contexts.contains("\"documentId\":\"id2\""))
Expand Down Expand Up @@ -462,7 +462,7 @@ class ConfigurationTest {
val events = eventStore.getEmittableEvents(10)
eventStore.removeAllEvents()
Assert.assertEquals(1, events.size.toLong())
val payload = events[0]!!.payload
val payload = events[0].payload
val contexts = payload.map["co"] as String?
Assert.assertTrue(contexts!!.contains("value1"))
Assert.assertTrue(contexts.contains("value2"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MockDeviceInfoMonitor : DeviceInfoMonitor() {
return "wifi"
}

override fun getNetworkTechnology(networkInfo: NetworkInfo?): String? {
override fun getNetworkTechnology(networkInfo: NetworkInfo?): String {
increaseMethodAccessCount("getNetworkTechnology")
return "3g"
}
Expand All @@ -71,7 +71,7 @@ class MockDeviceInfoMonitor : DeviceInfoMonitor() {
return 10
}

override fun getBatteryStateAndLevel(context: Context): Pair<String?, Int>? {
override fun getBatteryStateAndLevel(context: Context): Pair<String?, Int> {
increaseMethodAccessCount("getBatteryStateAndLevel")
return Pair("charging", 20)
}
Expand All @@ -97,22 +97,22 @@ class MockDeviceInfoMonitor : DeviceInfoMonitor() {
_language = value
}

override fun getResolution(context: Context): String? {
override fun getResolution(context: Context): String {
increaseMethodAccessCount("getResolution")
return "1024x768"
}

override fun getScale(context: Context): Float? {
override fun getScale(context: Context): Float {
increaseMethodAccessCount("getScale")
return 2.0f
}

override fun getIsPortrait(context: Context): Boolean? {
override fun getIsPortrait(context: Context): Boolean {
increaseMethodAccessCount("getIsPortrait")
return true
}

override fun getAppSetIdAndScope(context: Context): Pair<String, String>? {
override fun getAppSetIdAndScope(context: Context): Pair<String, String> {
increaseMethodAccessCount("getAppSetIdAndScope")
return Pair("XXX", "app")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ class MultipleInstancesTest {
fun testDefaultTracker() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val t1 = createTracker(context, "t1", NetworkConfiguration("snowplowanalytics.fake"))
val t2 = createTracker(context, "t2", NetworkConfiguration("snowplowanalytics.fake2"))
createTracker(context, "t2", NetworkConfiguration("snowplowanalytics.fake2"))
val td = defaultTracker
Assert.assertEquals(t1, td)
}

@Test
fun testUpdateDefaultTracker() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val t1 = createTracker(context, "t1", NetworkConfiguration("snowplowanalytics.fake"))
createTracker(context, "t1", NetworkConfiguration("snowplowanalytics.fake"))
val t2 = createTracker(context, "t2", NetworkConfiguration("snowplowanalytics.fake2"))
setTrackerAsDefault(t2)
val td = defaultTracker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import kotlin.collections.ArrayList
@RunWith(AndroidJUnit4::class)
class StateManagerTest {
@Test
@Suppress("unchecked_cast")
fun testStateManager() {
val stateManager = StateManager()
stateManager.addOrReplaceStateMachine(MockStateMachine())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ExecutorTest {
@Test
@Throws(InterruptedException::class)
fun testExecutorRaisingException() {
val expectation = Any() as Object
val expectation = Object()
val exceptionRaised = AtomicBoolean(false)
execute({ throw NullPointerException() }) { t: Throwable? ->
exceptionRaised.set(t is NullPointerException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class FocalMeterConfigurationTest {
// --- TESTS
@Test
fun logsSuccessfulRequest() {
withMockServer(200) { mockServer, endpoint ->
withMockServer(200) { _, endpoint ->
val focalMeter = FocalMeterConfiguration(endpoint)
val debugs = mutableListOf<String>()
val loggerDelegate = createLoggerDelegate(debugs = debugs)
Expand All @@ -68,10 +68,10 @@ class FocalMeterConfigurationTest {

@Test
fun logsSuccessfulRequestWithProcessedUserId() {
withMockServer(200) { mockServer, endpoint ->
withMockServer(200) { _, endpoint ->
val focalMeter = FocalMeterConfiguration(
kantarEndpoint = endpoint,
processUserId = { userId -> "processed-" + userId }
processUserId = { userId -> "processed-$userId" }
)
val debugs = mutableListOf<String>()
val loggerDelegate = createLoggerDelegate(debugs = debugs)
Expand All @@ -94,7 +94,7 @@ class FocalMeterConfigurationTest {

@Test
fun makesAnotherRequestWhenUserIdChanges() {
withMockServer(200) { mockServer, endpoint ->
withMockServer(200) { _, endpoint ->
val focalMeter = FocalMeterConfiguration(endpoint)
val debugs = mutableListOf<String>()
val loggerDelegate = createLoggerDelegate(debugs = debugs)
Expand All @@ -113,21 +113,21 @@ class FocalMeterConfigurationTest {
Assert.assertEquals(
1,
debugs.filter {
it.contains("Request to Kantar endpoint sent with user ID: ${firstUserId}")
it.contains("Request to Kantar endpoint sent with user ID: $firstUserId")
}.size
)
Assert.assertEquals(
1,
debugs.filter {
it.contains("Request to Kantar endpoint sent with user ID: ${secondUserId}")
it.contains("Request to Kantar endpoint sent with user ID: $secondUserId")
}.size
)
}
}

@Test
fun logsFailedRequest() {
withMockServer(500) { mockServer, endpoint ->
withMockServer(500) { _, endpoint ->
val focalMeter = FocalMeterConfiguration(endpoint)
val errors = mutableListOf<String>()
val loggerDelegate = createLoggerDelegate(errors = errors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MockEventStore : EventStore {
override fun removeEvents(ids: MutableList<Long>): Boolean {
var result = true
for (id in ids) {
val removed = removeEvent(id!!)
val removed = removeEvent(id)
result = result && removed
}
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class NetworkConnectionTest {
// Check successful result
val result = results[0]
Assert.assertTrue(result.isSuccessful)
Assert.assertEquals(1, result.eventIds[0]!!.toLong())
Assert.assertEquals(1, result.eventIds[0])
mockServer.shutdown()
}

Expand All @@ -82,7 +82,7 @@ class NetworkConnectionTest {
// Check unsuccessful result
val result = results[0]
Assert.assertFalse(result.isSuccessful)
Assert.assertEquals(1, result.eventIds[0]!!.toLong())
Assert.assertEquals(1, result.eventIds[0])
mockServer.shutdown()
}

Expand Down Expand Up @@ -111,7 +111,7 @@ class NetworkConnectionTest {
// Check successful result
val result = results[0]
Assert.assertTrue(result.isSuccessful)
Assert.assertEquals(1, result.eventIds[0]!!.toLong())
Assert.assertEquals(1, result.eventIds[0])
mockServer.shutdown()
}

Expand All @@ -135,7 +135,7 @@ class NetworkConnectionTest {
// Check unsuccessful result
val result = results[0]
Assert.assertFalse(result.isSuccessful)
Assert.assertEquals(1, result.eventIds[0]!!.toLong())
Assert.assertEquals(1, result.eventIds[0])
mockServer.shutdown()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ class SessionTest {
return Session(foregroundTimeout, backgroundTimeout, TimeUnit.SECONDS, null, context)
}

@Suppress("unchecked_cast")
private fun getSessionContext(
session: Session?,
eventId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ class EventSendingTest {
)
}

@Suppress("deprecation")
private fun trackEcommerceEvent(tracker: Tracker) {
val item = EcommerceTransactionItem("sku-1", 35.00, 1).name("Acme 1").category("Stuff")
.currency("AUD")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class NoiseTest {
}

companion object {
@Suppress("unchecked_cast")
private fun superficialEnumCodeCoverage(enumClass: Class<out Enum<*>?>) {
try {
for (o in enumClass.getMethod("values").invoke(null) as Array<Any>) {
Expand Down

0 comments on commit 5f86699

Please sign in to comment.