1+ package com.readdle.swiftjava.sample
2+
3+ import android.support.test.runner.AndroidJUnit4
4+ import com.readdle.codegen.anotation.JavaSwift
5+ import com.readdle.codegen.anotation.SwiftError
6+ import com.readdle.swiftjava.sample.SampleValue.Companion.funcThrows
7+ import com.readdle.swiftjava.sample.SampleValue.Companion.randomValue
8+ import org.junit.Assert
9+ import org.junit.Before
10+ import org.junit.Test
11+ import org.junit.runner.RunWith
12+ import java.util.*
13+
14+ @RunWith(AndroidJUnit4 ::class )
15+ class SampleValueTest {
16+ @Before
17+ fun setUp () {
18+ System .loadLibrary(" SampleAppCore" )
19+ JavaSwift .init ()
20+ }
21+
22+ @Test
23+ fun testGetRandomValue () {
24+ val sampleValue = randomValue.copy()
25+ Assert .assertNotNull(sampleValue)
26+ Assert .assertTrue(sampleValue.string.isNotEmpty())
27+ Assert .assertTrue(sampleValue.integer == 32 )
28+ Assert .assertTrue(sampleValue.int8.toInt() == 8 )
29+ Assert .assertTrue(sampleValue.int16.toInt() == 16 )
30+ Assert .assertTrue(sampleValue.int32 == 32 )
31+ Assert .assertTrue(sampleValue.int64 == 64L )
32+ Assert .assertTrue(sampleValue.uint == 32U )
33+ Assert .assertTrue(sampleValue.uint8.toUInt() == 8U )
34+ Assert .assertTrue(sampleValue.uint16.toUInt() == 16U )
35+ Assert .assertTrue(sampleValue.uint32 == 32U )
36+ Assert .assertTrue(sampleValue.uint64.toUInt() == 64U )
37+ Assert .assertTrue(sampleValue.objectArray.isEmpty())
38+ Assert .assertTrue(sampleValue.stringArray.size == 3 )
39+ Assert .assertTrue(sampleValue.numberArray.size == 3 )
40+ Assert .assertTrue(sampleValue.arrayInArray[0 ].size == 3 )
41+ Assert .assertTrue(sampleValue.dictInArray[0 ].size == 3 )
42+ Assert .assertTrue(sampleValue.dictSampleClass.isEmpty())
43+ Assert .assertTrue(sampleValue.dictStrings.size == 1 )
44+ Assert .assertTrue(sampleValue.dictNumbers.size == 1 )
45+ Assert .assertTrue(sampleValue.dict64Numbers.size == 1 )
46+ Assert .assertTrue(sampleValue.dictInDict.size == 1 )
47+ Assert .assertTrue(sampleValue.arrayInDict.size == 1 )
48+ Assert .assertTrue(sampleValue.set.size == 3 )
49+ Assert .assertTrue(sampleValue.setValues.isEmpty())
50+ }
51+
52+ @Test
53+ fun testSaveValue () {
54+ val sampleValue = randomValue
55+ sampleValue.string = UUID .randomUUID().toString()
56+ sampleValue.saveValue()
57+ }
58+
59+ @Test
60+ fun testIsSame () {
61+ val otherValue = randomValue
62+ val sampleValue = randomValue
63+ sampleValue.string = otherValue.string
64+ Assert .assertTrue(sampleValue.isSame(otherValue))
65+ }
66+
67+ @Test
68+ fun testThrows () {
69+ try {
70+ funcThrows()
71+ Assert .fail()
72+ } catch (swiftError: SwiftError ) {
73+ Assert .assertTrue(swiftError.message != null )
74+ }
75+ }
76+ }
0 commit comments