Skip to content

Commit e9b4ec6

Browse files
committed
Convert tests into Kotlin
1 parent e429667 commit e9b4ec6

File tree

4 files changed

+47
-35
lines changed

4 files changed

+47
-35
lines changed

app/build.gradle

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-kapt'
24
apply plugin: 'jacoco-android'
35
apply from: 'quality.gradle'
46
apply plugin: 'com.getkeepsafe.dexcount'
@@ -19,14 +21,15 @@ dependencies {
1921
transitive=true
2022
}
2123

24+
2225
implementation "com.android.support:support-v4:${project.supportLibVersion}"
2326
implementation "com.android.support:appcompat-v7:${project.supportLibVersion}"
2427
implementation "com.android.support:design:${project.supportLibVersion}"
2528

2629
implementation "com.android.support:cardview-v7:${project.supportLibVersion}"
2730

2831
implementation "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION"
29-
annotationProcessor "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION"
32+
kapt "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION"
3033

3134
implementation 'com.squareup.okhttp3:okhttp:3.8.1'
3235
implementation 'com.squareup.okio:okio:1.13.0'
@@ -46,8 +49,11 @@ dependencies {
4649
implementation "com.google.dagger:dagger:$DAGGER_VERSION"
4750
implementation "com.google.dagger:dagger-android-support:$DAGGER_VERSION"
4851

49-
annotationProcessor "com.google.dagger:dagger-android-processor:$DAGGER_VERSION"
50-
annotationProcessor "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
52+
kapt "com.google.dagger:dagger-android-processor:$DAGGER_VERSION"
53+
kapt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
54+
55+
testImplementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
56+
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
5157

5258
testImplementation 'junit:junit:4.12'
5359
testImplementation 'org.robolectric:robolectric:3.4'
@@ -78,6 +84,10 @@ android {
7884
vectorDrawables.useSupportLibrary = true
7985
}
8086

87+
sourceSets {
88+
test.java.srcDirs += 'src/test/kotlin'
89+
}
90+
8191
buildTypes {
8292
release {
8393
minifyEnabled false // See https://stackoverflow.com/questions/40232404/google-play-apk-and-android-studio-apk-usb-debug-behaving-differently - proguard.cfg modification alone insufficient.

app/src/test/java/fr/free/nrw/commons/UtilsTest.java

-32
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package fr.free.nrw.commons
2+
3+
import org.hamcrest.CoreMatchers.`is` as _is
4+
5+
import org.junit.Assert
6+
import org.junit.Test
7+
8+
class UtilsTest {
9+
@Test fun `strip nothing from non-localized string`() {
10+
Assert.assertThat(Utils.stripLocalizedString("Hello"), _is("Hello"))
11+
}
12+
13+
@Test fun `strip tag from Japanese string`() {
14+
Assert.assertThat(Utils.stripLocalizedString("\"こんにちは\"@ja"), _is("こんにちは"))
15+
}
16+
17+
@Test fun `capitalize first letter`() {
18+
Assert.assertThat(Utils.capitalize("hello"), _is("Hello"))
19+
}
20+
21+
@Test fun `capitalize - pass all-capital string as it is`() {
22+
Assert.assertThat(Utils.capitalize("HELLO"), _is("HELLO"))
23+
}
24+
25+
@Test fun `capitalize - pass numbers`() {
26+
Assert.assertThat(Utils.capitalize("12x"), _is("12x"))
27+
}
28+
29+
@Test fun `capitalize - pass Japanase characters`() {
30+
Assert.assertThat(Utils.capitalize("こんにちは"), _is("こんにちは"))
31+
}
32+
}

build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
3+
ext.kotlin_version = '1.1.51'
34
repositories {
45
jcenter()
56
mavenCentral()
@@ -10,6 +11,7 @@ buildscript {
1011
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1'
1112
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.1'
1213
classpath 'me.tatarka:gradle-retrolambda:3.6.1'
14+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1315
}
1416
}
1517

0 commit comments

Comments
 (0)