Skip to content

Commit 9dfd896

Browse files
authored
Merge pull request #235 from nhaarman/2.x-testing
Move tests to separate module
2 parents d848be8 + 5c034d4 commit 9dfd896

24 files changed

+87
-96
lines changed

.travis.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ matrix:
99
- jdk: oraclejdk8
1010
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.1.61
1111
- jdk: oraclejdk8
12-
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.2.10
12+
env: TERM=dumb MOCK_MAKER=mock-maker-inline KOTLIN_VERSION=1.2.20
1313
- jdk: oraclejdk8
1414
env: TERM=dumb KOTLIN_VERSION=1.0.7
1515
- jdk: oraclejdk8
1616
env: TERM=dumb KOTLIN_VERSION=1.1.61
1717
- jdk: oraclejdk8
18-
env: TERM=dumb KOTLIN_VERSION=1.2.10
18+
env: TERM=dumb KOTLIN_VERSION=1.2.20
1919

2020

2121
env:
@@ -26,7 +26,10 @@ install:
2626
- true
2727

2828
script:
29-
- ./gradlew test
29+
- ops/mockMakerInline.sh
30+
- ./gradlew clean
31+
- ./gradlew assemble
32+
- ./gradlew test -i
3033

3134
notifications:
32-
email: false
35+
email: false

mockito-kotlin/build.gradle

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply from: '../publishing.gradle'
33
apply plugin: 'org.jetbrains.dokka'
44

