Skip to content

Commit

Permalink
Merge pull request #68 from picimako/130
Browse files Browse the repository at this point in the history
v1.3.0
  • Loading branch information
picimako authored Sep 10, 2024
2 parents 7ff45de + 00f0845 commit f7d8e7a
Show file tree
Hide file tree
Showing 249 changed files with 1,867 additions and 1,215 deletions.
74 changes: 16 additions & 58 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ on:
# Trigger the workflow on any pull request
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:

# Prepare environment and build the plugin
Expand All @@ -32,13 +36,13 @@ jobs:
pluginVerifierHomeDir: ${{ steps.properties.outputs.pluginVerifierHomeDir }}
steps:

# Check out current repository
# Check out the current repository
- name: Fetch Sources
uses: actions/checkout@v4

# Validate wrapper
- name: Gradle Wrapper Validation
uses: gradle/wrapper-validation-action@v1.1.0
uses: gradle/actions/wrapper-validation@v3

# Set up Java environment for the next steps
- name: Setup Java
Expand All @@ -49,7 +53,7 @@ jobs:

# Setup Gradle
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
with:
gradle-home-cache-cleanup: true

Expand All @@ -69,8 +73,6 @@ jobs:
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
./gradlew listProductsReleases # prepare list of IDEs for Plugin Verifier
# Build plugin
- name: Build plugin
run: ./gradlew buildPlugin
Expand All @@ -88,7 +90,7 @@ jobs:
# Store already-built plugin as an artifact for downloading
- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ steps.artifact.outputs.filename }}
path: ./build/distributions/content/*/*
Expand All @@ -100,7 +102,7 @@ jobs:
runs-on: ubuntu-latest
steps:

# Check out current repository
# Check out the current repository
- name: Fetch Sources
uses: actions/checkout@v4

Expand All @@ -113,7 +115,7 @@ jobs:

# Setup Gradle
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
with:
gradle-home-cache-cleanup: true

Expand All @@ -124,7 +126,7 @@ jobs:
# Collect Tests Result of failed tests
- name: Collect Tests Result
if: ${{ failure() }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: tests-result
path: ${{ github.workspace }}/build/reports/tests
Expand All @@ -143,7 +145,7 @@ jobs:
tool-cache: false
large-packages: false

# Check out current repository
# Check out the current repository
- name: Fetch Sources
uses: actions/checkout@v4

Expand All @@ -156,69 +158,25 @@ jobs:

# Setup Gradle
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
with:
gradle-home-cache-cleanup: true

# Cache Plugin Verifier IDEs
- name: Setup Plugin Verifier IDEs Cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ needs.build.outputs.pluginVerifierHomeDir }}/ides
key: plugin-verifier-${{ hashFiles('build/listProductsReleases.txt') }}

# Run Verify Plugin task and IntelliJ Plugin Verifier tool
- name: Run Plugin Verification tasks
run: ./gradlew runPluginVerifier -Dplugin.verifier.home.dir=${{ needs.build.outputs.pluginVerifierHomeDir }}
run: ./gradlew verifyPlugin -Dplugin.verifier.home.dir=${{ needs.build.outputs.pluginVerifierHomeDir }}

# Collect Plugin Verifier Result
- name: Collect Plugin Verifier Result
if: ${{ always() }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: pluginVerifier-result
path: ${{ github.workspace }}/build/reports/pluginVerifier

# # Prepare a draft release for GitHub Releases page for the manual verification
# # If accepted and published, release workflow would be triggered
# releaseDraft:
# name: Release draft
# if: github.event_name != 'pull_request'
# needs: [ build, test, inspectCode, verify ]
# runs-on: ubuntu-latest
# permissions:
# contents: write
# steps:
#
# # Check out current repository
# - name: Fetch Sources
# uses: actions/checkout@v4
#
# # Set up Java environment for the next steps
# - name: Setup Java
# uses: actions/setup-java@v4
# with:
# distribution: zulu
# java-version: 17
#
# # Remove old release drafts by using the curl request for the available releases with a draft flag
# - name: Remove Old Release Drafts
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: |
# gh api repos/{owner}/{repo}/releases \
# --jq '.[] | select(.draft == true) | .id' \
# | xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{}
#
# # Create a new release draft which is not publicly visible and requires manual acceptance
# - name: Create Release Draft
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: |
# gh release create v${{ needs.build.outputs.version }} \
# --draft \
# --title "v${{ needs.build.outputs.version }}" \
# --notes "$(cat << 'EOM'
# ${{ needs.build.outputs.changelog }}
# EOM
# )"
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@

## [Unreleased]

## [1.3.0]
### Added
- The inspection reporting spy creation on a mock object now also recognizes passed in mock objects when they are created
either with `Mockito.mock()` or `Mockito.spy()`.
- [66](https://github.com/picimako/mockitools/issues/66): Added an inspection that can report the stubbing of private and native methods,
as well as `equals()` and `hashCode()`.
- [63](https://github.com/picimako/mockitools/issues/63): Added an inspection to report `ArgumentCaptor.captor()` calls when they are passed in at least one argument.
This method is not designed to accept any argument.
- [55](https://github.com/picimako/mockitools/issues/55): Added an inspection to report explicit initialization of `@Mock` and `@InjectMocks` annotated fields.
- Added support for generic inferred `Mockito.mock()` and `Mockito.spy()` calls when converting from those calls to `@Mock` and `@Spy` fields, respectively.

### Changed
- Applied a couple of code simplifications for easier maintenance.
- Improved the documentation, in many cases by replacing textual code examples with screenshots and gifs.

### Fixed
- Fixed the title of the list popup when selecting the target stubbing during conversion.
- Fixed a threading related exception that occurred during converting `@Mock` or `@Spy` fields to their corresponding method call versions.
- Fixed some potential `ArrayIndexOutOfBoundsException`s.

## [1.2.0]
### Changed
- New support range of IDEs: 2023.3-2024.2-EAP.
Expand Down
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ changelog {
}

dependencies {
testImplementation("org.assertj:assertj-core:3.26.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.0")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.0")
testImplementation("org.assertj:assertj-core:3.26.3")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.11.0")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.11.0")
}

tasks {
Expand Down
14 changes: 14 additions & 0 deletions docs/argument_matching_capture.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* [Inconsistent argument matcher usage](#inconsistent-argument-matcher-usage)
* [Explicit initialization of @Captor field is not required](#explicit-initialization-of-captor-field-is-not-required)
* [@Captor field must be of the type ArgumentCaptor](#captor-field-must-be-of-the-type-argumentcaptor)
* [Generic inferred ArgumentCaptor creation](#generic-inferred-argumentcaptor-creation)
<!-- TOC -->

## Inconsistent argument matcher usage
Expand Down Expand Up @@ -98,3 +99,16 @@ List<List<String>> captor; //before
@Captor
ArgumentCaptor<List<List<String>>> captor; //after
```

----

## Generic inferred ArgumentCaptor creation

![](https://img.shields.io/badge/inspection-orange) ![](https://img.shields.io/badge/since-1.3.0-blue) [![](https://img.shields.io/badge/implementation-GenericInferredCaptorCreationInspection-blue)](../src/main/java/com/picimako/mockitools/inspection/captor/GenericInferredCaptorCreationInspection.java)

[Mockito 5.7.0](https://github.com/mockito/mockito/pull/3144) introduced the `ArgumentCaptor.captor()` method
for captor creation, so that the captor type is not determined by the class passed in at creation, instead by the type of the variable/field it is assigned to.

This method throws an exception if objects are passed in, thus this inspection reports calls to this method when it finds at least one such argument.

![generic inferred captor creation](assets/generic_inferred_captor_creation.png)
Binary file removed docs/assets/consecutive_return_calls.png
Binary file not shown.
Binary file added docs/assets/consecutive_then_return_calls.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/consecutive_then_throw_calls.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/convert_mock_field_to_variable.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/convert_mock_variable_to_field.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/convert_stubbing.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/convert_verification.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/expand_mock_creation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/extra_interfaces_no_argument.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/generic_inferred_captor_creation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/interface_extends_not_extensible.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/mockito_reset_is_called.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/non_mockable_types.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/replace_times_zero_with_never.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/simplify_mock_creation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/single_verification_in_order.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/spying_on_mock_object.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/stubbing_private_method.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/target_method_selection_list.png
Binary file added docs/assets/unconfigured_mock_in_inorder.png
Binary file added docs/assets/unused_mock_in_inorder.png
2 changes: 1 addition & 1 deletion docs/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Notes:
- There are no dedicated quick fixes, since separate intention actions are available to convert between these approaches:
- [conversion of stubbing](stubbing.md#convert-between-various-stubbing-approaches)
- [conversion of verification](verifications.md#convert-between-various-verification-approaches)
- `MockedStatic` specific InOrder.verify() methods are excluded from the enforcement, since BDDMockito has no way of verifying MockedStatic.
- `MockedStatic` specific `InOrder.verify()` methods are excluded from the enforcement, since BDDMockito has no way of verifying MockedStatic.

**Example:**

Expand Down
9 changes: 1 addition & 8 deletions docs/framework_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,4 @@ According to the javadoc of the [`@NotExtensible`](https://javadoc.io/doc/org.mo
The inspection is applied to interfaces and named classes that can inherit from other types.

```java
import org.mockito.MockSettings;
import java.util.List;

//MockSettings is annotated as @NotExtensible, so this interface is reported by the inspection.
interface SomeInterface extends MockSettings, List<String> {
}
```
![interface extends not extensible interface](assets/interface_extends_not_extensible.png)
Loading

0 comments on commit f7d8e7a

Please sign in to comment.