Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0909d8c39 | ||
|
|
5113cc15ab | ||
|
|
ae2076a425 | ||
|
|
42429c0f72 | ||
|
|
8133f3850f | ||
|
|
8d03b3734c |
@@ -234,6 +234,35 @@ You can toggle the various inspections in the Settings/Editor/Inspections in the
|
|||||||
to: assertThat(objActual).hasSameHashCodeAs(objExpected);
|
to: assertThat(objActual).hasSameHashCodeAs(objExpected);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- AssertThatComparableExpression
|
||||||
|
|
||||||
|
Handles ```compareTo()``` inside an expected expression.
|
||||||
|
|
||||||
|
```
|
||||||
|
from: assertThat(obj1.compareTo(obj2)).isEqualTo(0);
|
||||||
|
to: assertThat(obj1).isEqualByComparingTo(obj2);
|
||||||
|
|
||||||
|
from: assertThat(obj1.compareTo(obj2)).isNotZero();
|
||||||
|
to: assertThat(obj1).isNotEqualByComparingTo(obj2);
|
||||||
|
|
||||||
|
from: assertThat(obj1.compareTo(obj2)).isNotEqualTo(-1);
|
||||||
|
from: assertThat(obj1.compareTo(obj2)).isGreaterThanOrEqualTo(0);
|
||||||
|
from: assertThat(obj1.compareTo(obj2)).isGreaterThan(-1);
|
||||||
|
from: assertThat(obj1.compareTo(obj2)).isNotNegative();
|
||||||
|
to: assertThat(obj1).isGreaterThanOrEqualTo(obj2);
|
||||||
|
|
||||||
|
from: assertThat(obj1.compareTo(obj2)).isOne();
|
||||||
|
to: assertThat(obj1).isGreaterThan(obj2);
|
||||||
|
|
||||||
|
from: assertThat(obj1.compareTo(obj2)).isNotPositive();
|
||||||
|
to: assertThat(obj1).isLessThanOrEqualTo(obj2);
|
||||||
|
|
||||||
|
from: assertThat(obj1.compareTo(obj2)).isLessThan(0);
|
||||||
|
to: assertThat(obj1).isLessThan(obj2);
|
||||||
|
```
|
||||||
|
|
||||||
|
Several more combinations omitted...
|
||||||
|
|
||||||
- AssertThatCollectionOrMapExpression
|
- AssertThatCollectionOrMapExpression
|
||||||
|
|
||||||
Moves ```Collection``` and ```Map``` operations inside ```assertThat()``` out.
|
Moves ```Collection``` and ```Map``` operations inside ```assertThat()``` out.
|
||||||
@@ -333,6 +362,47 @@ You can toggle the various inspections in the Settings/Editor/Inspections in the
|
|||||||
to: assertThat(file).isNotEmptyDirectory();
|
to: assertThat(file).isNotEmptyDirectory();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
and additionally with AssertJ 3.14.0 or later
|
||||||
|
|
||||||
|
```
|
||||||
|
from: assertThat(file.length()).isEqualTo(0);
|
||||||
|
from: assertThat(file.length()).isZero();
|
||||||
|
to: assertThat(file).isEmpty();
|
||||||
|
|
||||||
|
from: assertThat(file.length()).isNotEqualTo(0);
|
||||||
|
from: assertThat(file.length()).isNotZero();
|
||||||
|
to: assertThat(file).isNotEmpty();
|
||||||
|
|
||||||
|
from: assertThat(file.length()).isEqualTo(len);
|
||||||
|
to: assertThat(file).hasSize(len);
|
||||||
|
```
|
||||||
|
|
||||||
|
- AssertThatPathExpression
|
||||||
|
|
||||||
|
Moves ```Path``` method calls inside ```assertThat()``` out.
|
||||||
|
Note: Uses hasParentRaw() instead of hasParent() for quickfixes, because it is semantically
|
||||||
|
equivalent. For most cases though, hasParent() will show identical behavior.
|
||||||
|
|
||||||
|
```
|
||||||
|
from: assertThat(path.isAbsolute()).isTrue();
|
||||||
|
to: assertThat(path).isAbsolute();
|
||||||
|
|
||||||
|
from: assertThat(path.isAbsolute()).isFalse();
|
||||||
|
to: assertThat(path).isRelative();
|
||||||
|
|
||||||
|
from: assertThat(path.getParent()).isEqualTo(pathname);
|
||||||
|
to: assertThat(path).hasParentRaw(pathname);
|
||||||
|
|
||||||
|
from: assertThat(path.getParent()).isNull();
|
||||||
|
to: assertThat(path).hasNoParentRaw();
|
||||||
|
|
||||||
|
from: assertThat(path.startsWith(otherPath)).isTrue();
|
||||||
|
to: assertThat(path).startsWithRaw(otherPath);
|
||||||
|
|
||||||
|
from: assertThat(path.endsWith(otherPath)).isTrue();
|
||||||
|
to: assertThat(path).endsWithRaw(otherPath);
|
||||||
|
```
|
||||||
|
|
||||||
- AssertThatEnumerableIsEmpty
|
- AssertThatEnumerableIsEmpty
|
||||||
|
|
||||||
Uses ```isEmpty()``` for ```hasSize(0)``` iterable assertions instead.
|
Uses ```isEmpty()``` for ```hasSize(0)``` iterable assertions instead.
|
||||||
@@ -631,8 +701,7 @@ Feel free to use the code (in package ```de.platon42.intellij.jupiter```) for yo
|
|||||||
|
|
||||||
## Planned features
|
## Planned features
|
||||||
- More Optional fixes such as ```opt1.get() == opt2.get()``` etc.
|
- More Optional fixes such as ```opt1.get() == opt2.get()``` etc.
|
||||||
- More moving out of methods for Path, LocalDate/Time etc.
|
- More moving out of methods for LocalDate/Time etc.
|
||||||
- Converting ```foo.compareTo(bar) == 0``` to ```isEqualTo()``` (yes, I've *really* seen code like that)
|
|
||||||
- Extraction with property names to lambda/method reference with Java 8
|
- Extraction with property names to lambda/method reference with Java 8
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -642,6 +711,13 @@ Feel free to use the code (in package ```de.platon42.intellij.jupiter```) for yo
|
|||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
#### V1.7 (19-Nov-19)
|
||||||
|
- Fixed a lapsuus in AssertThatFileExpression also transforming ```.listFiles()``` with a filter argument.
|
||||||
|
- Added first version of AssertThatPathExpression for a limited number transformations (more stuff is possible,
|
||||||
|
but requires detection and transformation of static ```Files```-methods).
|
||||||
|
- Added AssertThatComparableExpression for funny ```compareTo()``` uses.
|
||||||
|
- Added ```hasSize(), isEmpty()``` and ```isNotEmpty()``` for AssertThatFileExpression when using AssertJ >= 3.14.0.
|
||||||
|
|
||||||
#### V1.6 (30-Sep-19)
|
#### V1.6 (30-Sep-19)
|
||||||
- Really fixed AssertThatGuavaOptional inspections to avoid conversions from ```.get()``` to ```.contains()```
|
- Really fixed AssertThatGuavaOptional inspections to avoid conversions from ```.get()``` to ```.contains()```
|
||||||
for array types. Sigh. Shouldn't be working >12h a day and then do some more stuff at home.
|
for array types. Sigh. Shouldn't be working >12h a day and then do some more stuff at home.
|
||||||
|
|||||||
+13
-16
@@ -1,13 +1,13 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'org.jetbrains.intellij' version '0.4.10'
|
id 'org.jetbrains.intellij' version '0.4.13'
|
||||||
id 'org.jetbrains.kotlin.jvm' version '1.3.50'
|
id 'org.jetbrains.kotlin.jvm' version '1.3.60'
|
||||||
id 'jacoco'
|
id 'jacoco'
|
||||||
id 'com.github.kt3k.coveralls' version '2.8.4'
|
id 'com.github.kt3k.coveralls' version '2.8.4'
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'de.platon42'
|
group 'de.platon42'
|
||||||
version '1.6'
|
version '1.7'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -20,8 +20,8 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
||||||
testCompile "org.assertj:assertj-core:3.13.2"
|
testCompile "org.assertj:assertj-core:3.14.0"
|
||||||
testCompile "org.assertj:assertj-guava:3.2.1"
|
testCompile "org.assertj:assertj-guava:3.3.0"
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
|
||||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
|
||||||
testImplementation "org.jetbrains.kotlin:kotlin-test"
|
testImplementation "org.jetbrains.kotlin:kotlin-test"
|
||||||
@@ -35,7 +35,7 @@ compileTestKotlin {
|
|||||||
kotlinOptions.jvmTarget = "1.8"
|
kotlinOptions.jvmTarget = "1.8"
|
||||||
}
|
}
|
||||||
intellij {
|
intellij {
|
||||||
version '2019.2.3'
|
version '2019.2.4'
|
||||||
// pluginName 'Concise AssertJ Optimizing Nitpicker (Cajon)'
|
// pluginName 'Concise AssertJ Optimizing Nitpicker (Cajon)'
|
||||||
updateSinceUntilBuild false
|
updateSinceUntilBuild false
|
||||||
plugins = ['java']
|
plugins = ['java']
|
||||||
@@ -43,16 +43,13 @@ intellij {
|
|||||||
|
|
||||||
patchPluginXml {
|
patchPluginXml {
|
||||||
changeNotes """
|
changeNotes """
|
||||||
<h4>V1.6 (30-Sep-19)</h4>
|
<h4>V1.7 (19-Nov-19)</h4>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Really fixed AssertThatGuavaOptional inspections to avoid conversions from .get() to .contains()
|
<li>Fixed a lapsuus in AssertThatFileExpression also transforming listFiles() with a filter argument.
|
||||||
for array types. Sigh. Shouldn't be working >12h a day and then do some more stuff at home.
|
<li>Added first version of AssertThatPathExpression for a limited number transformations (more stuff is possible,
|
||||||
<li>Fixed a bug in AssertThatBinaryExpression inspection for assertThat(null != expression) and related
|
but requires detection and transformation of static Files-methods).
|
||||||
that would not correctly invert the condition on transformation.
|
<li>Added AssertThatComparableExpression for funny compareTo() uses.
|
||||||
<li>Added new AssertThatFileExpression to move out many common methods from inside the
|
<li>Added hasSize(), isEmpty() and isNotEmpty() for AssertThatFileExpression when using AssertJ >= 3.14.0.
|
||||||
assertThat() expression (exists(), getName(), getParent() and many more).
|
|
||||||
<li>Added several transformations to AssertThatStringExpression inspection.
|
|
||||||
Specifically, uses of matches(), compareToIgnoreCase(), indexOf(), and trim().
|
|
||||||
</ul>
|
</ul>
|
||||||
<p>Full changelog available at <a href="https://github.com/chrisly42/cajon-plugin#changelog">Github project site</a>.</p>
|
<p>Full changelog available at <a href="https://github.com/chrisly42/cajon-plugin#changelog">Github project site</a>.</p>
|
||||||
"""
|
"""
|
||||||
@@ -66,7 +63,7 @@ test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
jacoco {
|
jacoco {
|
||||||
toolVersion = '0.8.4'
|
toolVersion = '0.8.5'
|
||||||
}
|
}
|
||||||
|
|
||||||
jacocoTestReport {
|
jacocoTestReport {
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ class AssertJClassNames {
|
|||||||
@NonNls
|
@NonNls
|
||||||
const val ABSTRACT_ITERABLE_ASSERT_CLASSNAME = "org.assertj.core.api.AbstractIterableAssert"
|
const val ABSTRACT_ITERABLE_ASSERT_CLASSNAME = "org.assertj.core.api.AbstractIterableAssert"
|
||||||
@NonNls
|
@NonNls
|
||||||
|
const val ABSTRACT_FILE_ASSERT_CLASSNAME = "org.assertj.core.api.AbstractFileAssert"
|
||||||
|
@NonNls
|
||||||
const val ABSTRACT_OPTIONAL_ASSERT_CLASSNAME = "org.assertj.core.api.AbstractOptionalAssert"
|
const val ABSTRACT_OPTIONAL_ASSERT_CLASSNAME = "org.assertj.core.api.AbstractOptionalAssert"
|
||||||
@NonNls
|
@NonNls
|
||||||
const val EXTRACTORS_CLASSNAME = "org.assertj.core.extractor.Extractors"
|
const val EXTRACTORS_CLASSNAME = "org.assertj.core.extractor.Extractors"
|
||||||
|
|||||||
+8
-2
@@ -137,9 +137,15 @@ abstract class AbstractAssertJInspection : AbstractBaseJavaLocalInspectionTool()
|
|||||||
val IS_LESS_THAN_OR_EQUAL_TO_INT = CallMatcher.instanceCall(ABSTRACT_COMPARABLE_ASSERT_CLASSNAME, MethodNames.IS_LESS_THAN_OR_EQUAL_TO)
|
val IS_LESS_THAN_OR_EQUAL_TO_INT = CallMatcher.instanceCall(ABSTRACT_COMPARABLE_ASSERT_CLASSNAME, MethodNames.IS_LESS_THAN_OR_EQUAL_TO)
|
||||||
.parameterTypes("int")!!
|
.parameterTypes("int")!!
|
||||||
|
|
||||||
val IS_ZERO = CallMatcher.instanceCall(ABSTRACT_INTEGER_ASSERT_CLASSNAME, MethodNames.IS_ZERO)
|
val IS_ZERO_INT = CallMatcher.instanceCall(ABSTRACT_INTEGER_ASSERT_CLASSNAME, MethodNames.IS_ZERO)
|
||||||
.parameterCount(0)!!
|
.parameterCount(0)!!
|
||||||
val IS_NOT_ZERO = CallMatcher.instanceCall(ABSTRACT_INTEGER_ASSERT_CLASSNAME, MethodNames.IS_NOT_ZERO)
|
val IS_NOT_ZERO_INT = CallMatcher.instanceCall(ABSTRACT_INTEGER_ASSERT_CLASSNAME, MethodNames.IS_NOT_ZERO)
|
||||||
|
.parameterCount(0)!!
|
||||||
|
val IS_ZERO_LONG = CallMatcher.instanceCall(ABSTRACT_LONG_ASSERT_CLASSNAME, MethodNames.IS_ZERO)
|
||||||
|
.parameterCount(0)!!
|
||||||
|
val IS_NOT_ZERO_LONG = CallMatcher.instanceCall(ABSTRACT_LONG_ASSERT_CLASSNAME, MethodNames.IS_NOT_ZERO)
|
||||||
|
.parameterCount(0)!!
|
||||||
|
val IS_ONE = CallMatcher.instanceCall(ABSTRACT_INTEGER_ASSERT_CLASSNAME, "isOne")
|
||||||
.parameterCount(0)!!
|
.parameterCount(0)!!
|
||||||
val IS_NEGATIVE = CallMatcher.instanceCall(ABSTRACT_INTEGER_ASSERT_CLASSNAME, "isNegative")
|
val IS_NEGATIVE = CallMatcher.instanceCall(ABSTRACT_INTEGER_ASSERT_CLASSNAME, "isNegative")
|
||||||
.parameterCount(0)!!
|
.parameterCount(0)!!
|
||||||
|
|||||||
+3
-1
@@ -42,7 +42,8 @@ abstract class AbstractMoveOutInspection : AbstractAssertJInspection() {
|
|||||||
MoveOutMethodCallExpressionQuickFix(
|
MoveOutMethodCallExpressionQuickFix(
|
||||||
desc, method,
|
desc, method,
|
||||||
replaceOnlyThisMethod = mapping.expectedMatcher,
|
replaceOnlyThisMethod = mapping.expectedMatcher,
|
||||||
replaceFromOriginalMethod = mapping.replaceFromOriginalMethod
|
replaceFromOriginalMethod = mapping.replaceFromOriginalMethod,
|
||||||
|
noExpectedExpression = mapping.noExpectedExpression
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,6 +58,7 @@ abstract class AbstractMoveOutInspection : AbstractAssertJInspection() {
|
|||||||
val expectNullNonNull: Boolean? = null,
|
val expectNullNonNull: Boolean? = null,
|
||||||
val expectedMatcher: CallMatcher? = null,
|
val expectedMatcher: CallMatcher? = null,
|
||||||
val replaceFromOriginalMethod: Boolean = false,
|
val replaceFromOriginalMethod: Boolean = false,
|
||||||
|
val noExpectedExpression: Boolean = false,
|
||||||
val additionalCondition: ((PsiExpressionStatement, PsiMethodCallExpression) -> Boolean)? = null
|
val additionalCondition: ((PsiExpressionStatement, PsiMethodCallExpression) -> Boolean)? = null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
+115
@@ -0,0 +1,115 @@
|
|||||||
|
package de.platon42.intellij.plugins.cajon.inspections
|
||||||
|
|
||||||
|
import com.intellij.codeInspection.ProblemsHolder
|
||||||
|
import com.intellij.psi.*
|
||||||
|
import com.siyeh.ig.callMatcher.CallMatcher
|
||||||
|
import de.platon42.intellij.plugins.cajon.MethodNames
|
||||||
|
import de.platon42.intellij.plugins.cajon.calculateConstantValue
|
||||||
|
import de.platon42.intellij.plugins.cajon.firstArg
|
||||||
|
|
||||||
|
class AssertThatComparableInspection : AbstractMoveOutInspection() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val DISPLAY_NAME = "Asserting a compareTo() expression"
|
||||||
|
|
||||||
|
private val ARG_IS_ZERO_CONST: (PsiExpressionStatement, PsiMethodCallExpression) -> Boolean = { _, call -> call.firstArg.calculateConstantValue() == 0 }
|
||||||
|
private val ARG_IS_PLUS_ONE_CONST: (PsiExpressionStatement, PsiMethodCallExpression) -> Boolean = { _, call -> call.firstArg.calculateConstantValue() == 1 }
|
||||||
|
private val ARG_IS_MINUS_ONE_CONST: (PsiExpressionStatement, PsiMethodCallExpression) -> Boolean = { _, call -> call.firstArg.calculateConstantValue() == -1 }
|
||||||
|
|
||||||
|
private val COMPARABLE_COMPARE_TO =
|
||||||
|
CallMatcher.instanceCall(CommonClassNames.JAVA_LANG_COMPARABLE, "compareTo").parameterCount(1)
|
||||||
|
|
||||||
|
private val MAPPINGS = listOf(
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
"isEqualByComparingTo", expectedMatcher = IS_EQUAL_TO_INT, replaceFromOriginalMethod = true,
|
||||||
|
additionalCondition = ARG_IS_ZERO_CONST
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
"isEqualByComparingTo", expectedMatcher = IS_ZERO_INT, replaceFromOriginalMethod = true
|
||||||
|
),
|
||||||
|
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
"isNotEqualByComparingTo", expectedMatcher = IS_NOT_EQUAL_TO_INT, replaceFromOriginalMethod = true,
|
||||||
|
additionalCondition = ARG_IS_ZERO_CONST
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
"isNotEqualByComparingTo", expectedMatcher = IS_NOT_ZERO_INT, replaceFromOriginalMethod = true
|
||||||
|
),
|
||||||
|
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
MethodNames.IS_GREATER_THAN_OR_EQUAL_TO, expectedMatcher = IS_GREATER_THAN_OR_EQUAL_TO_INT, replaceFromOriginalMethod = true,
|
||||||
|
additionalCondition = ARG_IS_ZERO_CONST
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
MethodNames.IS_GREATER_THAN_OR_EQUAL_TO, expectedMatcher = CallMatcher.anyOf(IS_NOT_EQUAL_TO_INT, IS_GREATER_THAN_INT), replaceFromOriginalMethod = true,
|
||||||
|
additionalCondition = ARG_IS_MINUS_ONE_CONST
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
MethodNames.IS_GREATER_THAN_OR_EQUAL_TO, expectedMatcher = IS_NOT_NEGATIVE, replaceFromOriginalMethod = true
|
||||||
|
),
|
||||||
|
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
MethodNames.IS_GREATER_THAN, expectedMatcher = CallMatcher.anyOf(IS_EQUAL_TO_INT, IS_GREATER_THAN_OR_EQUAL_TO_INT), replaceFromOriginalMethod = true,
|
||||||
|
additionalCondition = ARG_IS_PLUS_ONE_CONST
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
MethodNames.IS_GREATER_THAN, expectedMatcher = IS_GREATER_THAN_INT, replaceFromOriginalMethod = true,
|
||||||
|
additionalCondition = ARG_IS_ZERO_CONST
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
MethodNames.IS_GREATER_THAN, expectedMatcher = CallMatcher.anyOf(IS_POSITIVE, IS_ONE), replaceFromOriginalMethod = true
|
||||||
|
),
|
||||||
|
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
MethodNames.IS_LESS_THAN_OR_EQUAL_TO, expectedMatcher = IS_LESS_THAN_OR_EQUAL_TO_INT, replaceFromOriginalMethod = true,
|
||||||
|
additionalCondition = ARG_IS_ZERO_CONST
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
MethodNames.IS_LESS_THAN_OR_EQUAL_TO, expectedMatcher = CallMatcher.anyOf(IS_NOT_EQUAL_TO_INT, IS_LESS_THAN_INT), replaceFromOriginalMethod = true,
|
||||||
|
additionalCondition = ARG_IS_PLUS_ONE_CONST
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
MethodNames.IS_LESS_THAN_OR_EQUAL_TO, expectedMatcher = IS_NOT_POSITIVE, replaceFromOriginalMethod = true
|
||||||
|
),
|
||||||
|
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
MethodNames.IS_LESS_THAN, expectedMatcher = CallMatcher.anyOf(IS_EQUAL_TO_INT, IS_LESS_THAN_OR_EQUAL_TO_INT), replaceFromOriginalMethod = true,
|
||||||
|
additionalCondition = ARG_IS_MINUS_ONE_CONST
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
MethodNames.IS_LESS_THAN, expectedMatcher = IS_LESS_THAN_INT, replaceFromOriginalMethod = true,
|
||||||
|
additionalCondition = ARG_IS_ZERO_CONST
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
COMPARABLE_COMPARE_TO,
|
||||||
|
MethodNames.IS_LESS_THAN, expectedMatcher = IS_NEGATIVE, replaceFromOriginalMethod = true
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getDisplayName() = DISPLAY_NAME
|
||||||
|
|
||||||
|
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
|
||||||
|
return object : JavaElementVisitor() {
|
||||||
|
override fun visitExpressionStatement(statement: PsiExpressionStatement) {
|
||||||
|
super.visitExpressionStatement(statement)
|
||||||
|
createInspectionsForMappings(statement, holder, MAPPINGS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+52
-20
@@ -1,13 +1,9 @@
|
|||||||
package de.platon42.intellij.plugins.cajon.inspections
|
package de.platon42.intellij.plugins.cajon.inspections
|
||||||
|
|
||||||
import com.intellij.codeInspection.ProblemsHolder
|
import com.intellij.codeInspection.ProblemsHolder
|
||||||
import com.intellij.psi.CommonClassNames
|
import com.intellij.psi.*
|
||||||
import com.intellij.psi.JavaElementVisitor
|
|
||||||
import com.intellij.psi.PsiElementVisitor
|
|
||||||
import com.intellij.psi.PsiExpressionStatement
|
|
||||||
import com.siyeh.ig.callMatcher.CallMatcher
|
import com.siyeh.ig.callMatcher.CallMatcher
|
||||||
import de.platon42.intellij.plugins.cajon.AssertJClassNames
|
import de.platon42.intellij.plugins.cajon.*
|
||||||
import de.platon42.intellij.plugins.cajon.MethodNames
|
|
||||||
|
|
||||||
|
|
||||||
class AssertThatFileExpressionInspection : AbstractMoveOutInspection() {
|
class AssertThatFileExpressionInspection : AbstractMoveOutInspection() {
|
||||||
@@ -15,61 +11,94 @@ class AssertThatFileExpressionInspection : AbstractMoveOutInspection() {
|
|||||||
companion object {
|
companion object {
|
||||||
private const val DISPLAY_NAME = "Asserting a file specific expression"
|
private const val DISPLAY_NAME = "Asserting a file specific expression"
|
||||||
|
|
||||||
|
private val ARG_IS_ZERO_CONST: (PsiExpressionStatement, PsiMethodCallExpression) -> Boolean = { _, call -> call.firstArg.calculateConstantValue() == 0 }
|
||||||
|
private val ARG_IS_NOT_ZERO_CONST: (PsiExpressionStatement, PsiMethodCallExpression) -> Boolean = { _, call ->
|
||||||
|
val constant =
|
||||||
|
call.firstArg.calculateConstantValue()
|
||||||
|
(constant != null) && (constant != 0)
|
||||||
|
}
|
||||||
|
|
||||||
private val MAPPINGS = listOf(
|
private val MAPPINGS = listOf(
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "canRead"),
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "canRead").parameterCount(0),
|
||||||
"canRead", expectBoolean = true
|
"canRead", expectBoolean = true
|
||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "canWrite"),
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "canWrite").parameterCount(0),
|
||||||
"canWrite", expectBoolean = true
|
"canWrite", expectBoolean = true
|
||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "exists"),
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "exists").parameterCount(0),
|
||||||
"exists", "doesNotExist", expectBoolean = true
|
"exists", "doesNotExist", expectBoolean = true
|
||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "isAbsolute"),
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "isAbsolute").parameterCount(0),
|
||||||
"isAbsolute", "isRelative", expectBoolean = true
|
"isAbsolute", "isRelative", expectBoolean = true
|
||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "isDirectory"),
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "isDirectory").parameterCount(0),
|
||||||
"isDirectory", expectBoolean = true
|
"isDirectory", expectBoolean = true
|
||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "isFile"),
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "isFile").parameterCount(0),
|
||||||
"isFile", expectBoolean = true
|
"isFile", expectBoolean = true
|
||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "getName"),
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "getName").parameterCount(0),
|
||||||
"hasName",
|
"hasName",
|
||||||
expectedMatcher = CallMatcher.anyOf(IS_EQUAL_TO_OBJECT, IS_EQUAL_TO_STRING)
|
expectedMatcher = CallMatcher.anyOf(IS_EQUAL_TO_OBJECT, IS_EQUAL_TO_STRING)
|
||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "getParent", "getParentFile"),
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "getParent", "getParentFile").parameterCount(0),
|
||||||
"hasNoParent", expectNullNonNull = true
|
"hasNoParent", expectNullNonNull = true
|
||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "getParent"),
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "getParent").parameterCount(0),
|
||||||
"hasParent",
|
"hasParent",
|
||||||
expectedMatcher = CallMatcher.anyOf(IS_EQUAL_TO_OBJECT, IS_EQUAL_TO_STRING)
|
expectedMatcher = CallMatcher.anyOf(IS_EQUAL_TO_OBJECT, IS_EQUAL_TO_STRING)
|
||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "getParentFile"),
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "getParentFile").parameterCount(0),
|
||||||
"hasParent",
|
"hasParent",
|
||||||
expectedMatcher = IS_EQUAL_TO_OBJECT
|
expectedMatcher = IS_EQUAL_TO_OBJECT
|
||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "list", "listFiles"),
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "list", "listFiles").parameterCount(0),
|
||||||
"isEmptyDirectory",
|
"isEmptyDirectory",
|
||||||
expectedMatcher = CallMatcher.instanceCall(AssertJClassNames.ABSTRACT_OBJECT_ARRAY_ASSERT_CLASSNAME, MethodNames.IS_EMPTY)
|
expectedMatcher = CallMatcher.instanceCall(AssertJClassNames.ABSTRACT_OBJECT_ARRAY_ASSERT_CLASSNAME, MethodNames.IS_EMPTY)
|
||||||
.parameterCount(0)!!
|
.parameterCount(0)
|
||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "list", "listFiles"),
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "list", "listFiles").parameterCount(0),
|
||||||
"isNotEmptyDirectory",
|
"isNotEmptyDirectory",
|
||||||
expectedMatcher = CallMatcher.instanceCall(AssertJClassNames.ABSTRACT_OBJECT_ARRAY_ASSERT_CLASSNAME, MethodNames.IS_NOT_EMPTY)
|
expectedMatcher = CallMatcher.instanceCall(AssertJClassNames.ABSTRACT_OBJECT_ARRAY_ASSERT_CLASSNAME, MethodNames.IS_NOT_EMPTY)
|
||||||
.parameterCount(0)!!
|
.parameterCount(0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
private val MAPPINGS_SINCE_ASSERTJ_3_14_0 = listOf(
|
||||||
|
MoveOutMapping(
|
||||||
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "length").parameterCount(0),
|
||||||
|
"isEmpty", expectedMatcher = IS_ZERO_LONG, noExpectedExpression = true
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "length").parameterCount(0),
|
||||||
|
"isEmpty", expectedMatcher = IS_EQUAL_TO_LONG, noExpectedExpression = true,
|
||||||
|
additionalCondition = ARG_IS_ZERO_CONST
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "length").parameterCount(0),
|
||||||
|
"isNotEmpty", expectedMatcher = IS_NOT_ZERO_LONG, noExpectedExpression = true
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "length").parameterCount(0),
|
||||||
|
"isNotEmpty", expectedMatcher = IS_NOT_EQUAL_TO_LONG, noExpectedExpression = true,
|
||||||
|
additionalCondition = ARG_IS_ZERO_CONST
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
CallMatcher.instanceCall(CommonClassNames.JAVA_IO_FILE, "length").parameterCount(0),
|
||||||
|
"hasSize", expectedMatcher = IS_EQUAL_TO_LONG,
|
||||||
|
additionalCondition = ARG_IS_NOT_ZERO_CONST
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -81,6 +110,9 @@ class AssertThatFileExpressionInspection : AbstractMoveOutInspection() {
|
|||||||
override fun visitExpressionStatement(statement: PsiExpressionStatement) {
|
override fun visitExpressionStatement(statement: PsiExpressionStatement) {
|
||||||
super.visitExpressionStatement(statement)
|
super.visitExpressionStatement(statement)
|
||||||
createInspectionsForMappings(statement, holder, MAPPINGS)
|
createInspectionsForMappings(statement, holder, MAPPINGS)
|
||||||
|
if (hasAssertJMethod(statement, AssertJClassNames.ABSTRACT_FILE_ASSERT_CLASSNAME, MethodNames.HAS_SIZE)) {
|
||||||
|
createInspectionsForMappings(statement, holder, MAPPINGS_SINCE_ASSERTJ_3_14_0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
package de.platon42.intellij.plugins.cajon.inspections
|
||||||
|
|
||||||
|
import com.intellij.codeInspection.ProblemsHolder
|
||||||
|
import com.intellij.psi.JavaElementVisitor
|
||||||
|
import com.intellij.psi.PsiElementVisitor
|
||||||
|
import com.intellij.psi.PsiExpressionStatement
|
||||||
|
import com.siyeh.ig.callMatcher.CallMatcher
|
||||||
|
|
||||||
|
|
||||||
|
class AssertThatPathExpressionInspection : AbstractMoveOutInspection() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val DISPLAY_NAME = "Asserting a path specific expression"
|
||||||
|
private const val JAVA_NIO_PATH = "java.nio.file.Path"
|
||||||
|
|
||||||
|
private val MAPPINGS = listOf(
|
||||||
|
MoveOutMapping(
|
||||||
|
CallMatcher.instanceCall(JAVA_NIO_PATH, "isAbsolute").parameterCount(0),
|
||||||
|
"isAbsolute", "isRelative", expectBoolean = true
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
CallMatcher.instanceCall(JAVA_NIO_PATH, "startsWith").parameterTypes(JAVA_NIO_PATH),
|
||||||
|
"startsWithRaw", expectBoolean = true
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
CallMatcher.instanceCall(JAVA_NIO_PATH, "endsWith").parameterTypes(JAVA_NIO_PATH),
|
||||||
|
"endsWithRaw", expectBoolean = true
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
CallMatcher.instanceCall(JAVA_NIO_PATH, "getParent").parameterCount(0),
|
||||||
|
"hasParentRaw",
|
||||||
|
expectedMatcher = IS_EQUAL_TO_OBJECT
|
||||||
|
),
|
||||||
|
MoveOutMapping(
|
||||||
|
CallMatcher.instanceCall(JAVA_NIO_PATH, "getParent").parameterCount(0),
|
||||||
|
"hasNoParentRaw", expectNullNonNull = true
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getDisplayName() = DISPLAY_NAME
|
||||||
|
|
||||||
|
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
|
||||||
|
return object : JavaElementVisitor() {
|
||||||
|
override fun visitExpressionStatement(statement: PsiExpressionStatement) {
|
||||||
|
super.visitExpressionStatement(statement)
|
||||||
|
createInspectionsForMappings(statement, holder, MAPPINGS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-2
@@ -57,10 +57,10 @@ class AssertThatSizeInspection : AbstractAssertJInspection() {
|
|||||||
} else {
|
} else {
|
||||||
val isTestForEmpty = ((IS_LESS_THAN_OR_EQUAL_TO_INT.test(expression) && (constValue == 0))
|
val isTestForEmpty = ((IS_LESS_THAN_OR_EQUAL_TO_INT.test(expression) && (constValue == 0))
|
||||||
|| (IS_LESS_THAN_INT.test(expression) && (constValue == 1))
|
|| (IS_LESS_THAN_INT.test(expression) && (constValue == 1))
|
||||||
|| IS_ZERO.test(expression))
|
|| IS_ZERO_INT.test(expression))
|
||||||
val isTestForNotEmpty = ((IS_GREATER_THAN_INT.test(expression) && (constValue == 0))
|
val isTestForNotEmpty = ((IS_GREATER_THAN_INT.test(expression) && (constValue == 0))
|
||||||
|| (IS_GREATER_THAN_OR_EQUAL_TO_INT.test(expression) && (constValue == 1))
|
|| (IS_GREATER_THAN_OR_EQUAL_TO_INT.test(expression) && (constValue == 1))
|
||||||
|| IS_NOT_ZERO.test(expression))
|
|| IS_NOT_ZERO_INT.test(expression))
|
||||||
if ((isTestForEmpty && isLastExpression) || isTestForNotEmpty) {
|
if ((isTestForEmpty && isLastExpression) || isTestForNotEmpty) {
|
||||||
val replacementMethod = isTestForEmpty.map(MethodNames.IS_EMPTY, MethodNames.IS_NOT_EMPTY)
|
val replacementMethod = isTestForEmpty.map(MethodNames.IS_EMPTY, MethodNames.IS_NOT_EMPTY)
|
||||||
return Match(expression, replacementMethod, noExpectedExpression = true)
|
return Match(expression, replacementMethod, noExpectedExpression = true)
|
||||||
|
|||||||
+4
-4
@@ -60,7 +60,7 @@ class AssertThatStringExpressionInspection : AbstractMoveOutInspection() {
|
|||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
STRING_COMPARE_TO_IGNORE_CASE,
|
STRING_COMPARE_TO_IGNORE_CASE,
|
||||||
MethodNames.IS_EQUAL_TO_IC, expectedMatcher = IS_ZERO, replaceFromOriginalMethod = true
|
MethodNames.IS_EQUAL_TO_IC, expectedMatcher = IS_ZERO_INT, replaceFromOriginalMethod = true
|
||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
STRING_COMPARE_TO_IGNORE_CASE,
|
STRING_COMPARE_TO_IGNORE_CASE,
|
||||||
@@ -69,7 +69,7 @@ class AssertThatStringExpressionInspection : AbstractMoveOutInspection() {
|
|||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
STRING_COMPARE_TO_IGNORE_CASE,
|
STRING_COMPARE_TO_IGNORE_CASE,
|
||||||
MethodNames.IS_NOT_EQUAL_TO_IC, expectedMatcher = IS_NOT_ZERO, replaceFromOriginalMethod = true
|
MethodNames.IS_NOT_EQUAL_TO_IC, expectedMatcher = IS_NOT_ZERO_INT, replaceFromOriginalMethod = true
|
||||||
),
|
),
|
||||||
|
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
@@ -79,7 +79,7 @@ class AssertThatStringExpressionInspection : AbstractMoveOutInspection() {
|
|||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
STRING_INDEX_OF,
|
STRING_INDEX_OF,
|
||||||
MethodNames.STARTS_WITH, expectedMatcher = IS_ZERO, replaceFromOriginalMethod = true
|
MethodNames.STARTS_WITH, expectedMatcher = IS_ZERO_INT, replaceFromOriginalMethod = true
|
||||||
),
|
),
|
||||||
|
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
@@ -89,7 +89,7 @@ class AssertThatStringExpressionInspection : AbstractMoveOutInspection() {
|
|||||||
),
|
),
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
STRING_INDEX_OF,
|
STRING_INDEX_OF,
|
||||||
MethodNames.DOES_NOT_START_WITH, expectedMatcher = IS_NOT_ZERO, replaceFromOriginalMethod = true
|
MethodNames.DOES_NOT_START_WITH, expectedMatcher = IS_NOT_ZERO_INT, replaceFromOriginalMethod = true
|
||||||
),
|
),
|
||||||
|
|
||||||
MoveOutMapping(
|
MoveOutMapping(
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@ class MoveOutMethodCallExpressionQuickFix(
|
|||||||
val expectedExpression = createExpectedMethodCall(
|
val expectedExpression = createExpectedMethodCall(
|
||||||
it,
|
it,
|
||||||
replacementMethod,
|
replacementMethod,
|
||||||
*if (replaceFromOriginalMethod) arrayOf(assertExpressionArg!!) else it.argumentList.expressions
|
*if (replaceFromOriginalMethod || noExpectedExpression) listOfNotNull(assertExpressionArg).toTypedArray() else it.argumentList.expressions
|
||||||
)
|
)
|
||||||
expectedExpression.replaceQualifierFromMethodCall(it)
|
expectedExpression.replaceQualifierFromMethodCall(it)
|
||||||
it.replace(expectedExpression)
|
it.replace(expectedExpression)
|
||||||
|
|||||||
@@ -41,12 +41,16 @@
|
|||||||
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatBinaryExpressionInspection"/>
|
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatBinaryExpressionInspection"/>
|
||||||
<localInspection groupPath="Java" shortName="AssertThatObjectExpression" enabledByDefault="true" level="WARNING"
|
<localInspection groupPath="Java" shortName="AssertThatObjectExpression" enabledByDefault="true" level="WARNING"
|
||||||
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatObjectExpressionInspection"/>
|
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatObjectExpressionInspection"/>
|
||||||
|
<localInspection groupPath="Java" shortName="AssertThatComparable" enabledByDefault="true" level="WARNING"
|
||||||
|
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatComparableInspection"/>
|
||||||
<localInspection groupPath="Java" shortName="AssertThatStringExpression" enabledByDefault="true" level="WARNING"
|
<localInspection groupPath="Java" shortName="AssertThatStringExpression" enabledByDefault="true" level="WARNING"
|
||||||
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatStringExpressionInspection"/>
|
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatStringExpressionInspection"/>
|
||||||
<localInspection groupPath="Java" shortName="AssertThatCollectionOrMapExpression" enabledByDefault="true" level="WARNING"
|
<localInspection groupPath="Java" shortName="AssertThatCollectionOrMapExpression" enabledByDefault="true" level="WARNING"
|
||||||
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatCollectionOrMapExpressionInspection"/>
|
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatCollectionOrMapExpressionInspection"/>
|
||||||
<localInspection groupPath="Java" shortName="AssertThatFileExpression" enabledByDefault="true" level="WARNING"
|
<localInspection groupPath="Java" shortName="AssertThatFileExpression" enabledByDefault="true" level="WARNING"
|
||||||
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatFileExpressionInspection"/>
|
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatFileExpressionInspection"/>
|
||||||
|
<localInspection groupPath="Java" shortName="AssertThatPathExpression" enabledByDefault="true" level="WARNING"
|
||||||
|
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatPathExpressionInspection"/>
|
||||||
|
|
||||||
<localInspection groupPath="Java" shortName="JoinAssertThatStatements" enabledByDefault="true" level="WARNING"
|
<localInspection groupPath="Java" shortName="JoinAssertThatStatements" enabledByDefault="true" level="WARNING"
|
||||||
implementationClass="de.platon42.intellij.plugins.cajon.inspections.JoinAssertThatStatementsInspection"/>
|
implementationClass="de.platon42.intellij.plugins.cajon.inspections.JoinAssertThatStatementsInspection"/>
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
Turns assertThat(obj1.compareTo(obj2)) into assertThat(obj1).someMethod(obj2).
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
Operates on assertions on objects of type Path. Turns assertThat(file.someMethod(arg)).someAssertion() into assertThat(path).someMethod(arg).
|
||||||
|
<!-- tooltip end -->
|
||||||
|
<br>someMethod() can be isAbsolute(), getParent(), startsWith() and endsWith().
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package de.platon42.intellij.plugins.cajon.inspections
|
||||||
|
|
||||||
|
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
|
||||||
|
import de.platon42.intellij.jupiter.MyFixture
|
||||||
|
import de.platon42.intellij.jupiter.TestDataSubPath
|
||||||
|
import de.platon42.intellij.plugins.cajon.AbstractCajonTest
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
internal class AssertThatComparableInspectionTest : AbstractCajonTest() {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestDataSubPath("inspections/Comparable")
|
||||||
|
internal fun assertThat_with_compareTo_method(@MyFixture myFixture: JavaCodeInsightTestFixture) {
|
||||||
|
myFixture.enableInspections(AssertThatComparableInspection::class.java)
|
||||||
|
myFixture.configureByFile("ComparableBefore.java")
|
||||||
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove compareTo() of actual expression and use assertThat().isEqualByComparingTo() instead"), 2)
|
||||||
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove compareTo() of actual expression and use assertThat().isNotEqualByComparingTo() instead"), 2)
|
||||||
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove compareTo() of actual expression and use assertThat().isGreaterThanOrEqualTo() instead"), 4)
|
||||||
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove compareTo() of actual expression and use assertThat().isGreaterThan() instead"), 5)
|
||||||
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove compareTo() of actual expression and use assertThat().isLessThanOrEqualTo() instead"), 4)
|
||||||
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove compareTo() of actual expression and use assertThat().isLessThan() instead"), 4)
|
||||||
|
myFixture.checkResultByFile("ComparableAfter.java")
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -30,6 +30,9 @@ internal class AssertThatFileExpressionInspectionTest : AbstractCajonTest() {
|
|||||||
executeQuickFixes(myFixture, Regex.fromLiteral("Remove listFiles() of actual expression and use assertThat().isNotEmptyDirectory() instead"), 1)
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove listFiles() of actual expression and use assertThat().isNotEmptyDirectory() instead"), 1)
|
||||||
executeQuickFixes(myFixture, Regex.fromLiteral("Remove list() of actual expression and use assertThat().isEmptyDirectory() instead"), 1)
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove list() of actual expression and use assertThat().isEmptyDirectory() instead"), 1)
|
||||||
executeQuickFixes(myFixture, Regex.fromLiteral("Remove list() of actual expression and use assertThat().isNotEmptyDirectory() instead"), 1)
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove list() of actual expression and use assertThat().isNotEmptyDirectory() instead"), 1)
|
||||||
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove length() of actual expression and use assertThat().isEmpty() instead"), 2)
|
||||||
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove length() of actual expression and use assertThat().isNotEmpty() instead"), 2)
|
||||||
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove length() of actual expression and use assertThat().hasSize() instead"), 1)
|
||||||
myFixture.checkResultByFile("FileExpressionAfter.java")
|
myFixture.checkResultByFile("FileExpressionAfter.java")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package de.platon42.intellij.plugins.cajon.inspections
|
||||||
|
|
||||||
|
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
|
||||||
|
import de.platon42.intellij.jupiter.MyFixture
|
||||||
|
import de.platon42.intellij.jupiter.TestDataSubPath
|
||||||
|
import de.platon42.intellij.plugins.cajon.AbstractCajonTest
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
internal class AssertThatPathExpressionInspectionTest : AbstractCajonTest() {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestDataSubPath("inspections/PathExpression")
|
||||||
|
internal fun assertThat_with_certain_Path_methods(@MyFixture myFixture: JavaCodeInsightTestFixture) {
|
||||||
|
myFixture.enableInspections(AssertThatPathExpressionInspection::class.java)
|
||||||
|
myFixture.configureByFile("PathExpressionBefore.java")
|
||||||
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove isAbsolute() of actual expression and use assertThat().isAbsolute() instead"), 3)
|
||||||
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove isAbsolute() of actual expression and use assertThat().isRelative() instead"), 3)
|
||||||
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove startsWith() of actual expression and use assertThat().startsWithRaw() instead"), 3)
|
||||||
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove endsWith() of actual expression and use assertThat().endsWithRaw() instead"), 3)
|
||||||
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove getParent() of actual expression and use assertThat().hasNoParentRaw() instead"), 2)
|
||||||
|
executeQuickFixes(myFixture, Regex.fromLiteral("Remove getParent() of actual expression and use assertThat().hasParentRaw() instead"), 1)
|
||||||
|
myFixture.checkResultByFile("PathExpressionAfter.java")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.fail;
|
||||||
|
|
||||||
|
public class CompareTo {
|
||||||
|
|
||||||
|
private void comparable() {
|
||||||
|
String string = "string";
|
||||||
|
assertThat(string).isEqualByComparingTo("foo");
|
||||||
|
assertThat(string).isEqualByComparingTo("foo");
|
||||||
|
|
||||||
|
assertThat(string).isNotEqualByComparingTo("foo");
|
||||||
|
assertThat(string).isNotEqualByComparingTo("foo");
|
||||||
|
|
||||||
|
assertThat(string).isGreaterThanOrEqualTo("foo");
|
||||||
|
assertThat(string).isGreaterThanOrEqualTo("foo");
|
||||||
|
assertThat(string).isGreaterThanOrEqualTo("foo");
|
||||||
|
assertThat(string).isGreaterThanOrEqualTo("foo");
|
||||||
|
|
||||||
|
assertThat(string).isGreaterThan("foo");
|
||||||
|
assertThat(string).isGreaterThan("foo");
|
||||||
|
assertThat(string).isGreaterThan("foo");
|
||||||
|
assertThat(string).isGreaterThan("foo");
|
||||||
|
assertThat(string).isGreaterThan("foo");
|
||||||
|
|
||||||
|
assertThat(string).isLessThanOrEqualTo("foo");
|
||||||
|
assertThat(string).isLessThanOrEqualTo("foo");
|
||||||
|
assertThat(string).isLessThanOrEqualTo("foo");
|
||||||
|
assertThat(string).isLessThanOrEqualTo("foo");
|
||||||
|
|
||||||
|
assertThat(string).isLessThan("foo");
|
||||||
|
assertThat(string).isLessThan("foo");
|
||||||
|
assertThat(string).isLessThan("foo");
|
||||||
|
assertThat(string).isLessThan("foo");
|
||||||
|
|
||||||
|
assertThat(string.compareTo("foo")).isNotEqualTo(2);
|
||||||
|
assertThat(string.compareTo("foo")).isEqualTo(2);
|
||||||
|
|
||||||
|
org.junit.Assert.assertThat(string, null);
|
||||||
|
fail("oh no!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.fail;
|
||||||
|
|
||||||
|
public class CompareTo {
|
||||||
|
|
||||||
|
private void comparable() {
|
||||||
|
String string = "string";
|
||||||
|
assertThat(string.compareTo("foo")).isEqualTo(0);
|
||||||
|
assertThat(string.compareTo("foo")).isZero();
|
||||||
|
|
||||||
|
assertThat(string.compareTo("foo")).isNotEqualTo(0);
|
||||||
|
assertThat(string.compareTo("foo")).isNotZero();
|
||||||
|
|
||||||
|
assertThat(string.compareTo("foo")).isNotEqualTo(-1);
|
||||||
|
assertThat(string.compareTo("foo")).isGreaterThanOrEqualTo(0);
|
||||||
|
assertThat(string.compareTo("foo")).isGreaterThan(-1);
|
||||||
|
assertThat(string.compareTo("foo")).isNotNegative();
|
||||||
|
|
||||||
|
assertThat(string.compareTo("foo")).isEqualTo(1);
|
||||||
|
assertThat(string.compareTo("foo")).isOne();
|
||||||
|
assertThat(string.compareTo("foo")).isGreaterThan(0);
|
||||||
|
assertThat(string.compareTo("foo")).isPositive();
|
||||||
|
assertThat(string.compareTo("foo")).isGreaterThanOrEqualTo(1);
|
||||||
|
|
||||||
|
assertThat(string.compareTo("foo")).isNotEqualTo(1);
|
||||||
|
assertThat(string.compareTo("foo")).isLessThanOrEqualTo(0);
|
||||||
|
assertThat(string.compareTo("foo")).isLessThan(1);
|
||||||
|
assertThat(string.compareTo("foo")).isNotPositive();
|
||||||
|
|
||||||
|
assertThat(string.compareTo("foo")).isEqualTo(-1);
|
||||||
|
assertThat(string.compareTo("foo")).isLessThan(0);
|
||||||
|
assertThat(string.compareTo("foo")).isNegative();
|
||||||
|
assertThat(string.compareTo("foo")).isLessThanOrEqualTo(-1);
|
||||||
|
|
||||||
|
assertThat(string.compareTo("foo")).isNotEqualTo(2);
|
||||||
|
assertThat(string.compareTo("foo")).isEqualTo(2);
|
||||||
|
|
||||||
|
org.junit.Assert.assertThat(string, null);
|
||||||
|
fail("oh no!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -75,11 +75,22 @@ public class FileExpression {
|
|||||||
assertThat(file.getParentFile()).isNotEqualTo(null);
|
assertThat(file.getParentFile()).isNotEqualTo(null);
|
||||||
assertThat(file.getParentFile()).isNotNull();
|
assertThat(file.getParentFile()).isNotNull();
|
||||||
|
|
||||||
|
assertThat(file).isEmpty();
|
||||||
|
assertThat(file).isEmpty();
|
||||||
|
assertThat(file).isNotEmpty();
|
||||||
|
assertThat(file).isNotEmpty();
|
||||||
|
assertThat(file).hasSize(2);
|
||||||
|
|
||||||
assertThat(file.listFiles()).isNull();
|
assertThat(file.listFiles()).isNull();
|
||||||
assertThat(file.listFiles()).isNullOrEmpty();
|
assertThat(file.listFiles()).isNullOrEmpty();
|
||||||
assertThat(file).isEmptyDirectory();
|
assertThat(file).isEmptyDirectory();
|
||||||
assertThat(file).isNotEmptyDirectory();
|
assertThat(file).isNotEmptyDirectory();
|
||||||
|
|
||||||
|
assertThat(file.listFiles(f -> f.canExecute())).isNull();
|
||||||
|
assertThat(file.listFiles(f -> f.canExecute())).isNullOrEmpty();
|
||||||
|
assertThat(file.listFiles(f -> f.canExecute())).isEmpty();
|
||||||
|
assertThat(file.listFiles(f -> f.canExecute())).isNotEmpty();
|
||||||
|
|
||||||
assertThat(file.list()).isNull();
|
assertThat(file.list()).isNull();
|
||||||
assertThat(file.list()).isNullOrEmpty();
|
assertThat(file.list()).isNullOrEmpty();
|
||||||
assertThat(file).isEmptyDirectory();
|
assertThat(file).isEmptyDirectory();
|
||||||
|
|||||||
@@ -75,11 +75,22 @@ public class FileExpression {
|
|||||||
assertThat(file.getParentFile()).isNotEqualTo(null);
|
assertThat(file.getParentFile()).isNotEqualTo(null);
|
||||||
assertThat(file.getParentFile()).isNotNull();
|
assertThat(file.getParentFile()).isNotNull();
|
||||||
|
|
||||||
|
assertThat(file.length()).isEqualTo(0);
|
||||||
|
assertThat(file.length()).isZero();
|
||||||
|
assertThat(file.length()).isNotEqualTo(0);
|
||||||
|
assertThat(file.length()).isNotZero();
|
||||||
|
assertThat(file.length()).isEqualTo(2);
|
||||||
|
|
||||||
assertThat(file.listFiles()).isNull();
|
assertThat(file.listFiles()).isNull();
|
||||||
assertThat(file.listFiles()).isNullOrEmpty();
|
assertThat(file.listFiles()).isNullOrEmpty();
|
||||||
assertThat(file.listFiles()).isEmpty();
|
assertThat(file.listFiles()).isEmpty();
|
||||||
assertThat(file.listFiles()).isNotEmpty();
|
assertThat(file.listFiles()).isNotEmpty();
|
||||||
|
|
||||||
|
assertThat(file.listFiles(f -> f.canExecute())).isNull();
|
||||||
|
assertThat(file.listFiles(f -> f.canExecute())).isNullOrEmpty();
|
||||||
|
assertThat(file.listFiles(f -> f.canExecute())).isEmpty();
|
||||||
|
assertThat(file.listFiles(f -> f.canExecute())).isNotEmpty();
|
||||||
|
|
||||||
assertThat(file.list()).isNull();
|
assertThat(file.list()).isNull();
|
||||||
assertThat(file.list()).isNullOrEmpty();
|
assertThat(file.list()).isNullOrEmpty();
|
||||||
assertThat(file.list()).isEmpty();
|
assertThat(file.list()).isEmpty();
|
||||||
|
|||||||
@@ -0,0 +1,126 @@
|
|||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.fail;
|
||||||
|
|
||||||
|
public class PathExpression {
|
||||||
|
|
||||||
|
private void pathExpression() {
|
||||||
|
Path path = Paths.get("foo");
|
||||||
|
Path otherPath = Paths.get("bar");
|
||||||
|
|
||||||
|
assertThat(path).as("foo").isAbsolute();
|
||||||
|
assertThat(path).isAbsolute();
|
||||||
|
assertThat(path).isAbsolute();
|
||||||
|
assertThat(path).as("foo").isRelative();
|
||||||
|
assertThat(path).isRelative();
|
||||||
|
assertThat(path).isRelative();
|
||||||
|
|
||||||
|
assertThat(path).hasParentRaw(otherPath);
|
||||||
|
assertThat(path.getParent()).isNotEqualTo(otherPath);
|
||||||
|
assertThat(path).hasNoParentRaw();
|
||||||
|
assertThat(path).hasNoParentRaw();
|
||||||
|
assertThat(path.getParent()).isNotEqualTo(null);
|
||||||
|
assertThat(path.getParent()).isNotNull();
|
||||||
|
|
||||||
|
assertThat(path).as("foo").startsWithRaw(otherPath);
|
||||||
|
assertThat(path).startsWithRaw(otherPath);
|
||||||
|
assertThat(path).startsWithRaw(otherPath);
|
||||||
|
assertThat(path.startsWith(otherPath)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(path.startsWith(otherPath)).isNotEqualTo(true);
|
||||||
|
assertThat(path.startsWith(otherPath)).isFalse();
|
||||||
|
|
||||||
|
assertThat(path.startsWith("otherPath")).as("foo").isEqualTo(true);
|
||||||
|
assertThat(path.startsWith("otherPath")).isNotEqualTo(false);
|
||||||
|
assertThat(path.startsWith("otherPath")).isTrue();
|
||||||
|
assertThat(path.startsWith("otherPath")).as("foo").isEqualTo(false);
|
||||||
|
assertThat(path.startsWith("otherPath")).isNotEqualTo(true);
|
||||||
|
assertThat(path.startsWith("otherPath")).isFalse();
|
||||||
|
|
||||||
|
assertThat(path).as("foo").endsWithRaw(otherPath);
|
||||||
|
assertThat(path).endsWithRaw(otherPath);
|
||||||
|
assertThat(path).endsWithRaw(otherPath);
|
||||||
|
assertThat(path.endsWith(otherPath)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(path.endsWith(otherPath)).isNotEqualTo(true);
|
||||||
|
assertThat(path.endsWith(otherPath)).isFalse();
|
||||||
|
|
||||||
|
assertThat(path.endsWith("otherPath")).as("foo").isEqualTo(true);
|
||||||
|
assertThat(path.endsWith("otherPath")).isNotEqualTo(false);
|
||||||
|
assertThat(path.endsWith("otherPath")).isTrue();
|
||||||
|
assertThat(path.endsWith("otherPath")).as("foo").isEqualTo(false);
|
||||||
|
assertThat(path.endsWith("otherPath")).isNotEqualTo(true);
|
||||||
|
assertThat(path.endsWith("otherPath")).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.isReadable(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.isReadable(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.isReadable(path)).isTrue();
|
||||||
|
assertThat(Files.isReadable(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.isReadable(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.isReadable(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.isWritable(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.isWritable(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.isWritable(path)).isTrue();
|
||||||
|
assertThat(Files.isWritable(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.isWritable(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.isWritable(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.isExecutable(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.isExecutable(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.isExecutable(path)).isTrue();
|
||||||
|
assertThat(Files.isExecutable(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.isExecutable(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.isExecutable(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.isDirectory(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.isDirectory(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.isDirectory(path)).isTrue();
|
||||||
|
assertThat(Files.isDirectory(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.isDirectory(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.isDirectory(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.isRegularFile(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.isRegularFile(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.isRegularFile(path)).isTrue();
|
||||||
|
assertThat(Files.isRegularFile(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.isRegularFile(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.isRegularFile(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.isSymbolicLink(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.isSymbolicLink(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.isSymbolicLink(path)).isTrue();
|
||||||
|
assertThat(Files.isSymbolicLink(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.isSymbolicLink(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.isSymbolicLink(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.exists(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.exists(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.exists(path)).isTrue();
|
||||||
|
assertThat(Files.exists(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.exists(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.exists(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.notExists(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.notExists(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.notExists(path)).isTrue();
|
||||||
|
assertThat(Files.notExists(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.notExists(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.notExists(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.list(path)).isEmpty();
|
||||||
|
assertThat(Files.list(path)).isNotEmpty();
|
||||||
|
|
||||||
|
assertThat(Files.readAllBytes(path)).isEqualTo(new byte[1]);
|
||||||
|
assertThat(Files.readAllLines(path)).containsExactly("foo");
|
||||||
|
assertThat(Files.lines(path)).containsExactly("foo");
|
||||||
|
|
||||||
|
assertThat(path.getName()).endsWith(".foo"); // could be turned into .hasExtension("foo"), but not always.
|
||||||
|
|
||||||
|
assertThat(path.getName()).as("foo").isEqualTo("foo").as("bar").isEqualTo("bar");
|
||||||
|
|
||||||
|
org.junit.Assert.assertThat(path, null);
|
||||||
|
fail("oh no!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.fail;
|
||||||
|
|
||||||
|
public class PathExpression {
|
||||||
|
|
||||||
|
private void pathExpression() {
|
||||||
|
Path path = Paths.get("foo");
|
||||||
|
Path otherPath = Paths.get("bar");
|
||||||
|
|
||||||
|
assertThat(path.isAbsolute()).as("foo").isEqualTo(true);
|
||||||
|
assertThat(path.isAbsolute()).isNotEqualTo(false);
|
||||||
|
assertThat(path.isAbsolute()).isTrue();
|
||||||
|
assertThat(path.isAbsolute()).as("foo").isEqualTo(false);
|
||||||
|
assertThat(path.isAbsolute()).isNotEqualTo(true);
|
||||||
|
assertThat(path.isAbsolute()).isFalse();
|
||||||
|
|
||||||
|
assertThat(path.getParent()).isEqualTo(otherPath);
|
||||||
|
assertThat(path.getParent()).isNotEqualTo(otherPath);
|
||||||
|
assertThat(path.getParent()).isEqualTo(null);
|
||||||
|
assertThat(path.getParent()).isNull();
|
||||||
|
assertThat(path.getParent()).isNotEqualTo(null);
|
||||||
|
assertThat(path.getParent()).isNotNull();
|
||||||
|
|
||||||
|
assertThat(path.startsWith(otherPath)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(path.startsWith(otherPath)).isNotEqualTo(false);
|
||||||
|
assertThat(path.startsWith(otherPath)).isTrue();
|
||||||
|
assertThat(path.startsWith(otherPath)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(path.startsWith(otherPath)).isNotEqualTo(true);
|
||||||
|
assertThat(path.startsWith(otherPath)).isFalse();
|
||||||
|
|
||||||
|
assertThat(path.startsWith("otherPath")).as("foo").isEqualTo(true);
|
||||||
|
assertThat(path.startsWith("otherPath")).isNotEqualTo(false);
|
||||||
|
assertThat(path.startsWith("otherPath")).isTrue();
|
||||||
|
assertThat(path.startsWith("otherPath")).as("foo").isEqualTo(false);
|
||||||
|
assertThat(path.startsWith("otherPath")).isNotEqualTo(true);
|
||||||
|
assertThat(path.startsWith("otherPath")).isFalse();
|
||||||
|
|
||||||
|
assertThat(path.endsWith(otherPath)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(path.endsWith(otherPath)).isNotEqualTo(false);
|
||||||
|
assertThat(path.endsWith(otherPath)).isTrue();
|
||||||
|
assertThat(path.endsWith(otherPath)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(path.endsWith(otherPath)).isNotEqualTo(true);
|
||||||
|
assertThat(path.endsWith(otherPath)).isFalse();
|
||||||
|
|
||||||
|
assertThat(path.endsWith("otherPath")).as("foo").isEqualTo(true);
|
||||||
|
assertThat(path.endsWith("otherPath")).isNotEqualTo(false);
|
||||||
|
assertThat(path.endsWith("otherPath")).isTrue();
|
||||||
|
assertThat(path.endsWith("otherPath")).as("foo").isEqualTo(false);
|
||||||
|
assertThat(path.endsWith("otherPath")).isNotEqualTo(true);
|
||||||
|
assertThat(path.endsWith("otherPath")).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.isReadable(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.isReadable(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.isReadable(path)).isTrue();
|
||||||
|
assertThat(Files.isReadable(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.isReadable(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.isReadable(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.isWritable(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.isWritable(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.isWritable(path)).isTrue();
|
||||||
|
assertThat(Files.isWritable(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.isWritable(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.isWritable(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.isExecutable(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.isExecutable(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.isExecutable(path)).isTrue();
|
||||||
|
assertThat(Files.isExecutable(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.isExecutable(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.isExecutable(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.isDirectory(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.isDirectory(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.isDirectory(path)).isTrue();
|
||||||
|
assertThat(Files.isDirectory(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.isDirectory(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.isDirectory(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.isRegularFile(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.isRegularFile(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.isRegularFile(path)).isTrue();
|
||||||
|
assertThat(Files.isRegularFile(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.isRegularFile(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.isRegularFile(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.isSymbolicLink(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.isSymbolicLink(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.isSymbolicLink(path)).isTrue();
|
||||||
|
assertThat(Files.isSymbolicLink(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.isSymbolicLink(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.isSymbolicLink(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.exists(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.exists(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.exists(path)).isTrue();
|
||||||
|
assertThat(Files.exists(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.exists(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.exists(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.notExists(path)).as("foo").isEqualTo(true);
|
||||||
|
assertThat(Files.notExists(path)).isNotEqualTo(false);
|
||||||
|
assertThat(Files.notExists(path)).isTrue();
|
||||||
|
assertThat(Files.notExists(path)).as("foo").isEqualTo(false);
|
||||||
|
assertThat(Files.notExists(path)).isNotEqualTo(true);
|
||||||
|
assertThat(Files.notExists(path)).isFalse();
|
||||||
|
|
||||||
|
assertThat(Files.list(path)).isEmpty();
|
||||||
|
assertThat(Files.list(path)).isNotEmpty();
|
||||||
|
|
||||||
|
assertThat(Files.readAllBytes(path)).isEqualTo(new byte[1]);
|
||||||
|
assertThat(Files.readAllLines(path)).containsExactly("foo");
|
||||||
|
assertThat(Files.lines(path)).containsExactly("foo");
|
||||||
|
|
||||||
|
assertThat(path.getName()).endsWith(".foo"); // could be turned into .hasExtension("foo"), but not always.
|
||||||
|
|
||||||
|
assertThat(path.getName()).as("foo").isEqualTo("foo").as("bar").isEqualTo("bar");
|
||||||
|
|
||||||
|
org.junit.Assert.assertThat(path, null);
|
||||||
|
fail("oh no!");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user