From e9b4ec62a124a48fe5adad0aa3f903fcb7e248df Mon Sep 17 00:00:00 2001 From: Yusuke Matsubara Date: Tue, 14 Nov 2017 16:56:41 +0900 Subject: [PATCH] Convert tests into Kotlin --- app/build.gradle | 16 ++++++++-- .../java/fr/free/nrw/commons/UtilsTest.java | 32 ------------------- .../kotlin/fr/free/nrw/commons/UtilsTest.kt | 32 +++++++++++++++++++ build.gradle | 2 ++ 4 files changed, 47 insertions(+), 35 deletions(-) delete mode 100644 app/src/test/java/fr/free/nrw/commons/UtilsTest.java create mode 100644 app/src/test/kotlin/fr/free/nrw/commons/UtilsTest.kt diff --git a/app/build.gradle b/app/build.gradle index f45aa7cd4..1511c3ecd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,6 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-kapt' apply plugin: 'jacoco-android' apply from: 'quality.gradle' apply plugin: 'com.getkeepsafe.dexcount' @@ -19,6 +21,7 @@ dependencies { transitive=true } + implementation "com.android.support:support-v4:${project.supportLibVersion}" implementation "com.android.support:appcompat-v7:${project.supportLibVersion}" implementation "com.android.support:design:${project.supportLibVersion}" @@ -26,7 +29,7 @@ dependencies { implementation "com.android.support:cardview-v7:${project.supportLibVersion}" implementation "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION" - annotationProcessor "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION" + kapt "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION" implementation 'com.squareup.okhttp3:okhttp:3.8.1' implementation 'com.squareup.okio:okio:1.13.0' @@ -46,8 +49,11 @@ dependencies { implementation "com.google.dagger:dagger:$DAGGER_VERSION" implementation "com.google.dagger:dagger-android-support:$DAGGER_VERSION" - annotationProcessor "com.google.dagger:dagger-android-processor:$DAGGER_VERSION" - annotationProcessor "com.google.dagger:dagger-compiler:$DAGGER_VERSION" + kapt "com.google.dagger:dagger-android-processor:$DAGGER_VERSION" + kapt "com.google.dagger:dagger-compiler:$DAGGER_VERSION" + + testImplementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" + androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" testImplementation 'junit:junit:4.12' testImplementation 'org.robolectric:robolectric:3.4' @@ -78,6 +84,10 @@ android { vectorDrawables.useSupportLibrary = true } + sourceSets { + test.java.srcDirs += 'src/test/kotlin' + } + buildTypes { release { minifyEnabled false // See https://stackoverflow.com/questions/40232404/google-play-apk-and-android-studio-apk-usb-debug-behaving-differently - proguard.cfg modification alone insufficient. diff --git a/app/src/test/java/fr/free/nrw/commons/UtilsTest.java b/app/src/test/java/fr/free/nrw/commons/UtilsTest.java deleted file mode 100644 index a51b7a19a..000000000 --- a/app/src/test/java/fr/free/nrw/commons/UtilsTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package fr.free.nrw.commons; - -import org.junit.Assert; -import org.junit.Test; - -import static org.hamcrest.CoreMatchers.is; - -public class UtilsTest { - @Test public void stripLocalizedStringPass() { - Assert.assertThat(Utils.stripLocalizedString("Hello"), is("Hello")); - } - - @Test public void stripLocalizedStringJa() { - Assert.assertThat(Utils.stripLocalizedString("\"こんにちは\"@ja"), is("こんにちは")); - } - - @Test public void capitalizeLowercase() { - Assert.assertThat(Utils.capitalize("hello"), is("Hello")); - } - - @Test public void capitalizeFullCaps() { - Assert.assertThat(Utils.capitalize("HELLO"), is("HELLO")); - } - - @Test public void capitalizeNumbersPass() { - Assert.assertThat(Utils.capitalize("12x"), is("12x")); - } - - @Test public void capitalizeJaPass() { - Assert.assertThat(Utils.capitalize("こんにちは"), is("こんにちは")); - } -} diff --git a/app/src/test/kotlin/fr/free/nrw/commons/UtilsTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/UtilsTest.kt new file mode 100644 index 000000000..5b57b6253 --- /dev/null +++ b/app/src/test/kotlin/fr/free/nrw/commons/UtilsTest.kt @@ -0,0 +1,32 @@ +package fr.free.nrw.commons + +import org.hamcrest.CoreMatchers.`is` as _is + +import org.junit.Assert +import org.junit.Test + +class UtilsTest { + @Test fun `strip nothing from non-localized string`() { + Assert.assertThat(Utils.stripLocalizedString("Hello"), _is("Hello")) + } + + @Test fun `strip tag from Japanese string`() { + Assert.assertThat(Utils.stripLocalizedString("\"こんにちは\"@ja"), _is("こんにちは")) + } + + @Test fun `capitalize first letter`() { + Assert.assertThat(Utils.capitalize("hello"), _is("Hello")) + } + + @Test fun `capitalize - pass all-capital string as it is`() { + Assert.assertThat(Utils.capitalize("HELLO"), _is("HELLO")) + } + + @Test fun `capitalize - pass numbers`() { + Assert.assertThat(Utils.capitalize("12x"), _is("12x")) + } + + @Test fun `capitalize - pass Japanase characters`() { + Assert.assertThat(Utils.capitalize("こんにちは"), _is("こんにちは")) + } +} diff --git a/build.gradle b/build.gradle index 732be0d6e..1738c6dee 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.1.51' repositories { jcenter() mavenCentral() @@ -10,6 +11,7 @@ buildscript { classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1' classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.1' classpath 'me.tatarka:gradle-retrolambda:3.6.1' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } }