Skip to content

Commit ab1eb0d

Browse files
committed
Use same test source for inline tests
1 parent 2b31ed7 commit ab1eb0d

File tree

16 files changed

+82
-52
lines changed

16 files changed

+82
-52
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ language: java
55
jdk:
66
- oraclejdk7
77

8+
matrix:
9+
include:
10+
- jdk: oraclejdk7
11+
env: TERM=dumb MOCK_MAKER=mock-maker-inline
12+
813
env:
914
matrix:
1015
- TERM=dumb

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ plugins {
33
}
44

55
apply from: 'gradle/scripts/tagging.gradle'
6+
7+
println ext.versionName

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@
2424
#
2525

2626
isRelease = false
27+
publishToLocal = false

mockito-kotlin/build.gradle

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,6 @@ repositories {
2121
jcenter()
2222
}
2323

24-
sourceSets {
25-
testInlineMockito {
26-
compileClasspath += main.output + test.output
27-
runtimeClasspath += main.output + test.output
28-
}
29-
}
30-
31-
configurations {
32-
testInlineMockitoCompile.extendsFrom testCompile
33-
testInlineMockitoRuntime.extendsFrom testRuntime
34-
}
35-
36-
// define custom test task for running integration tests
37-
task testInlineMockito(type: Test) {
38-
testClassesDir = sourceSets.testInlineMockito.output.classesDir
39-
classpath = sourceSets.testInlineMockito.runtimeClasspath
40-
}
41-
42-
test.dependsOn testInlineMockito
43-
44-
4524
dependencies {
4625
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
4726
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
@@ -63,3 +42,26 @@ dokka {
6342
}
6443
}
6544
javadoc.dependsOn dokka
45+
46+
//Switch inline
47+
task createTestResources << {
48+
def mockMakerFile = new File("$projectDir/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker")
49+
if (System.env.MOCK_MAKER != null) {
50+
logger.warn("! Using MockMaker ${System.env.MOCK_MAKER}")
51+
mockMakerFile.parentFile.mkdirs()
52+
mockMakerFile.createNewFile()
53+
mockMakerFile.write(System.env.MOCK_MAKER)
54+
} else {
55+
logger.warn("! Using default MockMaker")
56+
}
57+
}
58+
59+
task removeTestResources << {
60+
def mockMakerFile = new File("$projectDir/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker")
61+
if (mockMakerFile.exists()) {
62+
mockMakerFile.delete()
63+
}
64+
}
65+
66+
test.dependsOn createTestResources
67+
test.finalizedBy removeTestResources

mockito-kotlin/publishing.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ uploadArchives {
4040
)
4141
}
4242

43+
if (publishToLocal) repository(url: mavenLocal().url)
44+
4345
pom.project {
4446
name 'Mockito-Kotlin'
4547
packaging 'jar'

mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/CreateInstance.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ import java.lang.reflect.Array as JavaArray
4848
/**
4949
* Checks whether the resource file to enable mocking of final classes is present.
5050
*/
51-
private var mockMakerInlineEnabled: Boolean? = null
51+
internal var mockMakerInlineEnabled: Boolean? = null
5252

53-
private fun mockMakerInlineEnabled(jClass: Class<out Any>): Boolean {
53+
internal fun mockMakerInlineEnabled(jClass: Class<out Any>): Boolean {
5454
return mockMakerInlineEnabled ?:
5555
jClass.getResource("mockito-extensions/org.mockito.plugins.MockMaker")?.let {
5656
mockMakerInlineEnabled = File(it.file).readLines().filter { it == "mock-maker-inline" }.isNotEmpty()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import com.nhaarman.mockito_kotlin.*
33
import org.junit.Test
44
import java.util.*
55

6-
class ArgumentCaptorTest {
6+
class ArgumentCaptorTest : BaseTest() {
77

88
@Test
99
fun argumentCaptor_withSingleValue() {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import com.nhaarman.mockito_kotlin.mockMakerInlineEnabled
2+
import org.junit.After
3+
import org.junit.Before
4+
5+
abstract class BaseTest {
6+
7+
@Before
8+
open fun setup() {
9+
mockMakerInlineEnabled = false
10+
}
11+
12+
@After
13+
open fun tearDown() {
14+
mockMakerInlineEnabled = null
15+
}
16+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import org.junit.Test
3131
import java.util.*
3232
import kotlin.reflect.KClass
3333

34-
class CreateInstanceTest {
34+
class CreateInstanceTest : BaseTest() {
3535

3636
@Test
3737
fun byte() {
@@ -555,8 +555,8 @@ class CreateInstanceTest {
555555
}
556556

557557
enum class MyEnum { VALUE, ANOTHER_VALUE }
558+
}
558559

559-
sealed class MySealedClass {
560-
class MySealedClassMember : MySealedClass()
561-
}
560+
sealed class MySealedClass {
561+
class MySealedClassMember : MySealedClass()
562562
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import org.junit.Before
3131
import org.junit.Test
3232
import org.mockito.Mockito
3333

34-
class EqTest {
34+
class EqTest : BaseTest() {
3535

3636
private val interfaceInstance: MyInterface = MyClass()
3737
private val openClassInstance: MyClass = MyClass()
@@ -40,13 +40,17 @@ class EqTest {
4040
private lateinit var doAnswer: Open
4141

4242
@Before
43-
fun setup() {
43+
override fun setup() {
44+
super.setup()
45+
4446
/* Create a proper Mockito state */
4547
doAnswer = Mockito.doAnswer { }.`when`(mock())
4648
}
4749

4850
@After
49-
fun tearDown() {
51+
override fun tearDown() {
52+
super.tearDown()
53+
5054
/* Close `any` Mockito state */
5155
doAnswer.go(0)
5256
}

0 commit comments

Comments
 (0)