-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce assorted AssertJ Refaster templates (#37)
- Loading branch information
Showing
11 changed files
with
204 additions
and
1 deletion.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...e-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJMapTemplates.java
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 @@ | ||
package tech.picnic.errorprone.refastertemplates; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.errorprone.refaster.annotation.AfterTemplate; | ||
import com.google.errorprone.refaster.annotation.BeforeTemplate; | ||
import java.util.Map; | ||
import org.assertj.core.api.AbstractMapAssert; | ||
|
||
final class AssertJMapTemplates { | ||
private AssertJMapTemplates() {} | ||
|
||
static final class AbstractMapAssertContainsExactlyInAnyOrderEntriesOf<K, V> { | ||
@BeforeTemplate | ||
AbstractMapAssert<?, ?, K, V> before(AbstractMapAssert<?, ?, K, V> mapAssert, Map<K, V> map) { | ||
return mapAssert.isEqualTo(map); | ||
} | ||
|
||
@AfterTemplate | ||
AbstractMapAssert<?, ?, K, V> after(AbstractMapAssert<?, ?, K, V> mapAssert, Map<K, V> map) { | ||
return mapAssert.containsExactlyInAnyOrderEntriesOf(map); | ||
} | ||
} | ||
|
||
static final class AbstractMapAssertContainsExactlyEntriesOf<K, V> { | ||
@BeforeTemplate | ||
AbstractMapAssert<?, ?, K, V> before(AbstractMapAssert<?, ?, K, V> mapAssert, K key, V value) { | ||
return mapAssert.containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(key, value)); | ||
} | ||
|
||
@AfterTemplate | ||
AbstractMapAssert<?, ?, K, V> after(AbstractMapAssert<?, ?, K, V> mapAssert, K key, V value) { | ||
return mapAssert.containsExactlyEntriesOf(ImmutableMap.of(key, value)); | ||
} | ||
} | ||
} |
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
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
18 changes: 18 additions & 0 deletions
18
...b/src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJMapTemplatesTestInput.java
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,18 @@ | ||
package tech.picnic.errorprone.bugpatterns; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.assertj.core.api.AbstractMapAssert; | ||
|
||
final class AssertJMapTemplatesTest implements RefasterTemplateTestCase { | ||
AbstractMapAssert<?, ?, Integer, Integer> | ||
testAbstractMapAssertContainsExactlyInAnyOrderEntriesOf() { | ||
return assertThat(ImmutableMap.of(1, 2, 3, 4)).isEqualTo(ImmutableMap.of(1, 2, 3, 4)); | ||
} | ||
|
||
AbstractMapAssert<?, ?, Integer, Integer> testAbstractMapAssertContainsExactlyEntriesOf() { | ||
return assertThat(ImmutableMap.of(1, 2)) | ||
.containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(1, 2)); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../src/test/resources/tech/picnic/errorprone/bugpatterns/AssertJMapTemplatesTestOutput.java
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,18 @@ | ||
package tech.picnic.errorprone.bugpatterns; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.assertj.core.api.AbstractMapAssert; | ||
|
||
final class AssertJMapTemplatesTest implements RefasterTemplateTestCase { | ||
AbstractMapAssert<?, ?, Integer, Integer> | ||
testAbstractMapAssertContainsExactlyInAnyOrderEntriesOf() { | ||
return assertThat(ImmutableMap.of(1, 2, 3, 4)) | ||
.containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(1, 2, 3, 4)); | ||
} | ||
|
||
AbstractMapAssert<?, ?, Integer, Integer> testAbstractMapAssertContainsExactlyEntriesOf() { | ||
return assertThat(ImmutableMap.of(1, 2)).containsExactlyEntriesOf(ImmutableMap.of(1, 2)); | ||
} | ||
} |
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
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