Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.1.2 #2

Merged
merged 5 commits into from
Jan 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,15 @@ install:
- true

script:
- ./gradlew test
- ./gradlew test

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -f $HOME/.gradle/caches/2.10/plugin-resolution/cache.properties.lock
- rm -f $HOME/.gradle/caches/2.10/plugin-resolution/cache.properties
cache:
directories:
- $HOME/.gradle/caches
- $HOME/.gradle/daemon
- $HOME/.gradle/native
- $HOME/.gradle/wrapper
2 changes: 1 addition & 1 deletion mockito-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bintray {
name = "Mockito-Kotlin"
desc = "Using Mockito with Kotlin"

licenses = ['Apache-2.0']
licenses = ['MIT']
vcsUrl = 'https://github.com/bintray/gradle-bintray-plugin.git'

version {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package com.nhaarman.mockito_kotlin

import org.mockito.Mockito
import org.mockito.verification.VerificationMode
import kotlin.reflect.KClass

inline fun <reified T : Any> mock() = Mockito.mock(T::class.java)
fun <T : Any> spy(value: T) = Mockito.spy(value)
Expand All @@ -40,6 +41,7 @@ fun <T> reset(mock: T) = Mockito.reset(mock)
fun inOrder(vararg value: Any) = Mockito.inOrder(*value)
fun never() = Mockito.never()

fun <T> eq(value: T) = Mockito.eq(value)
inline fun <reified T : Any> eq(value: T) = eq(value, T::class)
fun <T : Any> eq(value: T, kClass: KClass<T>) = Mockito.eq(value) ?: createInstance(kClass)

inline fun <reified T : Any> isNull(): T? = Mockito.isNull(T::class.java)
21 changes: 0 additions & 21 deletions mockito-kotlin/src/test/kotlin/AnyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,6 @@ import org.junit.Before
import org.junit.Test
import org.mockito.Mockito

/*
* Copyright 2016 Niek Haarman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

class AnyTest {

private lateinit var doAnswer: Fake
Expand Down Expand Up @@ -385,11 +369,6 @@ class AnyTest {
expect(result).toBe(MyEnum.VALUE)
}

open class Fake {
open fun go(arg: Any?) {
}
}

class ClosedClass
class ClosedParameterizedClass(val fake: Fake)
class ClosedClosedParameterizedClass(val closed: ClosedParameterizedClass)
Expand Down
85 changes: 85 additions & 0 deletions mockito-kotlin/src/test/kotlin/EqTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* The MIT License
*
* Copyright (c) 2016 Niek Haarman
* Copyright (c) 2007 Mockito contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

import com.nhaarman.expect.expect
import com.nhaarman.mockito_kotlin.eq
import com.nhaarman.mockito_kotlin.mock
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito

class EqTest {

private val interfaceInstance: MyInterface = MyClass()
private val openClassInstance: MyClass = MyClass()
private val closedClassInstance: ClosedClass = ClosedClass()

private lateinit var doAnswer: Fake

@Before
fun setup() {
/* Create a proper Mockito state */
doAnswer = Mockito.doAnswer { }.`when`(mock())
}

@After
fun tearDown() {
/* Close `any` Mockito state */
doAnswer.go(0)
}

@Test
fun eqInterfaceInstance() {
/* When */
val result = eq(interfaceInstance)

/* Then */
expect(result).toNotBeNull()
}

@Test
fun eqOpenClassInstance() {
/* When */
val result = eq(openClassInstance)

/* Then */
expect(result).toNotBeNull()
}

@Test
fun eqClosedClassInstance() {
/* When */
val result = eq(closedClassInstance)

/* Then */
expect(result).toNotBeNull()
}

private interface MyInterface
private open class MyClass : MyInterface
class ClosedClass
}

29 changes: 29 additions & 0 deletions mockito-kotlin/src/test/kotlin/Fake.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* The MIT License
*
* Copyright (c) 2016 Niek Haarman
* Copyright (c) 2007 Mockito contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

open class Fake {
open fun go(arg: Any?) {
}
}
16 changes: 0 additions & 16 deletions mockito-kotlin/src/test/kotlin/MatcherTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@ import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.verify
import org.junit.Test

/*
* Copyright 2016 Niek Haarman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

class MatcherTest {

@Test
Expand Down
16 changes: 0 additions & 16 deletions mockito-kotlin/src/test/kotlin/MockTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@ import com.nhaarman.mockito_kotlin.mock
import org.junit.Test
import org.mockito.exceptions.base.MockitoException

/*
* Copyright 2016 Niek Haarman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

class MockTest {

private lateinit var propertyInterfaceVariable: MyInterface
Expand Down
16 changes: 0 additions & 16 deletions mockito-kotlin/src/test/kotlin/SpyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@
* THE SOFTWARE.
*/

/*
* Copyright 2016 Niek Haarman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.nhaarman.expect.expect
import com.nhaarman.mockito_kotlin.spy
import org.junit.Test
Expand Down