parent
8358fc4c07
commit
bfc50ce5fe
@ -1,25 +1,59 @@ |
|||||||
package net.pokeranalytics.android |
package net.pokeranalytics.android |
||||||
|
|
||||||
import io.realm.Realm |
import io.realm.Realm |
||||||
import io.realm.RealmConfiguration |
import io.realm.log.RealmLog |
||||||
|
import net.pokeranalytics.android.model.realm.Session |
||||||
import org.junit.After |
import org.junit.After |
||||||
|
import org.junit.Assert.assertThat |
||||||
import org.junit.Before |
import org.junit.Before |
||||||
|
import org.junit.Rule |
||||||
|
import org.junit.Test |
||||||
|
import org.junit.runner.RunWith |
||||||
|
import org.powermock.api.mockito.PowerMockito |
||||||
|
import org.powermock.api.mockito.PowerMockito.`when` |
||||||
|
import org.powermock.api.mockito.PowerMockito.mockStatic |
||||||
|
import org.powermock.core.classloader.annotations.PowerMockIgnore |
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest |
||||||
|
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor |
||||||
|
import org.powermock.modules.junit4.rule.PowerMockRule |
||||||
|
import org.robolectric.RobolectricTestRunner |
||||||
|
import org.robolectric.annotation.Config |
||||||
|
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner::class) |
||||||
|
@Config(manifest = Config.NONE, sdk = [19]) |
||||||
|
@PowerMockIgnore("org.mockito.*", "org.robolectric.*", "android.*") |
||||||
|
@SuppressStaticInitializationFor("io.realm.internal.Util") |
||||||
|
@PrepareForTest(Realm::class, RealmLog::class) |
||||||
open class RealmUnitTest { |
open class RealmUnitTest { |
||||||
|
|
||||||
lateinit var mockRealm: Realm |
@get:Rule |
||||||
|
var rule = PowerMockRule() |
||||||
|
|
||||||
|
lateinit var mockRealm: Realm |
||||||
|
|
||||||
|
@Before |
||||||
|
fun setup() { |
||||||
|
mockStatic(RealmLog::class.java) |
||||||
|
mockStatic(Realm::class.java) |
||||||
|
|
||||||
|
val mockRealm = PowerMockito.mock(Realm::class.java) |
||||||
|
`when`(Realm.getDefaultInstance()).thenReturn(mockRealm) |
||||||
|
this.mockRealm = mockRealm |
||||||
|
} |
||||||
|
|
||||||
@Before |
@Test |
||||||
fun setup() { |
fun shouldBeAbleToCreateARealmObject() { |
||||||
val testConfig = RealmConfiguration.Builder().inMemory().name("test-realm").build() |
val session = Session() |
||||||
Realm.setDefaultConfiguration(testConfig) |
`when`(mockRealm.createObject(Session::class.java)).thenReturn(session) |
||||||
mockRealm = Realm.getDefaultInstance() |
val output = mockRealm.createObject(Session::class.java) |
||||||
} |
assertThat(output, org.hamcrest.CoreMatchers.`is`(session)) |
||||||
|
} |
||||||
|
|
||||||
@After |
@After |
||||||
@Throws(Exception::class) |
@Throws(Exception::class) |
||||||
public fun tearDown() { |
fun tearDown() { |
||||||
mockRealm.close() |
mockRealm.close() |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
Loading…
Reference in new issue