Fixed a lapsuus in AssertThatFileExpression also transforming listFiles() with a filter argument.

This commit is contained in:
Chris Hodges 2019-11-17 17:14:28 +01:00
parent 2f0d855d1e
commit 8d03b3734c
5 changed files with 29 additions and 23 deletions

View File

@ -642,6 +642,9 @@ Feel free to use the code (in package ```de.platon42.intellij.jupiter```) for yo
## Changelog ## Changelog
#### V1.7 (unreleased)
- Fixed a lapsuus in AssertThatFileExpression also transforming ```.listFiles()``` with a filter argument.
#### 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.

View File

@ -7,7 +7,7 @@ plugins {
} }
group 'de.platon42' group 'de.platon42'
version '1.6' version '1.7'
repositories { repositories {
mavenCentral() mavenCentral()
@ -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,9 @@ intellij {
patchPluginXml { patchPluginXml {
changeNotes """ changeNotes """
<h4>V1.6 (30-Sep-19)</h4> <h4>V1.7 (unreleased)</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 &gt;12h a day and then do some more stuff at home.
<li>Fixed a bug in AssertThatBinaryExpression inspection for assertThat(null != expression) and related
that would not correctly invert the condition on transformation.
<li>Added new AssertThatFileExpression to move out many common methods from inside the
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>
""" """

View File

@ -17,56 +17,56 @@ class AssertThatFileExpressionInspection : AbstractMoveOutInspection() {
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)!!

View File

@ -80,6 +80,11 @@ public class FileExpression {
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();

View File

@ -80,6 +80,11 @@ public class FileExpression {
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();