Skip to content

Commit 1ce3617

Browse files
authored
Reduce warnings during build, in IDE and in GitHub UI (#501)
1 parent a6719ad commit 1ce3617

26 files changed

+70
-83
lines changed

Diff for: .github/workflows/ci.yml

+32-32
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
# SINGLE-JOB
2424
#
2525
verify:
26-
runs-on: ubuntu-latest
26+
runs-on: ubuntu-latest
2727
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
2828

2929
steps:
@@ -44,7 +44,7 @@ jobs:
4444
#
4545
build:
4646
needs: [verify]
47-
runs-on: ubuntu-latest
47+
runs-on: ubuntu-latest
4848

4949
# Definition of the build matrix
5050
strategy:
@@ -56,20 +56,20 @@ jobs:
5656

5757
steps:
5858

59-
- name: 1. Check out code
60-
uses: actions/checkout@v2 # https://github.com/actions/checkout
59+
- name: 1. Check out code
60+
uses: actions/checkout@v2 # https://github.com/actions/checkout
6161

62-
- name: 2. Set up Java 11
63-
uses: actions/setup-java@v1 # https://github.com/actions/setup-java
64-
with:
65-
java-version: 11
62+
- name: 2. Set up Java 11
63+
uses: actions/setup-java@v1 # https://github.com/actions/setup-java
64+
with:
65+
java-version: 11
6666

67-
- name: 3. Build with Kotlin ${{ matrix.kotlin }} and mock-maker ${{ matrix.mock-maker }}
68-
run: |
69-
ops/mockMakerInline.sh
70-
./gradlew build -PtestKotlinVersion=${{ matrix.kotlin }}
71-
env:
72-
MOCK_MAKER: ${{ matrix.mock-maker }}
67+
- name: 3. Build with Kotlin ${{ matrix.kotlin }} and mock-maker ${{ matrix.mock-maker }}
68+
run: |
69+
ops/mockMakerInline.sh
70+
./gradlew build -PtestKotlinVersion=${{ matrix.kotlin }}
71+
env:
72+
MOCK_MAKER: ${{ matrix.mock-maker }}
7373

7474
#
7575
# Release job, only for pushes to the main development branch
@@ -85,21 +85,21 @@ jobs:
8585

8686
steps:
8787

88-
- name: Check out code
89-
uses: actions/checkout@v2 # https://github.com/actions/checkout
90-
with:
91-
fetch-depth: '0' # https://github.com/shipkit/shipkit-changelog#fetch-depth-on-ci
92-
93-
- name: Set up Java 11
94-
uses: actions/setup-java@v1
95-
with:
96-
java-version: 11
97-
98-
- name: Build and release
99-
run: ./gradlew githubRelease publishToSonatype closeAndReleaseStagingRepository releaseSummary
100-
env:
101-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
102-
NEXUS_TOKEN_USER: ${{secrets.NEXUS_TOKEN_USER}}
103-
NEXUS_TOKEN_PWD: ${{secrets.NEXUS_TOKEN_PWD}}
104-
PGP_KEY: ${{secrets.PGP_KEY}}
105-
PGP_PWD: ${{secrets.PGP_PWD}}
88+
- name: Check out code
89+
uses: actions/checkout@v2 # https://github.com/actions/checkout
90+
with:
91+
fetch-depth: '0' # https://github.com/shipkit/shipkit-changelog#fetch-depth-on-ci
92+
93+
- name: Set up Java 11
94+
uses: actions/setup-java@v1
95+
with:
96+
java-version: 11
97+
98+
- name: Build and release
99+
run: ./gradlew githubRelease publishToSonatype closeAndReleaseStagingRepository releaseSummary
100+
env:
101+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
102+
NEXUS_TOKEN_USER: ${{secrets.NEXUS_TOKEN_USER}}
103+
NEXUS_TOKEN_PWD: ${{secrets.NEXUS_TOKEN_PWD}}
104+
PGP_KEY: ${{secrets.PGP_KEY}}
105+
PGP_PWD: ${{secrets.PGP_PWD}}

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Mockito-Kotlin
2+
23
[ ![Download](https://maven-badges.herokuapp.com/maven-central/org.mockito.kotlin/mockito-kotlin/badge.svg) ](https://maven-badges.herokuapp.com/maven-central/org.mockito.kotlin/mockito-kotlin)
34
[![Nexus Snapshot](https://img.shields.io/nexus/s/org.mockito.kotlin/mockito-kotlin?server=https%3A%2F%2Fs01.oss.sonatype.org%2F)](https://s01.oss.sonatype.org/content/repositories/snapshots/org/mockito/kotlin/mockito-kotlin/)
45

@@ -56,7 +57,7 @@ keeping the base module at a recent version.
5657

5758
- `./gradlew check` runs the checks including tests.
5859

59-
Usually it is enough to test only using the default Kotlin versions;
60+
Usually it is enough to test only using the default Kotlin versions;
6061
CI will test against multiple versions.
6162
If you want to test using a different Kotlin version locally,
6263
add the `-PtestKotlinVersion=1.2.3` argument to the Gradle invocation while running the tests.

Diff for: mockito-kotlin/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ dependencies {
2222
testImplementation 'junit:junit:4.13.2'
2323
testImplementation 'com.nhaarman:expect.kt:1.0.1'
2424

25-
testImplementation "org.jetbrains.kotlin:kotlin-stdlib"
26-
testImplementation "org.jetbrains.kotlin:kotlin-test"
25+
testImplementation "org.jetbrains.kotlin:kotlin-stdlib"
26+
testImplementation "org.jetbrains.kotlin:kotlin-test"
2727
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0'
2828

2929
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0"

Diff for: mockito-kotlin/src/main/kotlin/org/mockito/kotlin/ArgumentCaptor.kt

-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ class ArgumentCaptorHolder5<out A, out B, out C, out D, out E>(
9393
operator fun component5() = fifth
9494
}
9595

96-
9796
/**
9897
* Creates 4 [KArgumentCaptor]s for given types.
9998
*/

Diff for: mockito-kotlin/src/main/kotlin/org/mockito/kotlin/KInOrder.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ package org.mockito.kotlin
2828
import org.mockito.InOrder
2929
import org.mockito.verification.VerificationMode
3030

31-
interface KInOrder: InOrder {
31+
interface KInOrder : InOrder {
3232
/**
3333
* Verifies certain suspending behavior <b>happened once</b> in order.
3434
*

Diff for: mockito-kotlin/src/main/kotlin/org/mockito/kotlin/KStubbing.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import org.mockito.stubbing.OngoingStubbing
3333
import org.mockito.stubbing.Stubber
3434
import kotlin.reflect.KClass
3535

36-
3736
inline fun <T : Any> stubbing(
3837
mock: T,
3938
stubbing: KStubbing<T>.(T) -> Unit
@@ -47,7 +46,7 @@ inline fun <T : Any> T.stub(stubbing: KStubbing<T>.(T) -> Unit): T {
4746

4847
class KStubbing<out T : Any>(val mock: T) {
4948
init {
50-
if(!mockingDetails(mock).isMock) throw NotAMockException("Stubbing target is not a mock!")
49+
if (!mockingDetails(mock).isMock) throw NotAMockException("Stubbing target is not a mock!")
5150
}
5251

5352
fun <R> on(methodCall: R): OngoingStubbing<R> = Mockito.`when`(methodCall)
@@ -90,4 +89,4 @@ class KStubbing<out T : Any>(val mock: T) {
9089
fun Stubber.on(methodCall: T.() -> Unit) {
9190
this.`when`(mock).methodCall()
9291
}
93-
}
92+
}

Diff for: mockito-kotlin/src/main/kotlin/org/mockito/kotlin/Matchers.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ inline fun <reified T : Any> anyVararg(): T {
5656
}
5757

5858
fun <T : Any> anyVararg(clazz: KClass<T>): T {
59-
return ArgumentMatchers.argThat(VarargMatcher(clazz.java))?: createInstance(clazz)
59+
return ArgumentMatchers.argThat(VarargMatcher(clazz.java)) ?: createInstance(clazz)
6060
}
6161

62-
private class VarargMatcher<T>(private val clazz: Class<T>) : ArgumentMatcher<T>{
62+
private class VarargMatcher<T>(private val clazz: Class<T>) : ArgumentMatcher<T> {
6363
override fun matches(t: T): Boolean = true
6464

6565
// In Java >= 12 you can do clazz.arrayClass()
@@ -148,4 +148,3 @@ fun <T : Any> notNull(): T? {
148148
inline fun <reified T : Any> refEq(value: T, vararg excludeFields: String): T {
149149
return ArgumentMatchers.refEq<T>(value, *excludeFields) ?: createInstance()
150150
}
151-

Diff for: mockito-kotlin/src/main/kotlin/org/mockito/kotlin/Mocking.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.mockito.MockSettings
3030
import org.mockito.Mockito
3131
import org.mockito.listeners.InvocationListener
3232
import org.mockito.mock.SerializableMode
33+
import org.mockito.quality.Strictness
3334
import org.mockito.stubbing.Answer
3435
import kotlin.DeprecationLevel.ERROR
3536
import kotlin.reflect.KClass
@@ -175,7 +176,7 @@ fun withSettings(
175176
if (stubOnly) stubOnly()
176177
useConstructor?.let { useConstructor(*it.args) }
177178
outerInstance?.let { outerInstance(it) }
178-
if (lenient) lenient()
179+
if (lenient) strictness(Strictness.LENIENT)
179180
}
180181

181182
class UseConstructor private constructor(val args: Array<Any>) {

Diff for: mockito-kotlin/src/main/kotlin/org/mockito/kotlin/Mockito.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ fun <T> reset(vararg mocks: T) {
3838

3939
fun mockingDetails(toInspect: Any): MockingDetails {
4040
return Mockito.mockingDetails(toInspect)!!
41-
}
41+
}

Diff for: mockito-kotlin/src/main/kotlin/org/mockito/kotlin/OngoingStubbing.kt

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import org.mockito.stubbing.Answer
3434
import org.mockito.stubbing.OngoingStubbing
3535
import kotlin.reflect.KClass
3636

37-
3837
/**
3938
* Enables stubbing methods. Use it when you want the mock to return particular value when particular method is called.
4039
*

Diff for: mockito-kotlin/src/main/kotlin/org/mockito/kotlin/Spying.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ package org.mockito.kotlin
2727

2828
import org.mockito.Mockito
2929

30-
3130
/**
3231
* Creates a spy of the real object.
3332
* The spy calls <b>real</b> methods unless they are stubbed.
@@ -58,5 +57,5 @@ fun <T> spy(value: T): T {
5857
*/
5958
inline fun <reified T : Any> spy(value: T, stubbing: KStubbing<T>.(T) -> Unit): T {
6059
return spy(value)
61-
.apply { KStubbing(this).stubbing(this) }!!
62-
}
60+
.apply { KStubbing(this).stubbing(this) }
61+
}

Diff for: mockito-kotlin/src/main/kotlin/org/mockito/kotlin/Stubber.kt

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import org.mockito.invocation.InvocationOnMock
3131
import org.mockito.stubbing.Stubber
3232
import kotlin.reflect.KClass
3333

34-
3534
fun <T> doAnswer(answer: (InvocationOnMock) -> T?): Stubber {
3635
return Mockito.doAnswer { answer(it) }!!
3736
}

Diff for: mockito-kotlin/src/main/kotlin/org/mockito/kotlin/Verification.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ package org.mockito.kotlin
2727

2828
import org.mockito.kotlin.internal.createInstance
2929
import kotlinx.coroutines.runBlocking
30-
import org.mockito.InOrder
3130
import org.mockito.Mockito
3231
import org.mockito.kotlin.internal.KInOrderDecorator
3332
import org.mockito.verification.VerificationAfterDelay
@@ -64,6 +63,7 @@ fun <T> verifyBlocking(mock: T, mode: VerificationMode, f: suspend T.() -> Unit)
6463
val m = Mockito.verify(mock, mode)
6564
runBlocking { m.f() }
6665
}
66+
6767
/**
6868
* Verifies certain behavior happened at least once / exact number of times / never.
6969
*
@@ -259,7 +259,6 @@ fun only(): VerificationMode {
259259
return Mockito.only()!!
260260
}
261261

262-
263262
/**
264263
* For usage with verification only.
265264
*
@@ -271,11 +270,12 @@ fun only(): VerificationMode {
271270
inline fun <reified T : Any> check(noinline predicate: (T) -> Unit): T {
272271
return Mockito.argThat { arg: T? ->
273272
if (arg == null) error(
274-
"""The argument passed to the predicate was null.
275-
276-
If you are trying to verify an argument to be null, use `isNull()`.
277-
If you are using `check` as part of a stubbing, use `argThat` or `argForWhich` instead.
278-
""".trimIndent()
273+
"""
274+
The argument passed to the predicate was null.
275+
276+
If you are trying to verify an argument to be null, use `isNull()`.
277+
If you are using `check` as part of a stubbing, use `argThat` or `argForWhich` instead.
278+
""".trimIndent()
279279
)
280280

281281
try {

Diff for: mockito-kotlin/src/main/kotlin/org/mockito/kotlin/VerifyScope.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
package org.mockito.kotlin
2727

28-
2928
/**
3029
* Verify multiple calls on mock
3130
* Supports an easier to read style of
@@ -45,4 +44,4 @@ class VerifyScope<out T>(val mock: T) {
4544
operator inline fun Int.times(call: T.() -> Unit) {
4645
verify(mock, org.mockito.kotlin.times(this)).call()
4746
}
48-
}
47+
}

Diff for: mockito-kotlin/src/main/kotlin/org/mockito/kotlin/internal/CreateInstance.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package org.mockito.kotlin.internal
2727

2828
import kotlin.reflect.KClass
29-
import java.lang.reflect.Array as JavaArray
3029

3130
inline fun <reified T : Any> createInstance(): T {
3231
return when (T::class) {
@@ -42,7 +41,7 @@ inline fun <reified T : Any> createInstance(): T {
4241
}
4342
}
4443

45-
fun <T : Any> createInstance(kClass: KClass<T>): T {
44+
fun <T : Any> createInstance(@Suppress("UNUSED_PARAMETER") kClass: KClass<T>): T {
4645
return castNull()
4746
}
4847

Diff for: mockito-kotlin/src/test/kotlin/test/CoroutinesTest.kt

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import org.mockito.InOrder
1616
import org.mockito.kotlin.*
1717
import java.util.*
1818

19-
2019
class CoroutinesTest {
2120

2221
@Test

Diff for: tests/src/test/kotlin/test/LenientStubberTest.kt

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import org.mockito.kotlin.mock
1212
import org.mockito.kotlin.whenever
1313
import org.mockito.quality.Strictness
1414

15-
1615
open class LenientStubberTest {
1716
@get:Rule
1817
val rule: MockitoRule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS)

Diff for: tests/src/test/kotlin/test/MatchersTest.kt

+9-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import org.mockito.invocation.InvocationOnMock
88
import org.mockito.kotlin.*
99
import org.mockito.stubbing.Answer
1010
import java.io.IOException
11-
import kotlin.reflect.KClass
1211

1312
class MatchersTest : TestBase() {
1413

@@ -99,6 +98,7 @@ class MatchersTest : TestBase() {
9998
verify(this).boolean(anyOrNull())
10099
}
101100
}
101+
102102
@Test
103103
fun anyNull_forPrimitiveByte() {
104104
mock<Methods>().apply {
@@ -238,7 +238,6 @@ class MatchersTest : TestBase() {
238238
}
239239
}
240240

241-
242241
@Test
243242
fun isA_withNonNullableString() {
244243
mock<Methods>().apply {
@@ -310,14 +309,14 @@ class MatchersTest : TestBase() {
310309
/** https://github.com/nhaarman/mockito-kotlin/issues/328 */
311310
@Test
312311
fun testRefEqForNonNullableParameter() {
313-
mock<Methods>().apply {
314-
/* When */
315-
val array = intArrayOf(2, 3)
316-
intArray(array)
317-
318-
/* Then */
319-
verify(this).intArray(refEq(array))
320-
}
312+
mock<Methods>().apply {
313+
/* When */
314+
val array = intArrayOf(2, 3)
315+
intArray(array)
316+
317+
/* Then */
318+
verify(this).intArray(refEq(array))
319+
}
321320
}
322321

323322
/**

Diff for: tests/src/test/kotlin/test/MockMaker.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package test
33
import org.mockito.internal.configuration.plugins.Plugins
44
import org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker
55

6-
76
internal var mockMakerInlineEnabled: Boolean? = null
7+
88
internal fun mockMakerInlineEnabled(): Boolean {
99
return mockMakerInlineEnabled ?: (Plugins.getMockMaker() is InlineByteBuddyMockMaker)
1010
}

0 commit comments

Comments
 (0)