Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/mockito#2602-makeSureConstructorInjec…
Browse files Browse the repository at this point in the history
…tionIsUsedIfValidConstructorExists
  • Loading branch information
1-alex98 committed Feb 21, 2023
2 parents 04bda90 + 4eb275c commit e54d95e
Show file tree
Hide file tree
Showing 233 changed files with 5,676 additions and 1,745 deletions.
6 changes: 3 additions & 3 deletions .github/CONTRIBUTING.md
Expand Up @@ -6,9 +6,9 @@

**If looking for support**

* Search / Ask a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/mockito)
* Search / Ask a question on [Stack Overflow / Questions tagged [mockito]](https://stackoverflow.com/questions/tagged/mockito)
* Go to the [mockito mailing-list](https://groups.google.com/group/mockito) (moderated)
* Issues should always have a [Short, Self Contained, Correct (Compilable), Example](http://sscce.org) (same as any question on stackoverflow.com)
* Issues should always have a [Short, Self Contained, Correct (Compilable), Example](http://sscce.org) (same as any question on [Stack Overflow](https://stackoverflow.com))

# Contributing to Mockito

Expand Down Expand Up @@ -54,7 +54,7 @@ Things we pay attention in a PR :
* In the code, always test your feature / change, in unit tests and in our `acceptance test suite` located in `org.mockitousage`. Older tests will be migrated when a test is modified.
* New test methods should follow a snake case convention (`ensure_that_stuff_is_doing_that`), this allows the test name to be fully expressive on intent while still readable.
* When reporting errors to the users, if it's a user report report it gently and explain how a user should deal with it, see the `Reporter` class. However not all errors should go there, some unlikely technical errors don't need to be in the `Reporter` class.
* Documentation !!! Always document with love the public API. Internals could use some love too. In all cases the code should _auto-document_ itself like any [well designed API](rebased and squashed if necessary, so that each commit clearly changes one things and there are no extraneous fix-ups).
* Documentation !!! Always document with love the public API. Internals could use some love too. In all cases the code should _auto-document_ itself like any well-designed API.
* We use (4) spaces instead of tabs. Make sure line ending is Unix style (LF). More on line ending on the [Github help](https://help.github.com/articles/dealing-with-line-endings/).


Expand Down
117 changes: 104 additions & 13 deletions .github/workflows/ci.yml
Expand Up @@ -14,6 +14,9 @@ on:
pull_request:
branches: ['**']

permissions:
contents: read

jobs:

#
Expand All @@ -26,8 +29,13 @@ jobs:
# Definition of the build matrix
strategy:
matrix:
java: [8, 11, 17]
mock-maker: ['mock-maker-default', 'mock-maker-inline']
java: [11, 17]
entry:
- { mock-maker: 'mock-maker-default', member-accessor: 'member-accessor-default' }
- { mock-maker: 'mock-maker-inline', member-accessor: 'member-accessor-module' }
- { mock-maker: 'mock-maker-subclass', member-accessor: 'member-accessor-module' }
- { mock-maker: 'mock-maker-subclass', member-accessor: 'member-accessor-reflection' }
- { mock-maker: 'mock-maker-inline', member-accessor: 'member-accessor-reflection' }

# All build steps
# SINGLE-MATRIX-JOB means that the step does not need to be executed on every job in the matrix
Expand All @@ -39,27 +47,28 @@ jobs:
fetch-depth: '0' # https://github.com/shipkit/shipkit-changelog#fetch-depth-on-ci

- name: 2. Set up Java ${{ matrix.java }}
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: ${{ matrix.java }}

- name: 3. Validate Gradle wrapper
if: matrix.java == 8 && matrix.mock-maker == 'mock-maker-default' # SINGLE-MATRIX-JOB
uses: gradle/wrapper-validation-action@v1.0.4 # https://github.com/gradle/wrapper-validation-action
if: matrix.java == 11 && matrix.entry.mock-maker == 'mock-maker-default' # SINGLE-MATRIX-JOB
uses: gradle/wrapper-validation-action@v1.0.6 # https://github.com/gradle/wrapper-validation-action

- name: 4. Build and check reproducibility of artifacts (single job only)
if: matrix.java == 8 && matrix.mock-maker == 'mock-maker-default' # SINGLE-MATRIX-JOB
if: matrix.java == 11 && matrix.entry.mock-maker == 'mock-maker-default' # SINGLE-MATRIX-JOB
run: ./check_reproducibility.sh

- name: 5. Spotless check (single job only). Run './gradlew spotlessApply' locally if this job fails.
if: matrix.java == 11 && matrix.mock-maker == 'mock-maker-default' # SINGLE-MATRIX-JOB
if: matrix.java == 11 && matrix.entry.mock-maker == 'mock-maker-default' # SINGLE-MATRIX-JOB
run: ./gradlew spotlessCheck

- name: 6. Build on Java ${{ matrix.java }} with ${{ matrix.mock-maker }}
- name: 6. Build on Java ${{ matrix.java }} with ${{ matrix.entry.mock-maker }} and ${{ matrix.entry.member-accessor }}
run: ./gradlew build idea --scan
env:
MOCK_MAKER: ${{ matrix.mock-maker }}
MOCK_MAKER: ${{ matrix.entry.mock-maker }}
MEMBER_ACCESSOR: ${{ matrix.entry.member-accessor }}

- name: 7. Upload coverage report
run: |
Expand All @@ -76,11 +85,93 @@ jobs:
chmod +x codecov
./codecov
#
# Android build job
#
android:
runs-on: macos-latest
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
timeout-minutes: 30

# Definition of the build matrix
strategy:
matrix:
# Minimum supported and maximum available.
android-api: [ 26, 33 ]

# All build steps
steps:
- name: 1. Check out code
uses: actions/checkout@v3
with:
fetch-depth: '0' # https://github.com/shipkit/shipkit-changelog#fetch-depth-on-ci

- name: 2. Set up Java 11
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11

- name: 3. Run Android tests on Android API level ${{ matrix.android-api }}
uses: reactivecircus/android-emulator-runner@v2
with:
arch: x86_64
api-level: ${{ matrix.android-api }}
# Workaround for https://issuetracker.google.com/issues/267458959
target: ${{ matrix.android-api >= 32 && 'google_apis' || 'default' }}
# Workaround for https://github.com/ReactiveCircus/android-emulator-runner/issues/160, but newer version.
emulator-build: 9322596 # 31.3.14.0 got it via `emulator -version`
# Override default "-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim"
# See emulator manual for reference: https://developer.android.com/studio/run/emulator-commandline
emulator-options: >
-no-window
-gpu swiftshader_indirect
-no-snapshot
-noaudio
-no-boot-anim
-camera-back none
-camera-front none
# See logcat manual for reference: https://developer.android.com/studio/command-line/logcat
script: |
# Capture logcat output from "Launch Emulator" to a file.
adb logcat -d > emulator-startup.log
# Shorten the logcat output, by truncating at this point, the relevant part is yet to come.
# Best effort, could fail with "failed to clear the 'main' log",
# because something is locking logcat, so try a few times, and ignore errors each time.
adb logcat --clear || true
adb logcat --clear || true
adb logcat --clear || true
# Capture full logcat output to a file.
adb logcat > emulator.log & echo $! > logcat_file.pid
# Output instrumentation test logs to the GitHub Actions output.
adb logcat "*:S MonitoringInstr:V AndroidJUnitRunner:V TestRequestBuilder:V TestExecutor:V TestRunner:V" --format=color & echo $! > logcat_console.pid
echo 0 > gradle.exit # Set a default exit code.
# Run the actual tests (suppress build failures by saving the exit code).
./gradlew :androidTest:connectedCheck --no-daemon --no-build-cache || echo $? > gradle.exit
# Stop capturing logcat output.
kill $(cat logcat_file.pid) || echo "::warning file=.github/workflows/ci.yml::Logcat process $(cat logcat_file.pid) didn't exist."
kill $(cat logcat_console.pid) || echo "::warning file=.github/workflows/ci.yml::Logcat process $(cat logcat_console.pid) didn't exist."
# Make sure the step fails if the tests failed.
exit $(cat gradle.exit)
- name: 4. Upload artifact "androidTest-results-${{ matrix.android-api }}"
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: androidTest-results-${{ matrix.android-api }}
path: |
${{ github.workspace }}/subprojects/androidTest/build/reports/androidTests/connected/**
${{ github.workspace }}/emulator.log
${{ github.workspace }}/emulator-startup.log
#
# Release job, only for pushes to the main development branch
#
release:
permissions:
contents: write
runs-on: ubuntu-latest
needs: [build] # build job must pass before we can release

Expand All @@ -96,11 +187,11 @@ jobs:
with:
fetch-depth: '0' # https://github.com/shipkit/shipkit-changelog#fetch-depth-on-ci

- name: Set up Java 8
uses: actions/setup-java@v2
- name: Set up Java 11
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: 8
distribution: 'zulu'
java-version: 11

- name: Build and release
run: ./gradlew githubRelease publishToSonatype closeAndReleaseStagingRepository releaseSummary
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -15,6 +15,9 @@
.settings/
bin/

# VSCode
.vscode/

# Gradle & builds
build
build-cache
Expand All @@ -26,4 +29,4 @@ classes
*.log

# Used to check reproducibility of Mockito jars
checksums/
checksums/
12 changes: 7 additions & 5 deletions README.md
Expand Up @@ -10,19 +10,21 @@ Most popular mocking framework for Java
[![Coverage Status](https://img.shields.io/codecov/c/github/mockito/mockito.svg)](https://codecov.io/github/mockito/mockito)
[![MIT License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/mockito/mockito/blob/main/LICENSE)

[![Release Notes](https://img.shields.io/badge/release%20notes-3.x-yellow.svg)](https://github.com/mockito/mockito/releases/)
[![Release Notes](https://img.shields.io/badge/release%20notes-5.x-yellow.svg)](https://github.com/mockito/mockito/releases/)
[![Maven Central](https://img.shields.io/maven-central/v/org.mockito/mockito-core.svg)](https://search.maven.org/artifact/org.mockito/mockito-core/)
[![Javadoc](https://www.javadoc.io/badge/org.mockito/mockito-core.svg)](https://www.javadoc.io/doc/org.mockito/mockito-core)


## Current version is 4.x
Still on Mockito 1.x? See [what's new](https://github.com/mockito/mockito/wiki/What%27s-new-in-Mockito-2) in Mockito 2! [Mockito 3](https://github.com/mockito/mockito/releases/tag/v3.0.0) does not introduce any breaking API changes, but now requires Java 8 over Java 6 for Mockito 2.
## Current version is 5.x
Still on Mockito 1.x? See [what's new](https://github.com/mockito/mockito/wiki/What%27s-new-in-Mockito-2) in Mockito 2!
[Mockito 3](https://github.com/mockito/mockito/releases/tag/v3.0.0) does not introduce any breaking API changes, but now requires Java 8 over Java 6 for Mockito 2.
[Mockito 4](https://github.com/mockito/mockito/releases/tag/v4.0.0) removes deprecated API.
[Mockito 5](https://github.com/mockito/mockito/releases/tag/v5.0.0) switches the default mockmaker to mockito-inline, and now requires Java 11.


## Mockito for enterprise

Available as part of the Tidelift Subscription
Available as part of the [Tidelift](https://tidelift.com/subscription/pkg/maven-org-mockito-mockito-core) Subscription.

The maintainers of org.mockito:mockito-core and thousands of other packages are working with Tidelift to deliver
commercial support and maintenance for the open source dependencies you use to build your applications. Save time,
Expand Down Expand Up @@ -73,7 +75,7 @@ Then, _open_ the generated *.ipr file in IDEA.

## How to release new version?

1. Every change on the main development branch is released as -SNAPSHOT version to Sonatype snapshot repo
1. Every change on the main development branch is released as `-SNAPSHOT` version to Sonatype snapshot repo
at https://s01.oss.sonatype.org/content/repositories/snapshots/org/mockito/mockito-core.
2. In order to release a non-snapshot version to Maven Central push an annotated tag, for example:

Expand Down
40 changes: 25 additions & 15 deletions build.gradle
Expand Up @@ -7,24 +7,24 @@ buildscript {

dependencies {
classpath 'gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:0.16.1'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:2.0.2'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:3.0.1'

classpath "io.github.gradle-nexus:publish-plugin:1.1.0"
classpath 'org.shipkit:shipkit-changelog:1.1.15'
classpath 'org.shipkit:shipkit-auto-version:1.1.20'
classpath 'org.shipkit:shipkit-changelog:1.2.0'
classpath 'org.shipkit:shipkit-auto-version:1.2.2'

classpath 'com.google.googlejavaformat:google-java-format:1.15.0'
classpath 'com.android.tools.build:gradle:4.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10"
}
}

plugins {
id 'com.diffplug.spotless' version '6.3.0'
id 'com.diffplug.spotless' version '6.15.0'
id 'eclipse'
id 'com.github.ben-manes.versions' version '0.42.0'
id 'biz.aQute.bnd.builder' version '6.2.0'
id 'ru.vyarus.animalsniffer' version '1.5.2'
id 'com.github.ben-manes.versions' version '0.46.0'
id 'biz.aQute.bnd.builder' version '6.4.0'
id 'ru.vyarus.animalsniffer' version '1.7.0'
}

description = 'Mockito mock objects library core API and implementation'
Expand Down Expand Up @@ -64,12 +64,14 @@ allprojects { proj ->
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charSet', 'UTF-8')
options.setSource('8')
options.setSource('11')
}

tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
dirMode = Integer.parseInt("0755", 8)
fileMode = Integer.parseInt("0644", 8)
}

apply plugin: 'checkstyle'
Expand All @@ -80,6 +82,9 @@ allprojects { proj ->

configurations {
testUtil //TODO move to separate project
// Putting 'provided' dependencies on test compile and runtime classpath.
testCompileOnly.extendsFrom(compileOnly)
testRuntimeOnly.extendsFrom(compileOnly)
}

dependencies {
Expand All @@ -90,19 +95,24 @@ dependencies {

testImplementation libraries.assertj

//putting 'provided' dependencies on test compile and runtime classpath
testCompileOnly configurations.compileOnly
testRuntimeOnly configurations.compileOnly

testUtil sourceSets.test.output

signature 'org.codehaus.mojo.signature:java18:1.0@signature'
signature 'net.sf.androidscents.signature:android-api-level-24:7.0_r2@signature'
signature 'net.sf.androidscents.signature:android-api-level-26:8.0.0_r2@signature'
}

animalsniffer {
sourceSets = [sourceSets.main]
annotation = 'org.mockito.internal.SuppressSignatureCheck'
// See please https://github.com/mojohaus/animal-sniffer/issues/172
ignore += [
'java.lang.instrument.Instrumentation',
'java.lang.invoke.MethodHandle',
'java.lang.invoke.MethodHandles$Lookup',
'java.lang.StackWalker',
'java.lang.StackWalker$StackFrame',
'java.lang.StackWalker$Option'
]
}

spotless {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Expand Up @@ -4,6 +4,7 @@ org.gradle.caching=true
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 \
-XX:+IgnoreUnrecognizedVMOptions \
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
Expand Down
29 changes: 13 additions & 16 deletions gradle/dependencies.gradle
Expand Up @@ -4,16 +4,16 @@ ext {

def versions = [:]

versions.bytebuddy = '1.12.8'
versions.junitJupiter = '5.8.2'
versions.errorprone = '2.10.0'
versions.bytebuddy = '1.14.0'
versions.junitJupiter = '5.9.2'
versions.errorprone = '2.18.0'

libraries.junit4 = 'junit:junit:4.13.2'
libraries.junitJupiterApi = "org.junit.jupiter:junit-jupiter-api:${versions.junitJupiter}"
libraries.junitPlatformLauncher = 'org.junit.platform:junit-platform-launcher:1.8.2'
libraries.junitPlatformLauncher = 'org.junit.platform:junit-platform-launcher:1.9.2'
libraries.junitJupiterEngine = "org.junit.jupiter:junit-jupiter-engine:${versions.junitJupiter}"
libraries.junitVintageEngine = "org.junit.vintage:junit-vintage-engine:${versions.junitJupiter}"
libraries.assertj = 'org.assertj:assertj-core:3.22.0'
libraries.assertj = 'org.assertj:assertj-core:3.24.2'
libraries.hamcrest = 'org.hamcrest:hamcrest-core:2.2'
libraries.opentest4j = 'org.opentest4j:opentest4j:1.2.0'

Expand All @@ -26,26 +26,23 @@ libraries.errorproneTestApi = "com.google.errorprone:error_prone_test_helpers:${

libraries.autoservice = "com.google.auto.service:auto-service:1.0.1"

libraries.objenesis = 'org.objenesis:objenesis:3.2'
libraries.objenesis = 'org.objenesis:objenesis:3.3'

libraries.osgi = 'org.osgi:osgi.core:8.0.0'
libraries.equinox = 'org.eclipse.platform:org.eclipse.osgi:3.17.200'
libraries.bndGradle = 'biz.aQute.bnd:biz.aQute.bnd.gradle:6.2.0'
libraries.equinox = 'org.eclipse.platform:org.eclipse.osgi:3.18.200'
libraries.bndGradle = 'biz.aQute.bnd:biz.aQute.bnd.gradle:6.4.0'

libraries.groovy = 'org.codehaus.groovy:groovy:3.0.10'
libraries.groovy = 'org.codehaus.groovy:groovy:3.0.15'

def kotlinVersion = '1.6.10'
def kotlinVersion = '1.8.10'
libraries.kotlin = [
version: kotlinVersion,

stdlib: "org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}",
coroutines: 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-native-mt',
coroutines: 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.3-native-mt',
gradlePlugin: "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}",
]
libraries.android = [
ktx: 'androidx.core:core-ktx:1.7.0',
compat: 'androidx.appcompat:appcompat:1.4.1',
material: 'com.google.android.material:material:1.5.0',
junit: 'androidx.test.ext:junit:1.1.3',
espresso: 'androidx.test.espresso:espresso-core:3.4.0',
runner: 'androidx.test:runner:1.5.2',
junit: 'androidx.test.ext:junit:1.1.5',
]

0 comments on commit e54d95e

Please sign in to comment.