-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from unv-unv/assertj-inspection-update
AssertJ inspection update
- Loading branch information
Showing
4 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
plugin/src/main/resources/inspectionDescriptions/AssertJAssertionsConverter.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<html> | ||
<body> | ||
Reports calls to <code>Assert.assertEquals()</code>, <code>Assert.assertTrue()</code>, etc. methods | ||
which can be migrated to AssertJ's self-describing <code>Assertions.assertThat()</code> chain calls. | ||
<p>For example:</p> | ||
<pre><code lang="java"> | ||
public class SubstantialTest { | ||
@Test | ||
public void test() { | ||
assertTrue("Foobar" instanceof String); | ||
assertFalse(new HashMap().size() > 1); | ||
assertEquals("foo", "foobar".substring(0, 3)); | ||
assertNull(null, "Null must be null"); | ||
assertNotNull(new Object()); | ||
} | ||
} | ||
</code></pre> | ||
<p>A quick-fix is provided to perform the migration:</p> | ||
<pre><code lang="java"> | ||
public class SubstantialTest { | ||
@Test | ||
public void testContents(Collection<String> c, String s) { | ||
assertThat("Foobar").isInstanceOf(String.class); | ||
assertThat(new HashMap()).hasSizeLessThanOrEqualTo(1); | ||
assertThat("foobar".substring(0, 3)).isEqualTo("foo"); | ||
assertThat(null).as("Null must be null").isNull(); | ||
assertThat(new Object()).isNotNull(); | ||
} | ||
} | ||
</code></pre> | ||
<!-- tooltip end --> | ||
<p>This inspection requires that the AssertJ library is available on the classpath. | ||
<p>Use the <b>Statically import AssertJ's methods</b> option to specify if you want the quick-fix to statically import the AssertJ methods. | ||
</body> | ||
</html> |
44 changes: 44 additions & 0 deletions
44
plugin/src/test/resources/AssertJAssertionsConverterInspection.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
assertEquals("foo", "foobar".substring(0, 3)); | ||
assertEquals("foo", "foobar".substring(0, 3), "Strings should be empty"); | ||
|
||
assertArrayEquals(new int[]{1, 2, 3}, new int[]{1, 2, 3}); | ||
assertArrayEquals(new int[]{1, 2, 3}, new int[]{1, 2, 3}, "Arrays should be equal"); | ||
|
||
assertNotEquals(new Object(), new Object()); | ||
assertNotEquals(new Object(), new Object(), "Objects should be non-equal"); | ||
|
||
assertEquals(0, new HashSet().size()); | ||
assertEquals(0, new HashSet().size(), "Set should have zero size"); | ||
|
||
int x = 5; | ||
assertFalse(x == 0); | ||
assertFalse(x == 0, "X should not be empty"); | ||
assertTrue(x != 0); | ||
assertTrue(x > 0); | ||
assertTrue(x >= 0); | ||
assertFalse(x < 0); | ||
assertFalse(x <= 0); | ||
|
||
assertTrue("Foobar" instanceof String); | ||
assertTrue("Foobar" instanceof String, "Expecting String"); | ||
|
||
assertTrue(new HashSet().isEmpty()); | ||
assertTrue(new ArrayList().isEmpty()); | ||
assertTrue(new HashMap().isEmpty()); | ||
assertTrue(new HashMap().isEmpty(), "Map should be empty"); | ||
|
||
assertTrue(new HashSet().size() == 0); | ||
assertTrue(new HashSet().size() == 0, "Set should have zero size"); | ||
assertFalse(new ArrayList().size() > 1); | ||
assertFalse(new ArrayList().size() >= 1); | ||
assertTrue(new HashMap().size() < 1); | ||
assertTrue(new HashMap().size() <= 1); | ||
|
||
assertNull((Object) null); | ||
assertNull((Object) null, "Should be null"); | ||
|
||
assertNotNull(new Object()); | ||
assertNotNull(new Object(), "Should not be null"); | ||
|
||
assertThrows(RuntimeException.class, () -> { throw new RuntimeException();}); | ||
assertThrows(RuntimeException.class, () -> { throw new RuntimeException();}, "Should throw RuntimeException"); |