55
buildscript {
6-
ext.kotlin_version = System.getenv("KOTLIN_VERSION") ?: '1.0.7'
6+
ext.kotlin_version = "1.2.20"
77

88
repositories {
99
mavenCentral()
@@ -24,12 +24,8 @@ repositories {
2424
}
2525

2626
dependencies {
27-
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
27+
compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
2828
compile "org.mockito:mockito-core:2.13.0"
29-
30-
/* Tests */
31-
testCompile "junit:junit:4.12"
32-
testCompile "com.nhaarman:expect.kt:1.0.0"
3329
}
3430

3531
dokka {
@@ -43,26 +39,3 @@ dokka {
4339
}
4440
}
4541
javadoc.dependsOn dokka
46-
47-
//Switch inline
48-
task createTestResources {
49-
def mockMakerFile = new File("$projectDir/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker")
50-
if (System.env.MOCK_MAKER != null) {
51-
logger.warn("! Using MockMaker ${System.env.MOCK_MAKER}")
52-
mockMakerFile.parentFile.mkdirs()
53-
mockMakerFile.createNewFile()
54-
mockMakerFile.write(System.env.MOCK_MAKER)
55-
} else {
56-
logger.warn("! Using default MockMaker")
57-
}
58-
}
59-
60-
task removeTestResources {
61-
def mockMakerFile = new File("$projectDir/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker")
62-
if (mockMakerFile.exists()) {
63-
mockMakerFile.delete()
64-
}
65-
}
66-
67-
test.dependsOn createTestResources
68-
test.finalizedBy removeTestResources

mockito-kotlin/src/main/kotlin/com/nhaarman/mockitokotlin2/internal/MockMaker.kt

Lines changed: 0 additions & 35 deletions
This file was deleted.

mockito-kotlin/src/test/kotlin/test/TestBase.kt

Lines changed: 0 additions & 18 deletions
This file was deleted.

ops/mockMakerInline.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -ev
4+
5+
if [ ${MOCK_MAKER} = "mock-maker-inline" ]; then
6+
mkdir -p tests/src/test/resources/mockito-extensions
7+
cp ops/org.mockito.plugins.MockMaker tests/src/test/resources/mockito-extensions/
8+
fi
9+
10+
exit 0;
11+

ops/org.mockito.plugins.MockMaker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mock-maker-inline

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
include 'mockito-kotlin'
2+
include 'tests'

tests/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Mockito-Kotlin tests
2+
====================
3+
4+
Tests should be placed in this module.
5+
CI is set up to execute tests for all major versions of Kotlin,
6+
whilst keeping the library version on the latest version.
7+
This ensures the library is backwards compatible for all Kotlin versions.

tests/build.gradle

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
buildscript {
2+
ext.kotlin_version = '1.2.20'
3+
ext.kotlin_version = System.getenv("KOTLIN_VERSION") ?: '1.0.7'
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
dependencies {
9+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
10+
}
11+
}
12+
13+
apply plugin: 'java'
14+
apply plugin: 'kotlin'
15+
16+
repositories {
17+
mavenCentral()
18+
jcenter()
19+
}
20+
21+
dependencies {
22+
compile files("${rootProject.projectDir}/mockito-kotlin/build/libs/mockito-kotlin-${rootProject.ext.versionName}.jar")
23+
24+
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
25+
compile "org.mockito:mockito-core:2.13.0"
26+
27+
testCompile "junit:junit:4.12"
28+
testCompile "com.nhaarman:expect.kt:1.0.0"
29+
}

mockito-kotlin/src/test/kotlin/test/EqTest.kt renamed to tests/src/test/kotlin/test/EqTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
package test/*
1+
package test
2+
3+
/*
24
* The MIT License
35
*
46
* Copyright (c) 2016 Niek Haarman
@@ -40,9 +42,7 @@ class EqTest : TestBase() {
4042
private lateinit var doAnswer: Open
4143

4244
@Before
43-
override fun setup() {
44-
super.setup()
45-
45+
fun setup() {
4646
/* Create a proper Mockito state */
4747
doAnswer = Mockito.doAnswer { }.`when`(mock())
4848
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package test
2+
3+
import org.mockito.internal.configuration.plugins.Plugins
4+
import org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker
5+
6+
7+
internal var mockMakerInlineEnabled: Boolean? = null
8+
internal fun mockMakerInlineEnabled(): Boolean {
9+
return mockMakerInlineEnabled ?: (Plugins.getMockMaker() is InlineByteBuddyMockMaker)
10+
}

mockito-kotlin/src/test/kotlin/test/OngoingStubbingTest.kt renamed to tests/src/test/kotlin/test/OngoingStubbingTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.nhaarman.expect.expect
44
import com.nhaarman.expect.expectErrorWithMessage
55
import com.nhaarman.expect.fail
66
import com.nhaarman.mockitokotlin2.*
7+
import org.junit.Assume.assumeFalse
78
import org.junit.Test
89
import org.mockito.Mockito
910
import org.mockito.stubbing.Answer
@@ -263,6 +264,7 @@ class OngoingStubbingTest : TestBase() {
263264

264265
@Test
265266
fun doReturn_throwsNPE() {
267+
assumeFalse(mockMakerInlineEnabled())
266268
expectErrorWithMessage("look at the stack trace below") on {
267269

268270
/* When */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package test
2+
3+
import org.junit.After
4+
5+
abstract class TestBase {
6+
7+
@After
8+
open fun tearDown() {
9+
mockMakerInlineEnabled = null
10+
}
11+
}

mockito-kotlin/src/test/kotlin/test/inline/UsingMockMakerInlineTest.kt renamed to tests/src/test/kotlin/test/inline/UsingMockMakerInlineTest.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@
2323
*/
2424

2525
import com.nhaarman.expect.expect
26-
import com.nhaarman.mockitokotlin2.any
27-
import com.nhaarman.mockitokotlin2.internal.mockMakerInlineEnabled
28-
import com.nhaarman.mockitokotlin2.doReturn
29-
import com.nhaarman.mockitokotlin2.mock
30-
import com.nhaarman.mockitokotlin2.verify
31-
import com.nhaarman.mockitokotlin2.whenever
26+
import com.nhaarman.mockitokotlin2.*
3227
import org.junit.Assume.assumeTrue
3328
import org.junit.Before
3429
import org.junit.Test
30+
import test.mockMakerInlineEnabled
3531
import java.io.IOException
3632
import java.math.BigInteger
3733

0 commit comments

Comments
 (0)