diff --git a/.github/workflows/kotlin.yml b/.github/workflows/kotlin.yml
index bc628c4b..daefbb20 100644
--- a/.github/workflows/kotlin.yml
+++ b/.github/workflows/kotlin.yml
@@ -16,21 +16,21 @@ jobs:
- name: Setup Kotlin
uses: fwilhe2/setup-kotlin@main
- name: Setup JDK 11
- uses: actions/setup-java@v2
+ uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: '11'
- name: build and test
run: ./gradlew build test --continue --info
- name: Archive Result Files
- uses: actions/upload-artifact@v2
+ uses: actions/upload-artifact@v3
with:
name: build_test_report
path: /Users/runner/work/ncmb_kotlin/ncmb_kotlin/build/reports/tests/testDebugUnitTest
- name: make NCMB.jar
run: ./gradlew clean makeJar
- name: upload NCMB.jar
- uses: actions/upload-artifact@v2
+ uses: actions/upload-artifact@v3
with:
name: NCMB.jar
path: ./release/NCMB.jar
diff --git a/LICENSE b/LICENSE
index 526389c2..e54a0c79 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright 2017-2021 FUJITSU CLOUD TECHNOLOGIES LIMITED All Rights Reserved.
+Copyright 2017-2023 FUJITSU CLOUD TECHNOLOGIES LIMITED All Rights Reserved.
Apache License
Version 2.0, January 2004
@@ -188,7 +188,7 @@ Copyright 2017-2021 FUJITSU CLOUD TECHNOLOGIES LIMITED All Rights Reserved.
same "printed page" as the copyright notice for easier
identification within third-party archives.
- Copyright [2021] [FUJITSU CLOUD TECHNOLOGIES LIMITED]
+ Copyright [2023] [FUJITSU CLOUD TECHNOLOGIES LIMITED]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git a/README.md b/README.md
index 35d77a17..f284cb96 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@
- Android 8.x ~ 13.x
- API levels 26 ~ 33
- Android Studio 2020.3.1 Patch 2 ~ 2021.3.1
-(※2023年1月時点)
+(※2023年3月時点)
## テクニカルサポート窓口対応バージョン
@@ -31,7 +31,7 @@
※なお、mobile backend にて大規模な改修が行われた際は、1年半以内のSDKであっても対応出来ない場合がございます。
その際は[informationブログ](https://mbaas.nifcloud.com/info/)にてお知らせいたします。予めご了承ください。
-- v1.0.0 ~ (※2023年1月時点)
+- v1.0.0 ~ (※2023年3月時点)
# インストール
Android Studioでプロジェクトを開き、以下の手順でSDKをインストールしてください。
@@ -61,7 +61,7 @@ dependencies {
ActivityのonCreateメソッド内に以下を記載します。
```kotlin
-NCMB.initialize(this.getApplicationContext(),"YOUR_APPLICATION_KEY","YOUR_CLIENT_KEY");
+NCMB.initialize(this.applicationContext,"YOUR_APPLICATION_KEY","YOUR_CLIENT_KEY");
```
* 利用する機能に合わせて使用するライブラリのimport
diff --git a/build.gradle b/build.gradle
index 2d142048..8c4de9c9 100644
--- a/build.gradle
+++ b/build.gradle
@@ -31,12 +31,12 @@ buildscript {
android {
- compileSdkVersion 29
+ compileSdkVersion 31
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 20
- targetSdkVersion 29
+ targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -78,6 +78,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.4'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.4'
+ implementation 'androidx.test:core-ktx:1.4.0'
testImplementation 'junit:junit:4.13.2'
testImplementation "com.nhaarman:mockito-kotlin:1.5.0"
testImplementation 'org.mockito:mockito-inline:3.11.0'
@@ -90,8 +91,8 @@ dependencies {
testImplementation 'org.yaml:snakeyaml:1.17'
testImplementation 'org.skyscreamer:jsonassert:1.5.0'
testImplementation 'org.robolectric:robolectric:4.5.1'
- testImplementation("org.jetbrains.kotlin:kotlin-test")
- testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
+ testImplementation "org.jetbrains.kotlin:kotlin-test"
+ testImplementation "org.jetbrains.kotlin:kotlin-test-junit"
def lifecycle_version = "1.1.1"
testImplementation "android.arch.core:core-testing:$lifecycle_version"
def coroutines_version = '1.3.9' //Kotlin coroutines用ライブラリ(async, await)のバージョン
@@ -105,9 +106,10 @@ dependencies {
implementation 'com.google.firebase:firebase-messaging-ktx'
// Use the Kotlin test library.
- testImplementation("org.jetbrains.kotlin:kotlin-test")
+ testImplementation "org.jetbrains.kotlin:kotlin-test"
// Use the Kotlin JUnit integration.
- testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
+ testImplementation "org.jetbrains.kotlin:kotlin-test-junit"
+
}
task clearJar(type: Delete) {
diff --git a/src/main/java/com/nifcloud/mbaas/core/NCMB.kt b/src/main/java/com/nifcloud/mbaas/core/NCMB.kt
index 4a6985cd..347cac64 100644
--- a/src/main/java/com/nifcloud/mbaas/core/NCMB.kt
+++ b/src/main/java/com/nifcloud/mbaas/core/NCMB.kt
@@ -43,7 +43,7 @@ class NCMB {
/**
* Version of this SDK
*/
- const val SDK_VERSION = "1.3.0"
+ const val SDK_VERSION = "1.4.0"
/**
* Prefix of keys in metadata for NCMB settings
@@ -151,23 +151,21 @@ class NCMB {
val utils = NCMBNotificationUtils(context)
utils.settingDefaultChannels()
}
- NCMBInstallation().getDeviceTokenInBackground(NCMBCallback { e, deviceToken ->
- if (e != null) {
- Log.d("error", "devicetoken GET ERROR : " + e.message)
+ NCMBInstallation().getDeviceTokenInBackground(NCMBCallback { err1, deviceToken ->
+ if (err1 != null) {
+ Log.d("error", "devicetoken GET ERROR : " + err1.message)
} else {
Log.d("success", "deviceToken :$deviceToken")
val installationObj = NCMBInstallation.currentInstallation
- if (installationObj != null) {
- installationObj.deviceToken = deviceToken as String
- installationObj.saveInBackground(NCMBCallback { e, ncmbInstallation ->
- if (e != null) {
- Log.d("error","installation SAVE ERROR : " + e.message)
- } else {
- val result = ncmbInstallation as NCMBInstallation
- Log.d("success","installation DONE ObjectID :" + result.getObjectId())
- }
- })
- }
+ installationObj.deviceToken = deviceToken as String
+ installationObj.saveInBackground(NCMBCallback { err2, ncmbInstallation ->
+ if (err2 != null) {
+ Log.d("error","installation SAVE ERROR : " + err2.message)
+ } else {
+ val result = ncmbInstallation as NCMBInstallation
+ Log.d("success","installation DONE ObjectID :" + result.getObjectId())
+ }
+ })
}
})
}
diff --git a/src/main/java/com/nifcloud/mbaas/core/NCMBBase.kt b/src/main/java/com/nifcloud/mbaas/core/NCMBBase.kt
index 1f94bfd0..0d56024c 100644
--- a/src/main/java/com/nifcloud/mbaas/core/NCMBBase.kt
+++ b/src/main/java/com/nifcloud/mbaas/core/NCMBBase.kt
@@ -113,11 +113,81 @@ open class NCMBBase(){
* @param key field name to get the value
* @return value of specified key or null
*/
- open fun getString(key: String): String? {
+ open fun getString(key: String, value: String? = null): String? {
return try {
mFields.getString(key)
} catch (e: JSONException) {
- null
+ return value
+ }
+ }
+
+ /**
+ * get int value from given key
+ *
+ * @param key field name to get the value
+ * @return value of specified key or null
+ */
+ fun getInt(key: String, value: Int? = null): Int?{
+ return try{
+ mFields.get(key) as Int
+ } catch (e: JSONException){
+ return value
+ }
+ }
+
+ /**
+ * get double value from given key
+ *
+ * @param key field name to get the value
+ * @return value of specified key or null
+ */
+ fun getDouble(key: String, value: Double? = null): Double?{
+ return try{
+ mFields.get(key) as Double
+ } catch (e: JSONException){
+ return value
+ }
+ }
+
+ /**
+ * get boolean value from given key
+ *
+ * @param key field name to get the value
+ * @return value of specified key or null
+ */
+ fun getBoolean(key: String, value: Boolean? = null): Boolean?{
+ return try{
+ mFields.get(key) as Boolean
+ } catch (e: JSONException){
+ return value
+ }
+ }
+
+ /**
+ * get JSONObject value from given key
+ *
+ * @param key field name to get the value
+ * @return value of specified key or null
+ */
+ fun getJson(key: String, value: JSONObject? = null): JSONObject?{
+ return try{
+ mFields.get(key) as JSONObject
+ } catch (e: JSONException){
+ return value
+ }
+ }
+
+ /**
+ * get JSONArray value from given key
+ *
+ * @param key field name to get the value
+ * @return value of specified key or null
+ */
+ fun getArray(key: String, value: JSONArray? = null): JSONArray?{
+ return try{
+ mFields.get(key) as JSONArray
+ } catch (e: JSONException){
+ return value
}
}
@@ -247,7 +317,7 @@ open class NCMBBase(){
}
@Throws(NCMBException::class)
- fun getDate(key : String): Date? {
+ fun getDate(key : String, value : Date? = null): Date? {
try {
if (!mFields.isNull(key)) {
val df: SimpleDateFormat = NCMBDateFormat.getIso8601()
@@ -256,7 +326,7 @@ open class NCMBBase(){
return df.parse(dateJson.getString("iso"))
}
}
- return null
+ return value
} catch (e: JSONException) {
return null
}
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBAclTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBAclTest.kt
index b1c5fac6..c4386422 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBAclTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBAclTest.kt
@@ -26,15 +26,15 @@ import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import org.skyscreamer.jsonassert.JSONAssert
+import androidx.test.core.app.ApplicationProvider
/**
* 主に通信を行うNCMBConnectionテストクラス
*/
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(26), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBAclTest {
private var mServer: MockWebServer = MockWebServer()
@@ -44,11 +44,11 @@ class NCMBAclTest {
@Before
fun setup() {
- var ncmbDispatcher = NCMBDispatcher("")
+ val ncmbDispatcher = NCMBDispatcher("")
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBBaseTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBBaseTest.kt
index 9740d0df..889ca7dd 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBBaseTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBBaseTest.kt
@@ -41,21 +41,37 @@ class NCMBBaseTest {
*/
@Test
fun put_string_test() {
- var baseObj = NCMBBase()
+ val baseObj = NCMBBase()
baseObj.put("keyString", "stringValue")
- Assert.assertEquals(baseObj.get("keyString"), "stringValue")
+ Assert.assertEquals(baseObj.getString("keyString"), "stringValue")
}
+ @Test
+ fun put_string_null_test() {
+ val baseObj = NCMBBase()
+ baseObj.put("keyString", "stringValue")
+ Assert.assertNull(baseObj.getString("key"))
+ Assert.assertEquals(baseObj.getString("key", "error"), "error")
+ }
/**
* putテスト
*/
@Test
fun put_int_test() {
- var baseObj = NCMBBase()
+ val baseObj = NCMBBase()
+ val setNumberValue: Int = 12
+ baseObj.put("keyNumberInt", setNumberValue)
+ Assert.assertEquals(baseObj.getInt("keyNumberInt"), setNumberValue)
+ }
+
+ @Test
+ fun put_int_null_test() {
+ val baseObj = NCMBBase()
val setNumberValue: Int = 12
baseObj.put("keyNumberInt", setNumberValue)
- Assert.assertEquals(baseObj.get("keyNumberInt"), setNumberValue)
+ Assert.assertNull(baseObj.getInt("key"))
+ Assert.assertEquals(baseObj.getInt("key", 0), 0)
}
/**
@@ -63,9 +79,17 @@ class NCMBBaseTest {
*/
@Test
fun put_int_test_direct() {
- var baseObj = NCMBBase()
+ val baseObj = NCMBBase()
+ baseObj.put("keyNumberInt", 1234)
+ Assert.assertEquals(baseObj.getInt("keyNumberInt"), 1234)
+ }
+
+ @Test
+ fun put_int_null_test_direct(){
+ val baseObj = NCMBBase()
baseObj.put("keyNumberInt", 1234)
- Assert.assertEquals(baseObj.get("keyNumberInt"), 1234)
+ Assert.assertNull(baseObj.getInt("key"))
+ Assert.assertEquals(baseObj.getInt("key", 0), 0)
}
/**
@@ -73,9 +97,63 @@ class NCMBBaseTest {
*/
@Test
fun put_double_test_direct() {
- var baseObj = NCMBBase()
+ val baseObj = NCMBBase()
baseObj.put("keyNumberDouble", 1234.33)
- Assert.assertEquals(baseObj.get("keyNumberDouble"), 1234.33)
+ Assert.assertEquals(baseObj.getDouble("keyNumberDouble"), 1234.33)
+ }
+
+ @Test
+ fun put_double_null_test_direct(){
+ val baseObj = NCMBBase()
+ baseObj.put("keyNumberDouble", 1234.33)
+ Assert.assertNull(baseObj.getDouble("key"))
+ Assert.assertEquals(baseObj.getDouble("key", 0.0), 0.0)
+ }
+
+ /**
+ * putテスト
+ */
+ @Test
+ fun put_boolean_test() {
+ val baseObj = NCMBBase()
+ val booleanValue: Boolean = true
+ baseObj.put("keyBoolean", booleanValue)
+ Assert.assertEquals(baseObj.getBoolean("keyBoolean"), true)
+ }
+
+ @Test
+ fun put_boolean_null_test() {
+ val baseObj = NCMBBase()
+ val booleanValue: Boolean = true
+ baseObj.put("keyBoolean", booleanValue)
+ Assert.assertNull(baseObj.getBoolean("key"))
+ Assert.assertEquals(baseObj.getBoolean("key", true), true)
+ }
+
+ /**
+ * putテスト
+ */
+ @Test
+ fun put_jsonObject_test() {
+ val baseObj = NCMBBase()
+ val jsonObjectValue = JSONObject()
+ val jsonObjectAssert = JSONObject()
+ jsonObjectValue.put("a","b")
+ jsonObjectAssert.put("a","b")
+ baseObj.put("keyJsonObject", jsonObjectValue)
+ JSONAssert.assertEquals(baseObj.getJson("keyJsonObject"), jsonObjectAssert, true)
+ }
+
+ @Test
+ fun put_jsonObject_null_test() {
+ val baseObj = NCMBBase()
+ val jsonObjectValue = JSONObject()
+ val jsonObjectAssert = JSONObject()
+ jsonObjectValue.put("a","b")
+ jsonObjectAssert.put("a","b")
+ baseObj.put("keyJsonObject", jsonObjectValue)
+ Assert.assertNull(baseObj.getJson("key"))
+ JSONAssert.assertEquals(baseObj.getJson("key", jsonObjectAssert), jsonObjectAssert, true)
}
/**
@@ -92,29 +170,56 @@ class NCMBBaseTest {
testArray2.put(1)
testArray2.put(2)
obj.put("keyArray", testArray)
- Assert.assertEquals(obj.get("keyArray"), testArray2)
+ Assert.assertEquals(obj.getArray("keyArray"), testArray2)
Assert.assertEquals(obj.mFields.get("keyArray"), testArray2)
}
+ @Test
+ fun put_array_of_int_null_test() {
+ val obj = NCMBBase()
+ val testArray = JSONArray()
+ testArray.put(1)
+ testArray.put(2)
+
+ val testArray2 = JSONArray()
+ testArray2.put(1)
+ testArray2.put(2)
+ obj.put("keyArray", testArray)
+ Assert.assertNull(obj.getArray("key"))
+ Assert.assertEquals(obj.getArray("key", testArray2), testArray2)
+ }
+
@Test
fun put_date_test_direct() {
- var baseObj = NCMBBase()
+ val baseObj = NCMBBase()
- val assertDate: Date = NCMBDateFormat.getIso8601().parse("2022-04-14T10:10:10.000Z")
+ val assertDate: Date = NCMBDateFormat.getIso8601().parse("2022-04-14T10:10:10.000Z") as Date
baseObj.put("keyDate", assertDate)
val expectedKeyDateJson = JSONObject("{\"__type\":\"Date\",\"iso\":\"2022-04-14T10:10:10.000Z\"}")
- Assert.assertTrue(assertDate.equals(baseObj.getDate("keyDate")));
+ Assert.assertEquals(assertDate,baseObj.getDate("keyDate"))
JSONAssert.assertEquals(expectedKeyDateJson, baseObj.mFields.getJSONObject("keyDate"), false)
Assert.assertEquals(1, baseObj.mUpdateKeys.size)
}
+ @Test
+ fun put_date_null_test_direct() {
+ val baseObj = NCMBBase()
+
+ val assertDate: Date = NCMBDateFormat.getIso8601().parse("2022-04-14T10:10:10.000Z")
+ val assertDate2: Date = NCMBDateFormat.getIso8601().parse("2023-01-27T10:10:10.000Z")
+ baseObj.put("keyDate", assertDate)
+
+ Assert.assertNull(baseObj.getDate("key"))
+ Assert.assertEquals(baseObj.getDate("key", assertDate2), assertDate2);
+ }
+
/**
* copyFromテスト
*/
@Test
fun copy_from_test() {
- var baseObj = NCMBBase()
+ val baseObj = NCMBBase()
val json = JSONObject("{\"objectId\":\"xxxxx\",\"userName\":\"YamadaTarou\"}")
val testKeys = hashSetOf("objectId", "userName")
Assert.assertEquals("xxxxx", json.getString("objectId"))
@@ -168,7 +273,7 @@ class NCMBBaseTest {
*/
@Test
fun setAcl_test() {
- var baseObj = NCMBBase()
+ val baseObj = NCMBBase()
val acl = NCMBAcl()
acl.publicReadAccess = true
baseObj.setAcl(acl)
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBConnectionTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBConnectionTest.kt
index d893afcc..e4a591d9 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBConnectionTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBConnectionTest.kt
@@ -26,14 +26,14 @@ import okhttp3.mockwebserver.MockWebServer
import org.junit.Before
import org.junit.Rule
import org.junit.rules.TestRule
-import org.robolectric.RuntimeEnvironment
+import androidx.test.core.app.ApplicationProvider
import org.robolectric.annotation.Config
/**
* 主に通信を行うNCMBConnectionテストクラス
*/
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(26), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBConnectionTest {
private var mServer: MockWebServer = MockWebServer()
@@ -42,11 +42,11 @@ class NCMBConnectionTest {
val rule: TestRule = InstantTaskExecutorRule()
@Before
fun setup() {
- var ncmbDispatcher = NCMBDispatcher("")
+ val ncmbDispatcher = NCMBDispatcher("")
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
@@ -88,16 +88,19 @@ class NCMBConnectionTest {
when(res) {
is NCMBResponse.Success -> {
print(res.data)
+ Assert.assertNotNull(res.data)
}
}
- Assert.assertNull(e)
}
}
- val handler = NCMBHandler { callback, res ->
+ val handler = NCMBHandler { callbackHandler, res ->
//Handler Action is set here
when(res) {
is NCMBResponse.Failure -> {
- callback!!.done(res.resException)
+ callbackHandler.done(res.resException)
+ }
+ is NCMBResponse.Success -> {
+ TODO()
}
}
}
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBDateFormatTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBDateFormatTest.kt
index e09e89bc..d61a3319 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBDateFormatTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBDateFormatTest.kt
@@ -27,14 +27,14 @@ import org.robolectric.annotation.Config
* 主に通信を行う自動化テストクラス
*/
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBDateFormatTest {
/**
* putテスト
*/
@Test
- fun UTC_check_test() {
- var format = getIso8601()
+ fun utc_check_test() {
+ val format = getIso8601()
Assert.assertEquals(format.timeZone.rawOffset, 0)
Assert.assertEquals(format.timeZone.id, "UTC")
}
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBDispatcher.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBDispatcher.kt
index 7fd58af9..576857de 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBDispatcher.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBDispatcher.kt
@@ -36,14 +36,14 @@ import java.nio.file.Paths
class NCMBDispatcher(var className:String): Dispatcher() {
- private val NUMBER_PATTERN = "[0-9]".toRegex()
- private val BOOL_PATTERN = """(true|false)""".toRegex()
+ private val _numberPattern = "[0-9]".toRegex()
+ private val _boolPattern = """(true|false)""".toRegex()
@Throws(InterruptedException::class)
override fun dispatch(request: RecordedRequest): MockResponse {
var input: InputStream? = null
try {
- if(className == "") {
+ if (className == "") {
input = FileInputStream(File("src/test/assets/yaml/mbaas.yml"))
} else {
input = FileInputStream(File("src/test/assets/yaml/mbaas_" + className +".yml"))
@@ -52,9 +52,9 @@ class NCMBDispatcher(var className:String): Dispatcher() {
e.printStackTrace()
}
val yaml = Yaml()
- var map: Map? = null
- var requestMap: Map? = null
- var responseMap: Map? = null
+ var map: Map?
+ var requestMap: Map?
+ var responseMap: Map?
var requestBody: String? = null
for (data in yaml.loadAll(input)) {
map = data as Map?
@@ -66,11 +66,11 @@ class NCMBDispatcher(var className:String): Dispatcher() {
val path = pathAndQuery?.get(0)
var query: String? = null
if (pathAndQuery?.size!! > 1) {
- query = pathAndQuery?.get(1)
+ query = pathAndQuery[1]
}
if(requestMap != null) {
- if (requestMap!!["url"] != path) {
+ if (requestMap["url"] != path) {
continue
//return defaultErrorResponse();
}
@@ -129,7 +129,7 @@ class NCMBDispatcher(var className:String): Dispatcher() {
if (requestMap.containsKey("query")) {
val mockQuery = requestMap["query"]
val mockQueryStr: String = Gson().toJson(mockQuery)
- if (checkRequestQuery(mockQueryStr, query) == true) {
+ if (checkRequestQuery(mockQueryStr, query)) {
return MockResponse().setResponseCode(responseMap!!["status"] as Int)
.setHeader("Content-Type", "application/json")
.setBody(readJsonResponse(responseMap["file"].toString()))
@@ -154,7 +154,7 @@ class NCMBDispatcher(var className:String): Dispatcher() {
val mockBodyStr: String = gson.toJson(mockBody)
//println("mock:$mockBodyStr")
//println("req:$requestBody")
- if (requestBody?.let { checkRequestBody(mockBodyStr, it) }!!) {
+ if (checkRequestBody(mockBodyStr, requestBody)) {
//Responseをreturn
MockResponse().setResponseCode(responseMap!!["status"] as Int)
.setHeader("Content-Type", "application/json")
@@ -168,8 +168,8 @@ class NCMBDispatcher(var className:String): Dispatcher() {
}
if (requestMap.containsKey("header")) {
val requestHeaders: Headers = request.headers
- val gson: Gson = GsonBuilder().serializeNulls().create()
- val mock: String = gson.toJson(requestMap["header"])
+ //val gson: Gson = GsonBuilder().serializeNulls().create()
+ //val mock: String = gson.toJson(requestMap["header"])
try {
val mockHeaders =
JSONObject(requestMap["header"].toString())
@@ -178,7 +178,7 @@ class NCMBDispatcher(var className:String): Dispatcher() {
val keys: Iterator<*> = mockHeaders.keys()
while (keys.hasNext()) {
val key = keys.next() as String
- if (requestHeaders.get(key) != null && requestHeaders.get(key)
+ if (requestHeaders[key] != null && requestHeaders.get(key)
.equals(mockHeaders.getString(key))
) {
return MockResponse().setResponseCode(responseMap!!["status"] as Int)
@@ -194,7 +194,7 @@ class NCMBDispatcher(var className:String): Dispatcher() {
}
if(responseMap != null) {
- return MockResponse().setResponseCode(responseMap!!["status"] as Int)
+ return MockResponse().setResponseCode(responseMap["status"] as Int)
.setHeader("Content-Type", "application/json")
.setBody(readJsonResponse(responseMap["file"].toString()))
}
@@ -215,7 +215,7 @@ class NCMBDispatcher(var className:String): Dispatcher() {
private fun checkRequestQuery(
mockRequestQueryStr: String,
realRequestQueryStr: String
- ): Boolean? {
+ ): Boolean {
try {
val mockQuery = JSONObject(mockRequestQueryStr)
val decodedQueryStr =
@@ -232,9 +232,9 @@ class NCMBDispatcher(var className:String): Dispatcher() {
if (queryData.size == 2) {
value = queryData[1]
}
- if (value.matches(NUMBER_PATTERN)) {
+ if (value.matches(_numberPattern)) {
realQueryMap[key] = value.toInt()
- } else if (value.matches(BOOL_PATTERN)) {
+ } else if (value.matches(_boolPattern)) {
realQueryMap[key] = java.lang.Boolean.parseBoolean(value)
} else {
realQueryMap[key] = value
@@ -295,9 +295,9 @@ class NCMBDispatcher(var className:String): Dispatcher() {
//val file = File("src/test/assets/json/$file_name")
val file = Paths.get("src/test/assets/json/$file_name")
- var json: String = ""
+ var json = ""
try {
- json = Files.readAllLines(file, StandardCharsets.UTF_8).toString();
+ json = Files.readAllLines(file, StandardCharsets.UTF_8).toString()
} catch (e: IOException) {
e.printStackTrace()
}
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorDispatcher.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorDispatcher.kt
index cb46e648..44ed5882 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorDispatcher.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorDispatcher.kt
@@ -36,8 +36,8 @@ import java.nio.file.Paths
class NCMBErrorDispatcher: Dispatcher() {
- private val NUMBER_PATTERN = """"[0-9]+""".toRegex()
- private val BOOL_PATTERN = """[true|false]""".toRegex()
+ private val _numberPattern = """"[0-9]+""".toRegex()
+ private val _boolPattern = """(true|false)""".toRegex()
@Throws(InterruptedException::class)
override fun dispatch(request: RecordedRequest): MockResponse {
@@ -48,9 +48,9 @@ class NCMBErrorDispatcher: Dispatcher() {
e.printStackTrace()
}
val yaml = Yaml()
- var map: Map? = null
- var requestMap: Map? = null
- var responseMap: Map? = null
+ var map: Map?
+ var requestMap: Map?
+ var responseMap: Map?
var requestBody: String? = null
for (data in yaml.loadAll(input)) {
map = data as Map?
@@ -62,7 +62,7 @@ class NCMBErrorDispatcher: Dispatcher() {
val path = pathAndQuery?.get(0)
var query: String? = null
if (pathAndQuery?.size!! > 1) {
- query = pathAndQuery?.get(1)
+ query = pathAndQuery[1]
}
if (requestMap!!["url"] != path) {
continue
@@ -96,7 +96,7 @@ class NCMBErrorDispatcher: Dispatcher() {
if (requestMap.containsKey("query")) {
val mockQuery = requestMap["query"]
val mockQueryStr: String = Gson().toJson(mockQuery)
- if (checkRequestQuery(mockQueryStr, query)!!) {
+ if (checkRequestQuery(mockQueryStr, query)) {
continue
}
} else {
@@ -116,7 +116,7 @@ class NCMBErrorDispatcher: Dispatcher() {
val mockBodyStr: String = gson.toJson(mockBody)
println("mock:$mockBodyStr")
println("req:$requestBody")
- if (requestBody?.let { checkRequestBody(mockBodyStr, it) }!!) {
+ if (checkRequestBody(mockBodyStr, requestBody)) {
//Responseをreturn
MockResponse().setResponseCode(responseMap!!["status"] as Int)
.setHeader("Content-Type", "application/json")
@@ -130,8 +130,8 @@ class NCMBErrorDispatcher: Dispatcher() {
}
if (requestMap.containsKey("header")) {
val requestHeaders: Headers = request.headers
- val gson: Gson = GsonBuilder().serializeNulls().create()
- val mock: String = gson.toJson(requestMap["header"])
+ //val gson: Gson = GsonBuilder().serializeNulls().create()
+ //val mock: String = gson.toJson(requestMap["header"])
try {
val mockHeaders =
JSONObject(requestMap["header"].toString())
@@ -140,7 +140,7 @@ class NCMBErrorDispatcher: Dispatcher() {
val keys: Iterator<*> = mockHeaders.keys()
while (keys.hasNext()) {
val key = keys.next() as String
- if (requestHeaders.get(key) != null && requestHeaders.get(key)
+ if (requestHeaders[key] != null && requestHeaders.get(key)
.equals(mockHeaders.getString(key))
) {
return MockResponse().setResponseCode(responseMap!!["status"] as Int)
@@ -172,7 +172,7 @@ class NCMBErrorDispatcher: Dispatcher() {
private fun checkRequestQuery(
mockRequestQueryStr: String,
realRequestQueryStr: String
- ): Boolean? {
+ ): Boolean {
println("checkRequestQuery")
try {
val mockQuery = JSONObject(mockRequestQueryStr)
@@ -190,9 +190,9 @@ class NCMBErrorDispatcher: Dispatcher() {
if (queryData.size == 2) {
value = queryData[1]
}
- if (value.matches(NUMBER_PATTERN)) {
+ if (value.matches(_numberPattern)) {
realQueryMap[key] = value.toInt()
- } else if (value.matches(BOOL_PATTERN)) {
+ } else if (value.matches(_boolPattern)) {
realQueryMap[key] = java.lang.Boolean.parseBoolean(value)
} else {
realQueryMap[key] = value
@@ -251,9 +251,9 @@ class NCMBErrorDispatcher: Dispatcher() {
//val file = File("src/test/assets/json/$file_name")
val file = Paths.get("src/test/assets/json_error/$file_name")
- var json: String = ""
+ var json = ""
try {
- json = Files.readAllLines(file, StandardCharsets.UTF_8).toString();
+ json = Files.readAllLines(file, StandardCharsets.UTF_8).toString()
} catch (e: IOException) {
e.printStackTrace()
}
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorFileTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorFileTest.kt
index d2668cba..945e40f0 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorFileTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorFileTest.kt
@@ -27,16 +27,15 @@ import org.junit.rules.TemporaryFolder
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
-import org.skyscreamer.jsonassert.JSONAssert
import java.io.File
import java.io.IOException
import java.util.*
import kotlin.test.assertFails
+import androidx.test.core.app.ApplicationProvider
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBErrorFileTest {
private var mServer: MockWebServer = MockWebServer()
@@ -48,7 +47,7 @@ class NCMBErrorFileTest {
*/
@get:Rule
var tmpFolder = TemporaryFolder()
- lateinit var tmpFile: File
+ private lateinit var tmpFile: File
@Before
fun setup() {
@@ -56,7 +55,7 @@ class NCMBErrorFileTest {
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorGeoPointTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorGeoPointTest.kt
index cf906c88..c6aa2946 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorGeoPointTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorGeoPointTest.kt
@@ -26,13 +26,13 @@ import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
+import androidx.test.core.app.ApplicationProvider
import org.robolectric.annotation.Config
import java.util.*
import kotlin.test.assertFails
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBErrorGeoPointTest {
private var mServer: MockWebServer = MockWebServer()
@@ -44,7 +44,7 @@ class NCMBErrorGeoPointTest {
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
@@ -55,8 +55,8 @@ class NCMBErrorGeoPointTest {
@Test
fun test_geopoint_saveInBackground_invalid_field(){
val inBackgroundHelper = NCMBInBackgroundTestHelper()
- val latitude : Double = 35.6666269
- val longitude : Double = 139.765607
+ val latitude = 35.6666269
+ val longitude = 139.765607
val obj = NCMBObject("TestClassGeo403")
val geopoint = NCMBGeoPoint(latitude, longitude)
obj.put("geo", geopoint)
@@ -83,9 +83,9 @@ class NCMBErrorGeoPointTest {
inBackgroundHelper.await()
Assert.assertTrue(inBackgroundHelper.isCalledRelease())
Assert.assertNull(inBackgroundHelper["e"])
- val throwable_wrong_type = assertFails { val geo: NCMBGeoPoint = (inBackgroundHelper["ncmbObj"] as NCMBObject).getGeo("geoPoint") }
- val throwable_wrong_key = assertFails { val geo: NCMBGeoPoint = (inBackgroundHelper["ncmbObj"] as NCMBObject).getGeo("geo") }
- Assert.assertEquals("type is not GeoPoint.", throwable_wrong_type.message)
- Assert.assertEquals("No value for geo", throwable_wrong_key.message)
+ val throwableWrongType = assertFails { (inBackgroundHelper["ncmbObj"] as NCMBObject).getGeo("geoPoint") }
+ val throwableWrongKey = assertFails { (inBackgroundHelper["ncmbObj"] as NCMBObject).getGeo("geo") }
+ Assert.assertEquals("type is not GeoPoint.", throwableWrongType.message)
+ Assert.assertEquals("No value for geo", throwableWrongKey.message)
}
}
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorInstallationTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorInstallationTest.kt
index 88361c1f..a1e0ac6a 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorInstallationTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorInstallationTest.kt
@@ -19,7 +19,6 @@ package com.nifcloud.mbaas.core
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.nifcloud.mbaas.core.helper.NCMBInBackgroundTestHelper
import okhttp3.mockwebserver.MockWebServer
-import org.json.JSONObject
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
@@ -27,7 +26,7 @@ import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
+import androidx.test.core.app.ApplicationProvider
import org.robolectric.annotation.Config
import kotlin.test.assertFails
@@ -35,7 +34,7 @@ import kotlin.test.assertFails
* 主に通信を行う自動化テストクラス
*/
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBErrorInstallationTest {
private var mServer: MockWebServer = MockWebServer()
@@ -46,11 +45,11 @@ class NCMBErrorInstallationTest {
val rule: TestRule = InstantTaskExecutorRule()
@Before
fun setup() {
- var ncmbDispatcher = NCMBErrorDispatcher()
+ val ncmbDispatcher = NCMBErrorDispatcher()
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorPushTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorPushTest.kt
index 44a71258..d89a448b 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorPushTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorPushTest.kt
@@ -27,8 +27,8 @@ import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
+import androidx.test.core.app.ApplicationProvider
import java.lang.Exception
import java.text.ParseException
import java.text.SimpleDateFormat
@@ -39,7 +39,7 @@ import java.util.*
* 主に通信を行う自動化テストクラス
*/
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBErrorPushTest {
private var mServer: MockWebServer = MockWebServer()
@@ -50,11 +50,11 @@ class NCMBErrorPushTest {
val rule: TestRule = InstantTaskExecutorRule()
@Before
fun setup() {
- var ncmbDispatcher = NCMBErrorDispatcher()
+ val ncmbDispatcher = NCMBErrorDispatcher()
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
@@ -117,10 +117,10 @@ class NCMBErrorPushTest {
//post
var date = Date()
val push = NCMBPush()
- var df = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
+ val df = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
df.timeZone = TimeZone.getTimeZone("Etc/UTC")
try {
- date = df.parse("2030-10-10 10:10:10")
+ date = df.parse("2030-10-10 10:10:10") as Date
} catch (e: ParseException) {
e.printStackTrace()
}
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorQueryTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorQueryTest.kt
index ed8141ff..a2b0b61b 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorQueryTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorQueryTest.kt
@@ -17,9 +17,6 @@
package com.nifcloud.mbaas.core
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
-import com.nifcloud.mbaas.core.NCMB
-import com.nifcloud.mbaas.core.NCMBErrorDispatcher
-import com.nifcloud.mbaas.core.NCMBException
import com.nifcloud.mbaas.core.helper.NCMBInBackgroundTestHelper
import okhttp3.mockwebserver.MockWebServer
import org.junit.Assert
@@ -29,7 +26,7 @@ import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
+import androidx.test.core.app.ApplicationProvider
import org.robolectric.annotation.Config
import kotlin.test.assertFails
@@ -38,7 +35,7 @@ import kotlin.test.assertFails
* 主に通信を行う自動化テストクラス
*/
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBErrorQueryTest {
private var mServer: MockWebServer = MockWebServer()
@@ -49,11 +46,11 @@ class NCMBErrorQueryTest {
val rule: TestRule = InstantTaskExecutorRule()
@Before
fun setup() {
- var ncmbDispatcher = NCMBErrorDispatcher()
+ val ncmbDispatcher = NCMBErrorDispatcher()
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
@@ -68,7 +65,7 @@ class NCMBErrorQueryTest {
fun testNCMBObject_DoSearchSync_503error() {
//TestClassクラスを検索するクエリを作成
val query = NCMBQuery.forObject("TestClass503")
- val throwable = assertFails{ val objects = query.find() }
+ val throwable = assertFails{ query.find() }
Assert.assertEquals("Service unavailable.",throwable.message)
}
@@ -77,7 +74,7 @@ class NCMBErrorQueryTest {
fun testNCMBObject_DoSearchSync_500error() {
//TestClassクラスを検索するクエリを作成
val query = NCMBQuery.forObject("TestClass500")
- val throwable = assertFails{ val objects = query.find() }
+ val throwable = assertFails{ query.find() }
Assert.assertEquals("System error.",throwable.message)
}
@@ -86,7 +83,7 @@ class NCMBErrorQueryTest {
fun testNCMBObject_DoSearchSync_429error() {
//TestClassクラスを検索するクエリを作成
val query = NCMBQuery.forObject("TestClass429")
- val throwable = assertFails{ val objects = query.find() }
+ val throwable = assertFails{ query.find() }
Assert.assertEquals("Too many requests.",throwable.message)
}
@@ -95,7 +92,7 @@ class NCMBErrorQueryTest {
fun testNCMBObject_DoCountSync_503error() {
//TestClassクラスを検索するクエリを作成
val query = NCMBQuery.forObject("TestClass503")
- val throwable = assertFails{ val objects = query.count() }
+ val throwable = assertFails{ query.count() }
Assert.assertEquals("Service unavailable.",throwable.message)
}
@@ -104,7 +101,7 @@ class NCMBErrorQueryTest {
fun testNCMBObject_DoCountSync_500error() {
//TestClassクラスを検索するクエリを作成
val query = NCMBQuery.forObject("TestClass500")
- val throwable = assertFails{ val objects = query.count() }
+ val throwable = assertFails{ query.count() }
Assert.assertEquals("System error.",throwable.message)
}
@@ -113,7 +110,7 @@ class NCMBErrorQueryTest {
fun testNCMBObject_DoCountSync_429error() {
//TestClassクラスを検索するクエリを作成
val query = NCMBQuery.forObject("TestClass429")
- val throwable = assertFails{ val objects = query.count() }
+ val throwable = assertFails{ query.count() }
Assert.assertEquals("Too many requests.",throwable.message)
}
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorScriptTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorScriptTest.kt
index 94832527..b271fd77 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorScriptTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorScriptTest.kt
@@ -24,19 +24,16 @@ import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
-import org.junit.rules.TemporaryFolder
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
+import androidx.test.core.app.ApplicationProvider
import org.robolectric.annotation.Config
-import java.io.File
-import java.io.IOException
import java.util.*
-import kotlin.test.assertFails
+
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBErrorScriptTest {
private var mServer: MockWebServer = MockWebServer()
@@ -49,7 +46,7 @@ class NCMBErrorScriptTest {
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
@@ -66,12 +63,11 @@ class NCMBErrorScriptTest {
val query = JSONObject()
val scriptObj = NCMBScript("errorTestScript.js", NCMBScript.MethodType.GET)
- var response : ByteArray? = null
try {
- response = scriptObj.execute(header, body, query)
+ scriptObj.execute(header, body, query)
}
catch(e : NCMBException){
- Assert.assertNull(response)
+ Assert.assertNotNull(e)
Assert.assertEquals(e.message, "errorTestScript.js not found")
}
}
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorUserTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorUserTest.kt
index e0faa4fc..d089e8c3 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBErrorUserTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBErrorUserTest.kt
@@ -17,10 +17,6 @@
package com.nifcloud.mbaas.core
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
-import com.nifcloud.mbaas.core.NCMB
-import com.nifcloud.mbaas.core.NCMBErrorDispatcher
-import com.nifcloud.mbaas.core.NCMBException
-import com.nifcloud.mbaas.core.NCMBUser
import com.nifcloud.mbaas.core.helper.NCMBInBackgroundTestHelper
import okhttp3.mockwebserver.MockWebServer
import org.junit.Assert
@@ -30,16 +26,15 @@ import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
+import androidx.test.core.app.ApplicationProvider
import org.robolectric.annotation.Config
-import kotlin.test.assertFails
/**
* 主に通信を行う自動化テストクラス
*/
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBErrorUserTest {
private var mServer: MockWebServer = MockWebServer()
@@ -50,11 +45,11 @@ class NCMBErrorUserTest {
val rule: TestRule = InstantTaskExecutorRule()
@Before
fun setup() {
- var ncmbDispatcher = NCMBErrorDispatcher()
+ val ncmbDispatcher = NCMBErrorDispatcher()
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBFileTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBFileTest.kt
index 579d988d..59a392d9 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBFileTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBFileTest.kt
@@ -20,7 +20,6 @@ import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
-import android.util.Log
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.nifcloud.mbaas.core.helper.NCMBInBackgroundTestHelper
import okhttp3.mockwebserver.MockWebServer
@@ -32,17 +31,17 @@ import org.junit.rules.TemporaryFolder
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import org.skyscreamer.jsonassert.JSONAssert
import java.io.File
import java.io.IOException
import java.nio.charset.Charset
import java.util.*
+import androidx.test.core.app.ApplicationProvider
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBFileTest {
private var mServer: MockWebServer = MockWebServer()
@@ -65,14 +64,14 @@ class NCMBFileTest {
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
"2013-09-01"
)
- callbackFlag = false;
+ callbackFlag = false
try {
// Create a temporary file.
@@ -82,11 +81,11 @@ class NCMBFileTest {
// Create a png file
tmpImgFile = tmpFolder.newFile("test.png")
- val bitmap = BitmapFactory.decodeFile(tmpImgFile.getAbsolutePath())
- var canvas = Canvas(bitmap)
+ val bitmap = BitmapFactory.decodeFile(tmpImgFile.absolutePath)
+ val canvas = Canvas(bitmap)
val paint = Paint()
- paint.setColor(Color.BLACK);
- paint.setTextSize(10F);
+ paint.color = Color.BLACK
+ paint.textSize = 10F
canvas.drawText("test", 1F, 1F, paint)
canvas.save()
@@ -110,16 +109,16 @@ class NCMBFileTest {
fun fileData_set_Get_test() {
val ncmbFile = NCMBFile()
ncmbFile.fileData = tmpFile
- Assert.assertEquals("hello world", ncmbFile.fileData!!.readText(Charset.defaultCharset()).toString())
- Assert.assertEquals("hello world", (ncmbFile.mFields.get(NCMBFile.FILE_DATA) as File).readText(Charset.defaultCharset()).toString())
+ Assert.assertEquals("hello world", ncmbFile.fileData!!.readText(Charset.defaultCharset()))
+ Assert.assertEquals("hello world", (ncmbFile.mFields.get(NCMBFile.FILE_DATA) as File).readText(Charset.defaultCharset()))
}
@Test
fun fileConstructor_filename_filedata() {
val ncmbFile = NCMBFile("testfile.txt", tmpFile)
Assert.assertEquals("testfile.txt", ncmbFile.fileName)
- Assert.assertEquals("hello world", ncmbFile.fileData!!.readText(Charset.defaultCharset()).toString())
- Assert.assertEquals("hello world", (ncmbFile.mFields.get(NCMBFile.FILE_DATA) as File).readText(Charset.defaultCharset()).toString())
+ Assert.assertEquals("hello world", ncmbFile.fileData!!.readText(Charset.defaultCharset()))
+ Assert.assertEquals("hello world", (ncmbFile.mFields.get(NCMBFile.FILE_DATA) as File).readText(Charset.defaultCharset()))
}
@Test
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBGeoPointTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBGeoPointTest.kt
index a5225f38..23ac9101 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBGeoPointTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBGeoPointTest.kt
@@ -16,7 +16,6 @@
package com.nifcloud.mbaas.core
-import android.util.Log
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.nifcloud.mbaas.core.NCMBDateFormat.getIso8601
import com.nifcloud.mbaas.core.helper.NCMBInBackgroundTestHelper
@@ -28,12 +27,12 @@ import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
+import androidx.test.core.app.ApplicationProvider
import org.robolectric.annotation.Config
import java.util.*
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBGeoPointTest {
private var mServer: MockWebServer = MockWebServer()
@@ -47,20 +46,20 @@ class NCMBGeoPointTest {
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
"2013-09-01"
)
- callbackFlag = false;
+ callbackFlag = false
}
@Test
fun test_geopoint_right_settings(){
- val latitude : Double = 35.6666269
- val longitude : Double = 139.765607
+ val latitude = 35.6666269
+ val longitude = 139.765607
val geopoint = NCMBGeoPoint(latitude, longitude)
Assert.assertEquals(geopoint.mlatitude, latitude, 0.0)
Assert.assertEquals(geopoint.mlongitude, longitude, 0.0)
@@ -76,9 +75,9 @@ class NCMBGeoPointTest {
@Test
fun test_geopoint_wrong_latitude(){
try {
- val latitude: Double = 139.765607
- val longitude: Double = 139.765607
- val geopoint = NCMBGeoPoint(latitude, longitude)
+ val latitude = 139.765607
+ val longitude = 139.765607
+ NCMBGeoPoint(latitude, longitude)
}
catch(e: NCMBException){
Assert.assertEquals(e.message, "set the latitude to a value between -90 and 90")
@@ -88,9 +87,9 @@ class NCMBGeoPointTest {
@Test
fun test_geopoint_wrong_longitude(){
try {
- val latitude: Double = 35.6666269
- val longitude: Double = 189.765607
- val geopoint = NCMBGeoPoint(latitude, longitude)
+ val latitude = 35.6666269
+ val longitude = 189.765607
+ NCMBGeoPoint(latitude, longitude)
}
catch(e: NCMBException){
Assert.assertEquals(e.message, "set the longitude to a value between -180 and 180")
@@ -99,9 +98,9 @@ class NCMBGeoPointTest {
@Test
fun test_geopoint_save(){
- val latitude : Double = 35.6666269
- val longitude : Double = 139.765607
- var obj = NCMBObject("TestClassGeo")
+ val latitude = 35.6666269
+ val longitude = 139.765607
+ val obj = NCMBObject("TestClassGeo")
val geopoint = NCMBGeoPoint(latitude, longitude)
obj.put("geoPoint", geopoint)
obj.save()
@@ -111,8 +110,8 @@ class NCMBGeoPointTest {
@Test
fun test_geopoint_put(){
val inBackgroundHelper = NCMBInBackgroundTestHelper()
- val latitude : Double = 35.6666269
- val longitude : Double = 139.765607
+ val latitude = 35.6666269
+ val longitude = 139.765607
val obj = NCMBObject("TestClassGeo")
val geopoint = NCMBGeoPoint(latitude, longitude)
obj.put("geoPoint", geopoint)
@@ -132,7 +131,7 @@ class NCMBGeoPointTest {
@Test
fun test_geopoint_get(){
- var obj = NCMBObject("TestClassGeo")
+ val obj = NCMBObject("TestClassGeo")
obj.setObjectId("7FrmPTBKSNtVjajm")
obj.fetch()
val geo = obj.getGeo("geoPoint")
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBInstallationTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBInstallationTest.kt
index 6741ecb1..1351d526 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBInstallationTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBInstallationTest.kt
@@ -17,32 +17,26 @@
package com.nifcloud.mbaas.core
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
-import com.google.gson.JsonObject
import com.nifcloud.mbaas.core.NCMBDateFormat.getIso8601
import com.nifcloud.mbaas.core.helper.NCMBInBackgroundTestHelper
import okhttp3.mockwebserver.MockWebServer
import org.json.JSONArray
-import org.json.JSONObject
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
-import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
+import androidx.test.core.app.ApplicationProvider
import org.robolectric.annotation.Config
-import org.robolectric.shadows.ShadowLooper
-import java.lang.AssertionError
-import java.text.SimpleDateFormat
import java.util.*
/**
* 主に通信を行う自動化テストクラス
*/
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBInstallationTest {
private var mServer: MockWebServer = MockWebServer()
@@ -56,14 +50,14 @@ class NCMBInstallationTest {
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
"2013-09-01"
)
- callbackFlag = false;
+ callbackFlag = false
}
@Test
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBObjectTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBObjectTest.kt
index e085e4a4..c7586580 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBObjectTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBObjectTest.kt
@@ -28,17 +28,16 @@ import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import java.util.*
import kotlin.test.assertFails
-
+import androidx.test.core.app.ApplicationProvider
/**
* 主に通信を行う自動化テストクラス
*/
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBObjectTest {
private var mServer: MockWebServer = MockWebServer()
@@ -52,14 +51,14 @@ class NCMBObjectTest {
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
"2013-09-01"
)
- callbackFlag = false;
+ callbackFlag = false
}
/**
@@ -88,13 +87,12 @@ class NCMBObjectTest {
@Test
fun put_ignoreKey_test() {
val obj = NCMBObject("TestClass")
- val throwable_ignore1 = assertFails { obj.put("objectId", "stringValue") }
- Assert.assertEquals("Can't put data to same name with special key.", throwable_ignore1.message)
- val throwable_ignore2 = assertFails { obj.put("createDate", "TestCreateDate") }
- Assert.assertEquals("Can't put data to same name with special key.", throwable_ignore2.message)
- val throwable_ignore3 = assertFails { obj.put("updateDate", "TestUpdateDate") }
- Assert.assertEquals("Can't put data to same name with special key.", throwable_ignore3.message)
-
+ val throwableIgnore1 = assertFails { obj.put("objectId", "stringValue") }
+ Assert.assertEquals("Can't put data to same name with special key.", throwableIgnore1.message)
+ val throwableIgnore2 = assertFails { obj.put("createDate", "TestCreateDate") }
+ Assert.assertEquals("Can't put data to same name with special key.", throwableIgnore2.message)
+ val throwableIgnore3 = assertFails { obj.put("updateDate", "TestUpdateDate") }
+ Assert.assertEquals("Can't put data to same name with special key.", throwableIgnore3.message)
}
/**
@@ -166,7 +164,7 @@ class NCMBObjectTest {
@Test
@Throws(NCMBException::class)
fun save_object_with_post_data_save_success() {
- var obj = NCMBObject("TestClass")
+ val obj = NCMBObject("TestClass")
obj.put("key", "value")
obj.save()
Assert.assertEquals(obj.getObjectId(), "7FrmPTBKSNtVjajm")
@@ -489,7 +487,7 @@ class NCMBObjectTest {
*/
@Test
fun isIgnore_true_test() {
- var testObj = NCMBObject("TestClass")
+ val testObj = NCMBObject("TestClass")
Assert.assertEquals(testObj.isIgnoreKey("createDate"), true)
Assert.assertEquals(testObj.isIgnoreKey("updateDate"), true)
Assert.assertEquals(testObj.isIgnoreKey("objectId"), true)
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBPushTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBPushTest.kt
index 831ed651..4ea2b519 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBPushTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBPushTest.kt
@@ -21,7 +21,6 @@ import com.nifcloud.mbaas.core.NCMBDateFormat.getIso8601
import com.nifcloud.mbaas.core.helper.NCMBInBackgroundTestHelper
import okhttp3.mockwebserver.MockWebServer
import org.json.JSONArray
-import org.json.JSONException
import org.json.JSONObject
import org.junit.Assert
import org.junit.Before
@@ -30,7 +29,7 @@ import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
+import androidx.test.core.app.ApplicationProvider
import org.robolectric.annotation.Config
import java.lang.Exception
import java.text.DateFormat
@@ -42,7 +41,7 @@ import java.util.*
* 主に通信を行う自動化テストクラス
*/
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBPushTest {
private var mServer: MockWebServer = MockWebServer()
@@ -56,14 +55,14 @@ class NCMBPushTest {
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
"2013-09-01"
)
- callbackFlag = false;
+ callbackFlag = false
}
/**
@@ -71,7 +70,7 @@ class NCMBPushTest {
*/
@Test
fun put_push_data_test() {
- var pushObj = NCMBPush()
+ val pushObj = NCMBPush()
pushObj.title = "title_update"
pushObj.message = "message_update"
pushObj.immediateDeliveryFlag = true
@@ -193,9 +192,9 @@ class NCMBPushTest {
push.immediateDeliveryFlag = true
push.isSendToIOS = true
push.save()
- val TestJSON = JSONObject()
- TestJSON.put("target",JSONArray(arrayListOf("ios")))
- Assert.assertEquals(TestJSON.get("target"), push.mFields.get("target"))
+ val testJSON = JSONObject()
+ testJSON.put("target",JSONArray(arrayListOf("ios")))
+ Assert.assertEquals(testJSON.get("target"), push.mFields.get("target"))
val push2 = NCMBPush()
push2.title = "title_update"
@@ -204,9 +203,9 @@ class NCMBPushTest {
push2.isSendToIOS = true
push2.isSendToAndroid = true
push2.save()
- val TestJSON2 = JSONObject()
- TestJSON2.put("target",JSONArray(arrayListOf("ios", "android")))
- Assert.assertEquals(TestJSON2.get("target"), push2.mFields.get("target"))
+ val testJSON2 = JSONObject()
+ testJSON2.put("target",JSONArray(arrayListOf("ios", "android")))
+ Assert.assertEquals(testJSON2.get("target"), push2.mFields.get("target"))
val push3 = NCMBPush()
push3.title = "title_update"
@@ -215,7 +214,7 @@ class NCMBPushTest {
push3.isSendToIOS = true
push3.isSendToAndroid = false
push3.save()
- Assert.assertEquals(TestJSON.get("target"), push3.mFields.get("target"))
+ Assert.assertEquals(testJSON.get("target"), push3.mFields.get("target"))
}
/**
@@ -237,9 +236,9 @@ class NCMBPushTest {
} catch (e: NCMBException) {
error = e
}
- val TestJSON = JSONObject()
- TestJSON.put("target",JSONArray(arrayListOf("android")))
- Assert.assertEquals(TestJSON.get("target"), push.mFields.get("target"))
+ val testJSON = JSONObject()
+ testJSON.put("target",JSONArray(arrayListOf("android")))
+ Assert.assertEquals(testJSON.get("target"), push.mFields.get("target"))
//check
Assert.assertNull(error)
Assert.assertEquals("7FrmPTBKSNtVjajm", push.getObjectId())
@@ -267,9 +266,9 @@ class NCMBPushTest {
} catch (e: NCMBException) {
error = e
}
- val TestJSON = JSONObject()
- TestJSON.put("target",JSONArray(arrayListOf("android", "ios")))
- Assert.assertEquals(TestJSON.get("target"), push.mFields.get("target"))
+ val testJSON = JSONObject()
+ testJSON.put("target",JSONArray(arrayListOf("android", "ios")))
+ Assert.assertEquals(testJSON.get("target"), push.mFields.get("target"))
//check
Assert.assertNull(error)
Assert.assertEquals("title_update", push.title)
@@ -290,7 +289,6 @@ class NCMBPushTest {
val df = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
df.timeZone = TimeZone.getTimeZone("Etc/UTC")
try {
- val date = df.parse("2030-10-10 10:10:10")
push.setObjectId("7FrmPTBKSNtVjajm")
push.title = "title_update"
push.message = "message_update"
@@ -303,9 +301,9 @@ class NCMBPushTest {
} catch (e: NCMBException) {
error = e
}
- val TestJSON = JSONObject()
- TestJSON.put("target",JSONArray(arrayListOf("android", "ios")))
- Assert.assertEquals(TestJSON.get("target"), push.mFields.get("target"))
+ val testJSON = JSONObject()
+ testJSON.put("target",JSONArray(arrayListOf("android", "ios")))
+ Assert.assertEquals(testJSON.get("target"), push.mFields.get("target"))
//check
Assert.assertNull(error)
Assert.assertEquals("title_update", push.title)
@@ -339,9 +337,9 @@ class NCMBPushTest {
} catch (e: NCMBException) {
error = e
}
- val TestJSON = JSONObject()
- TestJSON.put("target",JSONArray(arrayListOf("android", "ios")))
- Assert.assertEquals(TestJSON.get("target"), push.mFields.get("target"))
+ val testJSON = JSONObject()
+ testJSON.put("target",JSONArray(arrayListOf("android", "ios")))
+ Assert.assertEquals(testJSON.get("target"), push.mFields.get("target"))
//check
Assert.assertNull(error)
Assert.assertEquals("title_update", push.title)
@@ -370,9 +368,9 @@ class NCMBPushTest {
} catch (e: NCMBException) {
error = e
}
- val TestJSON = JSONObject()
- TestJSON.put("target",JSONArray(arrayListOf("android", "ios")))
- Assert.assertEquals(TestJSON.get("target"), push.mFields.get("target"))
+ val testJSON = JSONObject()
+ testJSON.put("target",JSONArray(arrayListOf("android", "ios")))
+ Assert.assertEquals(testJSON.get("target"), push.mFields.get("target"))
//check
Assert.assertNull(error)
Assert.assertEquals("title_update", push.title)
@@ -388,7 +386,7 @@ class NCMBPushTest {
@Test
@Throws(Exception::class)
fun send_post_deliveryExpirationDate() {
- var error: NCMBException? = null
+ val error: NCMBException? = null
val push = NCMBPush()
val df = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
df.timeZone = TimeZone.getTimeZone("Etc/UTC")
@@ -401,9 +399,9 @@ class NCMBPushTest {
push.isSendToAndroid = true
push.isSendToIOS = true
push.save()
- val TestJSON = JSONObject()
- TestJSON.put("target",JSONArray(arrayListOf("android", "ios")))
- Assert.assertEquals(TestJSON.get("target"), push.mFields.get("target"))
+ val testJSON = JSONObject()
+ testJSON.put("target",JSONArray(arrayListOf("android", "ios")))
+ Assert.assertEquals(testJSON.get("target"), push.mFields.get("target"))
//check
Assert.assertNull(error)
Assert.assertEquals("title_update", push.title)
@@ -413,8 +411,8 @@ class NCMBPushTest {
Assert.assertEquals(format.parse("2014-06-04T11:28:30.348Z"), push.getUpdateDate())
} catch (e: ParseException) {
e.printStackTrace()
- } catch (e: NCMBException) {
- error = e
+ } catch (ex: NCMBException) {
+ ex.printStackTrace()
}
}
@@ -445,9 +443,9 @@ class NCMBPushTest {
} catch (e: NCMBException) {
error = e
}
- val TestJSON = JSONObject()
- TestJSON.put("target",JSONArray(arrayListOf("android", "ios")))
- Assert.assertEquals(TestJSON.get("target"), push.mFields.get("target"))
+ val testJSON = JSONObject()
+ testJSON.put("target",JSONArray(arrayListOf("android", "ios")))
+ Assert.assertEquals(testJSON.get("target"), push.mFields.get("target"))
Assert.assertNull(error)
Assert.assertEquals("http://www.yahoo.co.jp/", push.mFields.get("richUrl"))
Assert.assertEquals(true, push.mFields.getBoolean("immediateDeliveryFlag"))
@@ -476,9 +474,9 @@ class NCMBPushTest {
} catch (e: NCMBException) {
error = e
}
- val TestJSON = JSONObject()
- TestJSON.put("target",JSONArray(arrayListOf("android", "ios")))
- Assert.assertEquals(TestJSON.get("target"), push.mFields.get("target"))
+ val testJSON = JSONObject()
+ testJSON.put("target",JSONArray(arrayListOf("android", "ios")))
+ Assert.assertEquals(testJSON.get("target"), push.mFields.get("target"))
Assert.assertNull(error)
Assert.assertEquals("http://www.yahoo.co.jp/", push.mFields.get("richUrl"))
Assert.assertEquals(true, push.mFields.getBoolean("immediateDeliveryFlag"))
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBQueryTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBQueryTest.kt
index fd9c2354..7814bbb2 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBQueryTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBQueryTest.kt
@@ -26,7 +26,7 @@ import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
+import androidx.test.core.app.ApplicationProvider
import org.robolectric.annotation.Config
import org.skyscreamer.jsonassert.JSONAssert
import java.lang.Exception
@@ -35,7 +35,7 @@ import kotlin.test.assertFails
//Android環境のベースにテスト実装するため
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBQueryTest {
//mockserver preparation
@@ -52,7 +52,7 @@ class NCMBQueryTest {
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
@@ -65,7 +65,7 @@ class NCMBQueryTest {
val inBackgroundHelper = NCMBInBackgroundTestHelper() // ヘルパーの初期化
//TestClassクラスを検索するクエリを作成
val query = NCMBQuery.forObject("TestClass")
- query.whereEqualTo("key", "value");
+ query.whereEqualTo("key", "value")
val callback = NCMBCallback { e, objects ->
inBackgroundHelper["e"] = e
inBackgroundHelper["objects"] = objects
@@ -77,15 +77,15 @@ class NCMBQueryTest {
Assert.assertTrue(inBackgroundHelper.isCalledRelease())
Assert.assertNull(inBackgroundHelper["e"])
Assert.assertEquals(
- (inBackgroundHelper["objects"] as List)[0].getObjectId(),
+ ((inBackgroundHelper["objects"] as List<*>)[0] as NCMBObject).getObjectId(),
"8FgKqFlH8dZRDrBJ"
)
Assert.assertEquals(
- (inBackgroundHelper["objects"] as List)[0].getString("key"),
+ ((inBackgroundHelper["objects"] as List<*>)[0] as NCMBObject).getString("key"),
"value"
)
Assert.assertEquals(
- (inBackgroundHelper["objects"] as List)[0].keys.size,
+ ((inBackgroundHelper["objects"] as List<*>)[0] as NCMBObject).keys.size,
5
)
}
@@ -107,7 +107,7 @@ class NCMBQueryTest {
Assert.assertNull(inBackgroundHelper["e"])
Assert.assertEquals(
0,
- (inBackgroundHelper["objects"] as List).size
+ (inBackgroundHelper["objects"] as List<*>).size
)
}
@@ -127,11 +127,11 @@ class NCMBQueryTest {
Assert.assertTrue(inBackgroundHelper.isCalledRelease())
Assert.assertNull(inBackgroundHelper["e"])
Assert.assertEquals(
- (inBackgroundHelper["objects"] as List)[0].getObjectId(),
+ ((inBackgroundHelper["objects"] as List<*>)[0] as NCMBObject).getObjectId(),
"8FgKqFlH8dZRDrBJ"
)
Assert.assertEquals(
- (inBackgroundHelper["objects"] as List)[1].getObjectId(),
+ ((inBackgroundHelper["objects"] as List<*>)[1] as NCMBObject).getObjectId(),
"eQRqoObEZmtrfgzH"
)
}
@@ -372,7 +372,7 @@ class NCMBQueryTest {
@Test
fun testNCMBObject_WhereContainedIn_Success() {
val query = NCMBQuery.forObject("TestClassContainedIn")
- val objs = setOf(1,2,3)
+ val objs = setOf(1,2,3)
query.whereContainedIn("keyArray", objs)
val objects = query.find()
Assert.assertEquals(
@@ -411,7 +411,7 @@ class NCMBQueryTest {
@Test
fun testNCMBObject_WhereContainedInArray_Success() {
val query = NCMBQuery.forObject("TestClassContainedInArray")
- val objs = setOf(1,2,3)
+ val objs = setOf(1,2,3)
query.whereContainedInArray("keyArray", objs)
val objects = query.find()
Assert.assertEquals(
@@ -450,7 +450,7 @@ class NCMBQueryTest {
@Test
fun testNCMBObject_WhereNotContainedInArray_Success() {
val query = NCMBQuery.forObject("TestClassNotContainedInArray")
- val objs = setOf(1,2,3)
+ val objs = setOf(1,2,3)
query.whereNotContainedInArray("keyArray", objs)
val objects = query.find()
Assert.assertEquals(
@@ -489,7 +489,7 @@ class NCMBQueryTest {
@Test
fun testNCMBObject_WhereNotContainedIn_Success() {
val query = NCMBQuery.forObject("TestClassNotContainedIn")
- val objs = setOf(1,2,3)
+ val objs = setOf(1,2,3)
query.whereNotContainedIn("keyArray", objs)
val objects = query.find()
Assert.assertEquals(
@@ -528,7 +528,7 @@ class NCMBQueryTest {
@Test
fun testNCMBObject_WhereContainedAll_Success() {
val query = NCMBQuery.forObject("TestClassContainedAll")
- val objs = setOf(1,2,3)
+ val objs = setOf(1,2,3)
query.whereContainsAll("keyArray", objs)
val objects = query.find()
Assert.assertEquals(
@@ -567,7 +567,7 @@ class NCMBQueryTest {
@Test
fun testNCMBObject_WhereContainedIn_StringArray_Success() {
val query = NCMBQuery.forObject("TestClassContainedIn_String")
- val objs = setOf("1","2","3")
+ val objs = setOf("1","2","3")
query.whereContainedIn("keyArray", objs)
val objects = query.find()
Assert.assertEquals(
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBScriptTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBScriptTest.kt
index 62b50d0c..6cb6723a 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBScriptTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBScriptTest.kt
@@ -18,7 +18,6 @@ package com.nifcloud.mbaas.core
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.nifcloud.mbaas.core.helper.NCMBInBackgroundTestHelper
-import kotlinx.serialization.json.JSON
import okhttp3.mockwebserver.MockWebServer
import org.json.JSONObject
import org.junit.Assert
@@ -28,11 +27,11 @@ import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
+import androidx.test.core.app.ApplicationProvider
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(26), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBScriptTest {
private var mServer: MockWebServer = MockWebServer()
@@ -46,7 +45,7 @@ class NCMBScriptTest {
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBTest.kt
index 66658ed4..77a75a84 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBTest.kt
@@ -22,27 +22,23 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
-
+import androidx.test.core.app.ApplicationProvider
/**
* 初期化のテスト
*
- * @param applicationKey & clientKey は apikey
- * @property なし .
- * @constructor なし .
*/
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBTest {
private var mServer: MockWebServer = MockWebServer()
@Before
@Throws(Exception::class)
fun setup() {
- var ncmbDispatcher = NCMBDispatcher("")
+ val ncmbDispatcher = NCMBDispatcher("")
mServer.dispatcher = ncmbDispatcher
mServer.start()
}
@@ -51,11 +47,11 @@ class NCMBTest {
* シンプルなapikeyの初期化テスト
*/
@Test
- fun Initialize_test() {
- var applicationKey = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
- var clientKey = "111111111111111111111111111111111111111111111111111111111111111"
+ fun initialize_test() {
+ val applicationKey = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
+ val clientKey = "111111111111111111111111111111111111111111111111111111111111111"
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
applicationKey,
clientKey)
Assert.assertEquals(applicationKey, NCMB.getApplicationKey())
@@ -68,13 +64,13 @@ class NCMBTest {
* シンプルなapikeyの初期化テスト
*/
@Test
- fun Initialize_test_domainurl_apiversion() {
- var applicationKey = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
- var clientKey = "111111111111111111111111111111111111111111111111111111111111111"
- var domainUrl = "https://mbaas.api.nifcloud.com/"
- var apiVersion = "2013-09-01"
+ fun initialize_test_domainurl_apiversion() {
+ val applicationKey = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
+ val clientKey = "111111111111111111111111111111111111111111111111111111111111111"
+ val domainUrl = "https://mbaas.api.nifcloud.com/"
+ val apiVersion = "2013-09-01"
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
applicationKey,
clientKey,
domainUrl,
@@ -89,15 +85,15 @@ class NCMBTest {
* シンプルなapikeyの初期化テスト
*/
@Test
- fun Initialize_test_domainurlScript_apiversionScript() {
- var applicationKey = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
- var clientKey = "111111111111111111111111111111111111111111111111111111111111111"
- var domainUrl = "https://testdomain.com/"
- var apiVersion = "2013-09-01"
- var scriptDomainUrl = "https://scripttestdomain.com/"
- var scriptApiVersion = "2015-09-01"
+ fun initialize_test_domainurlScript_apiversionScript() {
+ val applicationKey = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
+ val clientKey = "111111111111111111111111111111111111111111111111111111111111111"
+ val domainUrl = "https://testdomain.com/"
+ val apiVersion = "2013-09-01"
+ val scriptDomainUrl = "https://scripttestdomain.com/"
+ val scriptApiVersion = "2015-09-01"
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
applicationKey,
clientKey,
domainUrl,
@@ -115,11 +111,11 @@ class NCMBTest {
* シンプルなapikeyの初期化テスト
*/
@Test
- fun Initialize_onlyapiclientkey_test() {
- var applicationKey = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
- var clientKey = "111111111111111111111111111111111111111111111111111111111111111"
+ fun initialize_onlyapiclientkey_test() {
+ val applicationKey = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
+ val clientKey = "111111111111111111111111111111111111111111111111111111111111111"
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
applicationKey,
clientKey
)
@@ -132,18 +128,18 @@ class NCMBTest {
* 初期化が2度起きた時のテスト
*/
@Test
- fun Initialize_two_times() {
- var applicationKey1 = "0123456789"
- var clientKey1 = "111111111"
- var applicationKey2 = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
- var clientKey2 = "111111111111111111111111111111111111111111111111111111111111111"
+ fun initialize_two_times() {
+ val applicationKey1 = "0123456789"
+ val clientKey1 = "111111111"
+ val applicationKey2 = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
+ val clientKey2 = "111111111111111111111111111111111111111111111111111111111111111"
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
applicationKey1,
clientKey1
)
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
applicationKey2,
clientKey2
)
@@ -155,9 +151,9 @@ class NCMBTest {
* 直接apikeyを代入した初期化のテスト.
*/
@Test
- fun Initialize_direct() {
+ fun initialize_direct() {
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"111111111111111111111111111111111111111111111111111111111111111"
)
diff --git a/src/test/java/com/nifcloud/mbaas/core/NCMBUserTest.kt b/src/test/java/com/nifcloud/mbaas/core/NCMBUserTest.kt
index ef9cb3b3..9c9921cb 100644
--- a/src/test/java/com/nifcloud/mbaas/core/NCMBUserTest.kt
+++ b/src/test/java/com/nifcloud/mbaas/core/NCMBUserTest.kt
@@ -27,7 +27,7 @@ import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
-import org.robolectric.RuntimeEnvironment
+import androidx.test.core.app.ApplicationProvider
import org.robolectric.annotation.Config
import java.util.Date
@@ -36,7 +36,7 @@ import java.util.Date
* 主に通信を行う自動化テストクラス
*/
@RunWith(RobolectricTestRunner::class)
-@Config(sdk = intArrayOf(27), manifest = Config.NONE)
+@Config(sdk = [27], manifest = Config.NONE)
class NCMBUserTest {
private var mServer: MockWebServer = MockWebServer()
@@ -47,11 +47,11 @@ class NCMBUserTest {
val rule: TestRule = InstantTaskExecutorRule()
@Before
fun setup() {
- var ncmbDispatcher = NCMBDispatcher("users")
+ val ncmbDispatcher = NCMBDispatcher("users")
mServer.dispatcher = ncmbDispatcher
mServer.start()
NCMB.initialize(
- RuntimeEnvironment.application.getApplicationContext(),
+ ApplicationProvider.getApplicationContext(),
"appKey",
"cliKey",
mServer.url("/").toString(),
@@ -71,7 +71,7 @@ class NCMBUserTest {
user.setObjectId("dummyUserId")
user.put("key", "value")
user.save()
- val date: Date = getIso8601().parse("2014-06-04T11:28:30.348Z")
+ val date: Date? = getIso8601().parse("2014-06-04T11:28:30.348Z")
Assert.assertEquals(user.getUpdateDate(), date)
}
@@ -107,7 +107,7 @@ class NCMBUserTest {
@Test
@Throws(java.lang.Exception::class)
fun login_and_getCurrentUser() {
- val user: NCMBUser = NCMBUser().login("Ncmb Tarou", "dummyPassword")
+ NCMBUser().login("Ncmb Tarou", "dummyPassword")
Assert.assertEquals("dummyObjectId", NCMBUser().getCurrentUser().getObjectId())
Assert.assertEquals("Ncmb Tarou", NCMBUser().getCurrentUser().userName)
Assert.assertEquals("ebDH8TtmLoygzjqjaI4EWFfxc", NCMB.SESSION_TOKEN)