-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1666 from OneSignal/user-model/unit-test-initial
[User Model] Unit Test Initial
- Loading branch information
Showing
20 changed files
with
1,645 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...DK/onesignal/src/main/java/com/onesignal/core/internal/http/impl/HttpConnectionFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.onesignal.core.internal.http.impl | ||
|
||
import java.io.IOException | ||
import java.net.HttpURLConnection | ||
import java.net.URL | ||
|
||
internal class HttpConnectionFactory : IHttpConnectionFactory { | ||
@Throws(IOException::class) | ||
override fun newHttpURLConnection(url: String): HttpURLConnection { | ||
return URL(BASE_URL + url).openConnection() as HttpURLConnection | ||
} | ||
|
||
companion object { | ||
private const val BASE_URL = "https://api.onesignal.com/" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...K/onesignal/src/main/java/com/onesignal/core/internal/http/impl/IHttpConnectionFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.onesignal.core.internal.http.impl | ||
|
||
import java.io.IOException | ||
import java.net.HttpURLConnection | ||
|
||
internal interface IHttpConnectionFactory { | ||
@Throws(IOException::class) | ||
fun newHttpURLConnection(url: String): HttpURLConnection | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...onesignal/src/test/java/com/onesignal/core/tests/extensions/ContainedRobolectricRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Code taken from https://github.com/kotest/kotest-extensions-robolectric with no changes. | ||
* | ||
* LICENSE: https://github.com/kotest/kotest-extensions-robolectric/blob/master/LICENSE | ||
*/ | ||
package com.onesignal.core.tests.extensions | ||
|
||
import org.junit.runners.model.FrameworkMethod | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.annotation.Config | ||
import org.robolectric.internal.bytecode.InstrumentationConfiguration | ||
import org.robolectric.pluginapi.config.ConfigurationStrategy | ||
import org.robolectric.plugins.ConfigConfigurer | ||
import java.lang.reflect.Method | ||
|
||
internal class ContainedRobolectricRunner( | ||
private val config: Config? | ||
) : RobolectricTestRunner(PlaceholderTest::class.java, injector) { | ||
private val placeHolderMethod: FrameworkMethod = children[0] | ||
val sdkEnvironment = getSandbox(placeHolderMethod).also { | ||
configureSandbox(it, placeHolderMethod) | ||
} | ||
private val bootStrapMethod = sdkEnvironment.bootstrappedClass<Any>(testClass.javaClass) | ||
.getMethod(PlaceholderTest::bootStrapMethod.name) | ||
|
||
fun containedBefore() { | ||
super.beforeTest(sdkEnvironment, placeHolderMethod, bootStrapMethod) | ||
} | ||
|
||
fun containedAfter() { | ||
super.afterTest(placeHolderMethod, bootStrapMethod) | ||
super.finallyAfterTest(placeHolderMethod) | ||
} | ||
|
||
override fun createClassLoaderConfig(method: FrameworkMethod?): InstrumentationConfiguration { | ||
return InstrumentationConfiguration.Builder(super.createClassLoaderConfig(method)) | ||
.doNotAcquirePackage("io.kotest") | ||
.build() | ||
} | ||
|
||
override fun getConfig(method: Method?): Config { | ||
val defaultConfiguration = injector.getInstance(ConfigurationStrategy::class.java) | ||
.getConfig(testClass.javaClass, method) | ||
|
||
if (config != null) { | ||
val configConfigurer = injector.getInstance(ConfigConfigurer::class.java) | ||
return configConfigurer.merge(defaultConfiguration[Config::class.java], config) | ||
} | ||
|
||
return super.getConfig(method) | ||
} | ||
|
||
class PlaceholderTest { | ||
@org.junit.Test | ||
fun testPlaceholder() { | ||
} | ||
|
||
fun bootStrapMethod() { | ||
} | ||
} | ||
|
||
companion object { | ||
private val injector = defaultInjector().build() | ||
} | ||
} |
Oops, something went wrong.