-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAppsflyerKitTests.kt
More file actions
86 lines (78 loc) · 3 KB
/
AppsflyerKitTests.kt
File metadata and controls
86 lines (78 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.mparticle.kits
import android.content.Context
import com.mparticle.MParticle
import com.mparticle.MParticleOptions
import com.mparticle.commerce.CommerceEvent
import com.mparticle.commerce.Product
import com.mparticle.commerce.TransactionAttributes
import junit.framework.Assert.assertEquals
import org.junit.Assert
import org.junit.Test
import org.mockito.Mockito
class AppsflyerKitTests {
private val kit = AppsFlyerKit()
@Test
@Throws(Exception::class)
fun testGetName() {
val name = kit.name
Assert.assertTrue(name.isNotEmpty())
}
/**
* Kit *should* throw an exception when they're initialized with the wrong settings.
*
*/
@Test
@Throws(Exception::class)
fun testOnKitCreate() {
var e: Throwable? = null
try {
val settings = HashMap<String,String>()
settings["fake setting"] = "fake"
kit.onKitCreate(settings as Map<String?, String?>, Mockito.mock(Context::class.java))
} catch (ex: Throwable) {
e = ex
}
Assert.assertNotNull(e)
}
@Test
@Throws(Exception::class)
fun testClassName() {
val options = Mockito.mock(MParticleOptions::class.java)
val factory = KitIntegrationFactory(options)
val integrations = factory.supportedKits.values
val className = kit.javaClass.name
for (integration in integrations) {
if (integration.name == className) {
return
}
}
Assert.fail("$className not found as a known integration.")
}
@Test
@Throws(Exception::class)
fun testGenerateSkuString() {
MParticle.setInstance(Mockito.mock(MParticle::class.java))
Mockito.`when`(MParticle.getInstance()?.environment)
.thenReturn(MParticle.Environment.Production)
Assert.assertNull(AppsFlyerKit.generateProductIdList(null))
val product = Product.Builder("foo-name", "foo-sku", 50.0).build()
val event = CommerceEvent.Builder(Product.PURCHASE, product)
.transactionAttributes(TransactionAttributes("foo"))
.build()
assertEquals(mutableListOf("foo-sku"), AppsFlyerKit.generateProductIdList(event))
val product2 = Product.Builder("foo-name-2", "foo-sku-2", 50.0).build()
val event2 = CommerceEvent.Builder(Product.PURCHASE, product)
.addProduct(product2)
.transactionAttributes(TransactionAttributes("foo"))
.build()
assertEquals(
mutableListOf("foo-sku","foo-sku-2"), AppsFlyerKit.generateProductIdList(event2))
val product3 = Product.Builder("foo-name-3", "foo-sku-,3", 50.0).build()
val event3 = CommerceEvent.Builder(Product.PURCHASE, product)
.addProduct(product2)
.addProduct(product3)
.transactionAttributes(TransactionAttributes("foo"))
.build()
assertEquals(mutableListOf("foo-sku","foo-sku-2","foo-sku-%2C3"), AppsFlyerKit.generateProductIdList(event3))
}
}