Skip to content

Commit a6bf663

Browse files
authored
Merge pull request #18 from picimako/v040
Changes for v.0.4.0
2 parents 1cc86af + 21db6a6 commit a6bf663

File tree

105 files changed

+7206
-883
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+7206
-883
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ jobs:
9292
path: ${{ github.workspace }}/build/reports/pluginVerifier
9393

9494
# Run Qodana inspections
95-
- name: Qodana - Code Inspection
96-
uses: JetBrains/[email protected]
95+
# - name: Qodana - Code Inspection
96+
# uses: JetBrains/[email protected]
9797

9898
# Prepare plugin archive content for creating artifact
9999
- name: Prepare Plugin Artifact

CHANGELOG.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,35 @@
44

55
## [Unreleased]
66

7+
## [0.4.0]
8+
### Added
9+
- [#4](https://github.com/picimako/mockitools/issues/4): Added an intention action that can convert `Mockito.mock()` calls to `@Mock` annotated fields.
10+
- [#8](https://github.com/picimako/mockitools/issues/8): Added a new inspection that reports multiple consecutive calls on `*Throw()` stubbing calls.
11+
They can be merged into a single such call.
12+
- [#8](https://github.com/picimako/mockitools/issues/8): Merging of consecutive `*Return()` and `*Throw()` stubbing calls can happen separately if
13+
there are multiple such sections within a stubbing call chain. They, from now on, also keep line wrapping and indentation after applying the quick fix.
14+
- [#12](https://github.com/picimako/mockitools/issues/12): Added a new intention action that can convert arguments of `*Throw()` stubbing methods
15+
from `Type.class` expressions to `new Type()` expressions and vice versa.
16+
- [#13](https://github.com/picimako/mockitools/issues/13): Added 4 new intention actions that can convert between the various stubbing approaches.
17+
- [#15](https://github.com/picimako/mockitools/issues/15): Added 2 new intention actions that can convert between the `Mockito.verify()`
18+
and `BDDMockito.then()` approaches, and vice versa.
19+
- [#16](https://github.com/picimako/mockitools/issues/16): Added a new inspection that can enforce `org.mockito.Mockito` or `org.mockito.BDDMockito` based
20+
stubbing and verification.
21+
722
## [0.3.0]
823
- **IntelliJ version support: versions prior to 2021.1 are no longer supported.**
924

1025
### Added
1126
- Added a new inspection to report checked exceptions in `*Throw()` stubbing calls that are not specified in the stubbed method's `throws` clause.
1227
See [documentation](/docs/stubbing.md#invalid-checked-exception-is-passed-into-throw-methods).
13-
- [#8](https://github.com/picimako/mockitools/issues/8): Added a new inspection that reports multiple consecutive calls on `*Return()` stubbing calls. These can be merged into a single such call.
14-
See [documentation](docs/stubbing.md#consecutive-return-calls-can-be-merged).
28+
- [#8](https://github.com/picimako/mockitools/issues/8): Added a new inspection that reports multiple consecutive calls on `*Return()` stubbing calls.
29+
These can be merged into a single such call. See [documentation](docs/stubbing.md#consecutive-return-and-throw-calls-can-be-merged).
1530

1631
### Changed
1732
- Updated Gradle IntelliJ plugin to 1.4.0, gradle to 7.4, and qodana-action to 4.2.5.
1833
- Replaced unit test file checks with a less restrictive, test source root content check, because unit test file names don't necessarily end with the word *Test*.
1934
This will allow certain functionality to run in files whose names don't end with *Test*.
20-
35+
2136
## [0.2.0]
2237
### Added
2338
- [#2](https://github.com/picimako/mockitools/issues/2): Extended `MockTypeInspection` to validate and report types annotated with `@DoNotMock` annotation.
@@ -27,7 +42,7 @@ See [documentation](docs/stubbing.md#consecutive-return-calls-can-be-merged).
2742
- [Mockito pull request: Add annotation to mark a type as DoNotMock](https://github.com/mockito/mockito/pull/1833/files)
2843
- Extended `MockTypeInspection` to validate new expressions (i.e. `new Clazz()`) against non-mockable types.
2944
- [#4](https://github.com/picimako/mockitools/issues/4): Added intention to convert `Mockito.spy()` calls to `@Spy` annotated fields.
30-
See [documentation](docs/mock_creation.md#convert-mockitospy-calls-to-spy-fields).
45+
See [documentation](docs/mock_creation.md#convert-mockitomockspy-calls-to-mockspy-fields).
3146
- [#4](https://github.com/picimako/mockitools/issues/4): Added intention to convert `@Mock` and `@Spy` annotated fields to `Mockito.mock` and `Mockito.spy()`
3247
calls, respectively. See [documentation](docs/mock_creation.md#convert-mockspy-fields-to-mockitomockspy-calls).
3348

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Mockitools IntelliJ plugin
22

3-
![Build](https://github.com/picimako/mockitools/workflows/Build/badge.svg)
43
[![Version](https://img.shields.io/jetbrains/plugin/v/18117-mockitools.svg)](https://plugins.jetbrains.com/plugin/18117-mockitools)
4+
![Build](https://github.com/picimako/mockitools/workflows/Build/badge.svg)
55
[![Downloads](https://img.shields.io/jetbrains/plugin/d/18117-mockitools.svg)](https://plugins.jetbrains.com/plugin/18117-mockitools)
6+
![](https://img.shields.io/badge/since-IJ2021.1-blue) ![](https://img.shields.io/badge/until-IJ2022.1-blue)
7+
[![Donate](https://img.shields.io/badge/donate-paypal-yellow.svg)](https://www.paypal.com/donate/?hosted_button_id=VVLWNZWPBRUDL)
68

79
<!-- Plugin description -->
8-
This is an IntelliJ-based plugin for [Mockito](https://site.mockito.org), one of the (if not the) most popular mocking framework for unit tests in Java.
10+
Mockitools is a plugin for IntelliJ-based IDEs that provides framework integration for [Mockito](https://site.mockito.org), one of the (if not the) most popular mocking frameworks for unit testing in Java.
911
<!-- Plugin description end -->
1012

1113
It is available for IntelliJ Community Edition as well as IntelliJ IDEA Ultimate Edition.
@@ -14,32 +16,31 @@ It is available for IntelliJ Community Edition as well as IntelliJ IDEA Ultimate
1416

1517
### Mockito 4 migration aids
1618

17-
There is a handful of inspections available to help to migrate users from Mockito 2.x/3.x to 4.x.
18-
19-
Since Mockito 4 has been released only recently, they are enabled by default. But, if you are already
20-
using Mockito 4, it is recommended to disable them, so that IntelliJ doesn't execute inspection that don't make sense
21-
in terms of your project(s). See <kbd>Java</kbd> > <kbd>Mockito</kbd> > <kbd>Migration aids (v4)</kbd> in Inspection settings.
19+
There is a handful of inspections available to help migrate users from Mockito 2.x/3.x to 4.x.
2220

23-
Eventually, when a good amount of time passed and many users potentially moved to v4, these inspections will be disabled by default.
21+
Since Mockito 4 has been released only recently, they are enabled by default, but if you are already
22+
using Mockito 4, it is recommended to disable them in <kbd>Java</kbd> > <kbd>Mockito</kbd> > <kbd>Migration aids (v4)</kbd> in Inspection settings,
23+
so they are not executed for your project. As users move to v4, eventually they will get disabled by default.
2424

25-
The list and details of those inspections can be found in [Mockito v4 migration aids](docs/migration_aids_v4.md).
25+
See the list of those inspections in [Mockito v4 migration aids](docs/migration_aids_v4.md).
2626

2727
### SonarLint
2828

29-
SonarLint also have a few inspections for Mockito, you can find them under the [Java category](https://rules.sonarsource.com/java?search=mockito).
29+
SonarLint also has a few inspections for Mockito that you can find under the [Java category](https://rules.sonarsource.com/java?search=mockito) of their rules.
3030

31-
If you use SonarLint or any other plugin that has checks for things provided by the Mockitools plugin, it is advised adjusting your settings,
32-
so that only those versions of the inspections are enabled that you feel comfortable working with.
31+
If you use SonarLint to validate things that are available in Mockitools too, it is advised to adjust your settings,
32+
and have only those ones enabled that you feel comfortable working with. Be it in SonarLint or in Mockitools.
3333
This will help declutter your editor from duplicate highlights for the same problems, and will also improve the analysis performance in the IDE.
3434

35-
You can find the list of those inspections in the [Mockitools/SonarLint rules](docs/mockitools_sonarlint_rules.md) document.
35+
You can find the list of those inspections in the [Mockitools/SonarLint rules](docs/sonarlint_rules.md) document.
3636

3737
## Why Mockitools is tasty
3838

3939
If [*"Mockito ... tastes really good"* and *"doesn’t give you hangover"*](https://site.mockito.org/#why), this IDE plugin will only make it better. You can find out why, in the dedicated documentation below.
4040

4141
- [Mock creation](docs/mock_creation.md)
42-
- [Mockito verifications](docs/mockito_verifications.md)
42+
- [Stubbing](docs/stubbing.md)
43+
- [Mockito verifications](docs/verifications.md)
4344
- [Argument matching and capturing](docs/argument_matching_capture.md)
4445
- [Version migration aids](docs/migration_aids_v4.md)
4546
- [Framework integration](docs/framework_integration.md)

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
// Kotlin support
1010
// id("org.jetbrains.kotlin.jvm") version "1.6.10"
1111
// Gradle IntelliJ Plugin
12-
id("org.jetbrains.intellij") version "1.4.0"
12+
id("org.jetbrains.intellij") version "1.5.3"
1313
// Gradle Changelog Plugin
1414
id("org.jetbrains.changelog") version "1.3.1"
1515
// Gradle Qodana Plugin

docs/argument_matching_capture.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ Argument matchers are used inconsistently (and incorrectly) when, during stubbin
88
mixed manner. That is not permitted by Mockito, and test execution fails when it encounters this problem. As per Mockito documentation:
99
> If you are using argument matchers, all arguments have to be provided by matchers.
1010
11-
For example:
11+
For example, the followings are invalid, and would block test execution.
1212

1313
```java
1414
Mockito.when(mock.method(eq("some string"), 25)).thenReturn(10);
1515
//or
1616
Mockito.when(mock.method("some string", geq(25))).thenReturn(10);
1717
```
18-
are invalid, and would block test execution.
1918

2019
The following ways of stubbing are supported by this inspection:
2120
- `Mockito.when()`
@@ -38,7 +37,7 @@ SonarLint also have a rule for this validation: [Mockito argument matchers shoul
3837
![](https://img.shields.io/badge/since-0.1.0-blue) [![](https://img.shields.io/badge/implementation-CaptorFieldInitializationInspection-blue)](../src/main/java/com/picimako/mockitools/inspection/CaptorFieldInitializationInspection.java)
3938

4039
Since `@Captor` annotated fields are initialized automagically by Mockito via `MockitoJUnitRunner`, `MockitoJUnit.rule()` or
41-
`MockitoAnnotations.initMocks()` / `MockitoAnnotations.openMocks()`, there is no need to explicitly initialize them.
40+
`MockitoAnnotations.initMocks()/openMocks()`, there is no need to explicitly initialize them.
4241

4342
This inspection reports `ArgumentCaptor` type `@Captor` fields that have an initializer specified.
4443

@@ -70,27 +69,25 @@ Fields that are annotated as `@Captor` must have `ArgumentCaptor` as their type,
7069
This inspection reports fields that are annotated as `@Captor` but their types are not `ArgumentCaptor`.
7170
It also provides a quick fix (*Convert field type to ArgumentCaptor<>*) to convert the field type to ArgumentCaptor with the appropriate generic type.
7271

73-
See some examples below (with the before-after states):
74-
7572
```java
7673
//-- arrays --
7774

7875
@Captor
79-
String[] captor;
76+
String[] captor; //before
8077
@Captor
81-
ArgumentCaptor<String[]> captor;
78+
ArgumentCaptor<String[]> captor; //after
8279

8380
//-- primitive types --
8481

8582
@Captor
86-
char captor;
83+
char captor; //before
8784
@Captor
88-
ArgumentCaptor<Character> captor; //field type is replaced with its boxed type
85+
ArgumentCaptor<Character> captor; //after: field type is replaced with its boxed type
8986

9087
//-- types with generic types --
9188

9289
@Captor
93-
List<List<String>> captor;
90+
List<List<String>> captor; //before
9491
@Captor
95-
ArgumentCaptor<List<List<String>>> captor;
92+
ArgumentCaptor<List<List<String>>> captor; //after
9693
```

docs/conventions.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Project Conventions
2+
3+
### Enforce org.mockito.Mockito over org.mockito.BDDMockito and vice versa
4+
5+
![](https://img.shields.io/badge/inspection-orange) ![](https://img.shields.io/badge/since-0.4.0-blue)
6+
[![](https://img.shields.io/badge/implementation-EnforceConventionInspection-blue)](../src/main/java/com/picimako/mockitools/inspection/EnforceConventionInspection.java)
7+
8+
Projects might want to enforce certain coding conventions for Mockito. This inspection helps with that.
9+
10+
It reports calls to static stubbing and verification methods of `org.mockito.Mockito`, if `org.mockito.BDDMockito`
11+
based stubbing and verification must be used, and vice versa.
12+
Whether to enforce one or the other can be configured in the inspection settings.
13+
14+
Notes:
15+
- It is not enabled by default since a project might not want to enforce these conventions.
16+
- There are no dedicated quick fixes, since separate intention actions are available to convert between these approaches:
17+
- [conversion of stubbing](stubbing.md#convert-between-various-stubbing-approaches)
18+
- [conversion of verification](verifications.md#convert-between-various-verification-approaches)
19+
- It doesn't support `InOrder` verification at the moment.
20+
21+
**Example:**
22+
23+
Let's say we want to enforce `org.mockito.BDDMockito` based calls, then the following calls would all be reported:
24+
25+
```java
26+
//stubbing
27+
Mockito.when(mockObject.doSomething()).thenReturn(10);
28+
Mockito.doReturn(10).when(mockObject).doSomething();
29+
Mockito.doThrow(IllegalArgumentException.class).when(mockObject).doSomething();
30+
Mockito.doAnswer(Answers.CALLS_REAL_METHODS).when(mockObject).doSomething();
31+
Mockito.doCallRealMethod().when(mockObject).doSomething();
32+
Mockito.doNothing().when(mockObject).voidMethod();
33+
34+
//verification
35+
Mockito.verify(mockObject, Mockito.times(2)).doSomething();
36+
Mockito.verifyNoMoreInteractions(mockObject);
37+
Mockito.verifyNoInteractions(mockObject);
38+
Mockito.verifyZeroInteractions(mockObject); //only in Mockito 3
39+
```

docs/framework_integration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ According to the javadoc of the [`@NotExtensible`](https://javadoc.io/doc/org.mo
1313

1414
> Indicates to the user that she should not provide custom implementations of given type.
1515
16+
The inspection is applied to interfaces and named classes that can inherit from other types.
17+
1618
```java
1719
import org.mockito.MockSettings;
1820
import java.util.List;
@@ -21,5 +23,3 @@ import java.util.List;
2123
interface SomeInterface extends MockSettings, List<String> {
2224
}
2325
```
24-
25-
The inspection is applied to interfaces and named classes that can inherit from other types.

docs/migration_aids_v4.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ some inspections to help migrate from one version to another; in the context of
55

66
Check out the [Mockito 4.0.0 release notes](https://github.com/mockito/mockito/releases/tag/v4.0.0) for details.
77

8-
### Argument matchers are called via org.mockito.Matchers instead of org.mockito.ArgumentMatchers
8+
- [Argument matchers are called via org.mockito.Matchers instead of org.mockito.ArgumentMatchers](#argument-matchers-are-called-via-orgmockitomatchers-instead-of-orgmockitoargumentmatchers)
9+
- [Usage of deprecated anyX() matchers](#usage-of-deprecated-anyx-matchers)
10+
- [Usage of parameterized variants of isNull(), isNotNull() and notNull()](#usage-of-parameterized-variants-of-isnull-isnotnull-and-notnull)
11+
- [Usage of deprecated verify methods](#usage-of-deprecated-verify-methods)
12+
- [Usage of deprecated plugins classes](#usage-of-deprecated-plugins-classes)
13+
- [Usage of deprecated JUnit runners](#usage-of-deprecated-junit-runners)
14+
15+
### Argument matchers are called via org.mockito.Matchers instead of org.mockito.ArgumentMatchers
916

1017
![](https://img.shields.io/badge/since-0.1.0-blue) [![](https://img.shields.io/badge/implementation-ArgumentMatchersCalledViaMatchersInspection-blue)](../src/main/java/com/picimako/mockitools/inspection/migrationaids/v4/ArgumentMatchersCalledViaMatchersInspection.java)
1118
![](https://img.shields.io/badge/mockito-2.x-orange) ![](https://img.shields.io/badge/mockito-3.x-orange)
@@ -65,7 +72,7 @@ Mockito.when(mock.method(ArgumentMatchers.anyCollection())).thenReturn(10);
6572
#### Notes
6673

6774
If a matcher is not used with static import and referenced via `org.mockito.Matchers`, it is also replaced
68-
with the `org.mockito.ArgumentMatchers` qualifier. See the corresponding logic in [ReplaceMatchersWithArgumentMatchersQuickFix](../src/main/java/com/picimako/mockitools/inspection/migrationaids/v4/UseArgumentMatchersInsteadOfMatchersInspection.java).
75+
with the `org.mockito.ArgumentMatchers` qualifier. See the corresponding logic in [ReplaceAnyXOfWithAnyXQuickFix](../src/main/java/com/picimako/mockitools/inspection/migrationaids/v4/UsageOfAnyMatchersInspection.java).
6976

7077
### Usage of parameterized variants of isNull(), isNotNull() and notNull()
7178

@@ -89,7 +96,7 @@ Mockito.when(mock.method(ArgumentMatchers.notNull())).thenReturn(10);
8996

9097
### Usage of deprecated verify methods
9198

92-
![](https://img.shields.io/badge/since-0.1.0-blue) [![](https://img.shields.io/badge/implementation-DeprecatedMockedStaticVerifyInspection-blue)](../src/main/java/com/picimako/mockitools/inspection/migrationaids/v4/DeprecatedMockedStaticVerifyInspection.java)
99+
![](https://img.shields.io/badge/since-0.1.0-blue) [![](https://img.shields.io/badge/implementation-UsageOfDeprecatedVerifyInspection-blue)](../src/main/java/com/picimako/mockitools/inspection/migrationaids/v4/UsageOfDeprecatedVerifyInspection.java)
93100
![](https://img.shields.io/badge/mockito-3.x-orange)
94101

95102
#### MockedStatic.verify()

0 commit comments

Comments
 (0)