AssertThatJava8Optional and AssertThatGuavaOptional inspections do not longer try to fix assertThat(optional).isEqualTo(Optional.fromNullable(expression)) to contains() when expression is not a non-null constant expression.
This commit is contained in:
parent
8fb3ecce95
commit
4420a0a392
@ -509,7 +509,7 @@ The IntelliJ framework actually uses the JUnit 3 TestCase for plugin testing and
|
||||
Feel free to use the code (in package ```de.platon42.intellij.jupiter```) for your projects (with attribution).
|
||||
|
||||
## Planned features
|
||||
- Joining .contains() expressions
|
||||
- Joining ```.contains()``` expressions
|
||||
- Converting ```foo.compareTo(bar) == 0``` to ```isEqualTo()``` (yes, I've *really* seen code like that)
|
||||
- Extraction with property names to lambda with Java 8
|
||||
|
||||
@ -520,6 +520,12 @@ Feel free to use the code (in package ```de.platon42.intellij.jupiter```) for yo
|
||||
|
||||
## Changelog
|
||||
|
||||
#### V1.3 (02-Aug-19)
|
||||
- AssertJ 3.13.0 broke some inspections due to new ```AbstractStringAssert::isEqualTo()``` method.
|
||||
- AssertThatJava8Optional and AssertThatGuavaOptional inspections do not longer try to fix
|
||||
```assertThat(optional).isEqualTo(Optional.fromNullable(expression))``` to ```contains()```
|
||||
when ```expression``` is not a non-null constant expression.
|
||||
|
||||
#### V1.2 (23-Jun-19)
|
||||
- Due to popular demand the JoinAssertThatStatements inspection will now add line breaks on joining statements.
|
||||
The amount of statements joined without causing line breaks can be configured but defaults to 1 (always).
|
||||
|
@ -3,7 +3,7 @@ plugins {
|
||||
id 'org.jetbrains.intellij' version '0.4.9'
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.3.41'
|
||||
id 'jacoco'
|
||||
id 'com.github.kt3k.coveralls' version '2.8.2'
|
||||
id 'com.github.kt3k.coveralls' version '2.8.4'
|
||||
}
|
||||
|
||||
group 'de.platon42'
|
||||
@ -43,9 +43,12 @@ intellij {
|
||||
|
||||
patchPluginXml {
|
||||
changeNotes """
|
||||
<h4>V1.3 (01-Aug-19)</h4>
|
||||
<h4>V1.3 (02-Aug-19)</h4>
|
||||
<ul>
|
||||
<li>AssertJ 3.13.0 broke some inspections due to new AbstractStringAssert::isEqualTo().
|
||||
<li>AssertJ 3.13.0 broke some inspections due to new AbstractStringAssert::isEqualTo() method.
|
||||
<li>AssertThatJava8Optional and AssertThatGuavaOptional inspections do not longer try to fix
|
||||
assertThat(optional).isEqualTo(Optional.fromNullable(expression)) to contains()
|
||||
when expression is not a non-null constant expression.
|
||||
</ul>
|
||||
<p>Full changelog available at <a href="https://github.com/chrisly42/cajon-plugin#changelog">Github project site</a>.</p>
|
||||
"""
|
||||
|
@ -70,6 +70,9 @@ class AssertThatGuavaOptionalInspection : AbstractAssertJInspection() {
|
||||
if (IS_EQUAL_TO_OBJECT.test(expression)) {
|
||||
val innerExpectedCall = expression.firstArg as? PsiMethodCallExpression ?: return
|
||||
if (CallMatcher.anyOf(GUAVA_OPTIONAL_OF, GUAVA_OPTIONAL_FROM_NULLABLE).test(innerExpectedCall)) {
|
||||
if (GUAVA_OPTIONAL_FROM_NULLABLE.test(innerExpectedCall)) {
|
||||
innerExpectedCall.firstArg.calculateConstantValue() ?: return
|
||||
}
|
||||
registerRemoveExpectedOutmostMethod(holder, expression, expression, MethodNames.CONTAINS) { desc, method ->
|
||||
QuickFixWithPostfixDelegate(
|
||||
UnwrapExpectedStaticMethodCallQuickFix(desc, method),
|
||||
|
@ -60,6 +60,9 @@ class AssertThatJava8OptionalInspection : AbstractAssertJInspection() {
|
||||
if (IS_EQUAL_TO_OBJECT.test(expression)) {
|
||||
val innerExpectedCall = expression.firstArg as? PsiMethodCallExpression ?: return
|
||||
if (CallMatcher.anyOf(OPTIONAL_OF, OPTIONAL_OF_NULLABLE).test(innerExpectedCall)) {
|
||||
if (OPTIONAL_OF_NULLABLE.test(innerExpectedCall)) {
|
||||
innerExpectedCall.firstArg.calculateConstantValue() ?: return
|
||||
}
|
||||
registerRemoveExpectedOutmostMethod(holder, expression, expression, MethodNames.CONTAINS, ::UnwrapExpectedStaticMethodCallQuickFix)
|
||||
} else if (OPTIONAL_EMPTY.test(innerExpectedCall)) {
|
||||
registerSimplifyMethod(holder, expression, MethodNames.IS_NOT_PRESENT)
|
||||
|
@ -1,7 +1,7 @@
|
||||
<idea-plugin>
|
||||
<id>de.platon42.cajon</id>
|
||||
<name>Concise AssertJ Optimizing Nitpicker (Cajon)</name>
|
||||
<vendor email="chrisly@platon42.de" url="https://github.com/chrisly42/cajon-plugin">Platon42</vendor>
|
||||
<vendor email="chrisly@platon42.de" url="https://github.com/chrisly42/cajon-plugin">Chris 'platon42' Hodges</vendor>
|
||||
|
||||
<description><![CDATA[
|
||||
Cajon is an IntelliJ IDEA Plugin for shortening and optimizing AssertJ assertions.
|
||||
|
@ -31,8 +31,14 @@ public class GuavaOptional {
|
||||
assertThat(opt).isPresent();
|
||||
assertThat(opt).isPresent();
|
||||
|
||||
String possibleNullString = System.getProperty("username");
|
||||
String notNullString = "Narf";
|
||||
|
||||
assertThat(opt).as("foo").contains("foo");
|
||||
assertThat(opt).contains("foo");
|
||||
assertThat(opt).isEqualTo(Optional.fromNullable(null));
|
||||
assertThat(opt).isEqualTo(Optional.fromNullable(possibleNullString));
|
||||
assertThat(opt).isEqualTo(Optional.fromNullable(notNullString));
|
||||
assertThat(opt).isNotEqualTo(Optional.of("foo"));
|
||||
assertThat(opt).isNotEqualTo(Optional.fromNullable("foo"));
|
||||
|
||||
|
@ -31,8 +31,14 @@ public class GuavaOptional {
|
||||
assertThat(opt.orNull()).isNotEqualTo(null);
|
||||
assertThat(opt.orNull()).isNotNull();
|
||||
|
||||
String possibleNullString = System.getProperty("username");
|
||||
String notNullString = "Narf";
|
||||
|
||||
assertThat(opt).as("foo").isEqualTo(Optional.of("foo"));
|
||||
assertThat(opt).isEqualTo(Optional.fromNullable("foo"));
|
||||
assertThat(opt).isEqualTo(Optional.fromNullable(null));
|
||||
assertThat(opt).isEqualTo(Optional.fromNullable(possibleNullString));
|
||||
assertThat(opt).isEqualTo(Optional.fromNullable(notNullString));
|
||||
assertThat(opt).isNotEqualTo(Optional.of("foo"));
|
||||
assertThat(opt).isNotEqualTo(Optional.fromNullable("foo"));
|
||||
|
||||
|
@ -30,8 +30,14 @@ public class Java8Optional {
|
||||
assertThat(opt).isPresent();
|
||||
assertThat(opt).isPresent();
|
||||
|
||||
String possibleNullString = System.getProperty("username");
|
||||
String notNullString = "Narf";
|
||||
|
||||
assertThat(opt).as("foo").contains("foo");
|
||||
assertThat(opt).contains("foo");
|
||||
assertThat(opt).isEqualTo(Optional.ofNullable(null));
|
||||
assertThat(opt).isEqualTo(Optional.ofNullable(possibleNullString));
|
||||
assertThat(opt).isEqualTo(Optional.ofNullable(notNullString));
|
||||
assertThat(opt).isNotEqualTo(Optional.of("foo"));
|
||||
assertThat(opt).isNotEqualTo(Optional.ofNullable("foo"));
|
||||
|
||||
|
@ -30,8 +30,14 @@ public class Java8Optional {
|
||||
assertThat(opt.orElse(null)).isNotEqualTo(null);
|
||||
assertThat(opt.orElse(null)).isNotNull();
|
||||
|
||||
String possibleNullString = System.getProperty("username");
|
||||
String notNullString = "Narf";
|
||||
|
||||
assertThat(opt).as("foo").isEqualTo(Optional.of("foo"));
|
||||
assertThat(opt).isEqualTo(Optional.ofNullable("foo"));
|
||||
assertThat(opt).isEqualTo(Optional.ofNullable(null));
|
||||
assertThat(opt).isEqualTo(Optional.ofNullable(possibleNullString));
|
||||
assertThat(opt).isEqualTo(Optional.ofNullable(notNullString));
|
||||
assertThat(opt).isNotEqualTo(Optional.of("foo"));
|
||||
assertThat(opt).isNotEqualTo(Optional.ofNullable("foo"));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user