-
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
AssertJComparableTemplates
and AssertJPrimitiveTemplates
(
#225)
- Loading branch information
1 parent
bfc951b
commit 8e7d04a
Showing
7 changed files
with
517 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
...ib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplates.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,92 @@ | ||
package tech.picnic.errorprone.refastertemplates; | ||
|
||
import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.google.errorprone.refaster.annotation.AfterTemplate; | ||
import com.google.errorprone.refaster.annotation.BeforeTemplate; | ||
import com.google.errorprone.refaster.annotation.UseImportPolicy; | ||
import org.assertj.core.api.AbstractComparableAssert; | ||
import org.assertj.core.api.AbstractIntegerAssert; | ||
|
||
final class AssertJComparableTemplates { | ||
private AssertJComparableTemplates() {} | ||
|
||
static final class AssertThatIsEqualByComparingTo<T extends Comparable<? super T>> { | ||
@BeforeTemplate | ||
AbstractIntegerAssert<?> before(T actual, T expected) { | ||
return assertThat(actual.compareTo(expected)).isEqualTo(0); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(STATIC_IMPORT_ALWAYS) | ||
AbstractComparableAssert<?, ?> after(T actual, T expected) { | ||
return assertThat(actual).isEqualByComparingTo(expected); | ||
} | ||
} | ||
|
||
static final class AssertThatIsNotEqualByComparingTo<T extends Comparable<? super T>> { | ||
@BeforeTemplate | ||
AbstractIntegerAssert<?> before(T actual, T expected) { | ||
return assertThat(actual.compareTo(expected)).isNotEqualTo(0); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(STATIC_IMPORT_ALWAYS) | ||
AbstractComparableAssert<?, ?> after(T actual, T expected) { | ||
return assertThat(actual).isNotEqualByComparingTo(expected); | ||
} | ||
} | ||
|
||
static final class AssertThatIsLessThan<T extends Comparable<? super T>> { | ||
@BeforeTemplate | ||
AbstractIntegerAssert<?> before(T actual, T expected) { | ||
return assertThat(actual.compareTo(expected)).isNegative(); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(STATIC_IMPORT_ALWAYS) | ||
AbstractComparableAssert<?, ?> after(T actual, T expected) { | ||
return assertThat(actual).isLessThan(expected); | ||
} | ||
} | ||
|
||
static final class AssertThatIsLessThanOrEqualTo<T extends Comparable<? super T>> { | ||
@BeforeTemplate | ||
AbstractIntegerAssert<?> before(T actual, T expected) { | ||
return assertThat(actual.compareTo(expected)).isNotPositive(); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(STATIC_IMPORT_ALWAYS) | ||
AbstractComparableAssert<?, ?> after(T actual, T expected) { | ||
return assertThat(actual).isLessThanOrEqualTo(expected); | ||
} | ||
} | ||
|
||
static final class AssertThatIsGreaterThan<T extends Comparable<? super T>> { | ||
@BeforeTemplate | ||
AbstractIntegerAssert<?> before(T actual, T expected) { | ||
return assertThat(actual.compareTo(expected)).isPositive(); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(STATIC_IMPORT_ALWAYS) | ||
AbstractComparableAssert<?, ?> after(T actual, T expected) { | ||
return assertThat(actual).isGreaterThan(expected); | ||
} | ||
} | ||
|
||
static final class AssertThatIsGreaterThanOrEqualTo<T extends Comparable<? super T>> { | ||
@BeforeTemplate | ||
AbstractIntegerAssert<?> before(T actual, T expected) { | ||
return assertThat(actual.compareTo(expected)).isNotNegative(); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(STATIC_IMPORT_ALWAYS) | ||
AbstractComparableAssert<?, ?> after(T actual, T expected) { | ||
return assertThat(actual).isGreaterThanOrEqualTo(expected); | ||
} | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
...rib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJPrimitiveTemplates.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,111 @@ | ||
package tech.picnic.errorprone.refastertemplates; | ||
|
||
import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.google.errorprone.refaster.Refaster; | ||
import com.google.errorprone.refaster.annotation.AfterTemplate; | ||
import com.google.errorprone.refaster.annotation.BeforeTemplate; | ||
import com.google.errorprone.refaster.annotation.UseImportPolicy; | ||
import org.assertj.core.api.AbstractBooleanAssert; | ||
import org.assertj.core.api.AbstractDoubleAssert; | ||
|
||
final class AssertJPrimitiveTemplates { | ||
private AssertJPrimitiveTemplates() {} | ||
|
||
static final class AssertThatIsEqualTo { | ||
@BeforeTemplate | ||
AbstractBooleanAssert<?> before(boolean actual, boolean expected) { | ||
return Refaster.anyOf( | ||
assertThat(actual == expected).isTrue(), assertThat(actual != expected).isFalse()); | ||
} | ||
|
||
@BeforeTemplate | ||
AbstractBooleanAssert<?> before(double actual, double expected) { | ||
return Refaster.anyOf( | ||
assertThat(actual == expected).isTrue(), assertThat(actual != expected).isFalse()); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(STATIC_IMPORT_ALWAYS) | ||
AbstractBooleanAssert<?> after(boolean actual, boolean expected) { | ||
return assertThat(actual).isEqualTo(expected); | ||
} | ||
} | ||
|
||
static final class AssertThatIsNotEqualTo { | ||
@BeforeTemplate | ||
AbstractBooleanAssert<?> before(boolean actual, boolean expected) { | ||
return Refaster.anyOf( | ||
assertThat(actual != expected).isTrue(), assertThat(actual == expected).isFalse()); | ||
} | ||
|
||
@BeforeTemplate | ||
AbstractBooleanAssert<?> before(double actual, double expected) { | ||
return Refaster.anyOf( | ||
assertThat(actual != expected).isTrue(), assertThat(actual == expected).isFalse()); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(STATIC_IMPORT_ALWAYS) | ||
AbstractBooleanAssert<?> after(boolean actual, boolean expected) { | ||
return assertThat(actual).isNotEqualTo(expected); | ||
} | ||
} | ||
|
||
static final class AssertThatIsLessThan { | ||
@BeforeTemplate | ||
AbstractBooleanAssert<?> before(double actual, double expected) { | ||
return Refaster.anyOf( | ||
assertThat(actual < expected).isTrue(), assertThat(actual >= expected).isFalse()); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(STATIC_IMPORT_ALWAYS) | ||
AbstractDoubleAssert<?> after(double actual, double expected) { | ||
return assertThat(actual).isLessThan(expected); | ||
} | ||
} | ||
|
||
static final class AssertThatIsLessThanOrEqualTo { | ||
@BeforeTemplate | ||
AbstractBooleanAssert<?> before(double actual, double expected) { | ||
return Refaster.anyOf( | ||
assertThat(actual <= expected).isTrue(), assertThat(actual > expected).isFalse()); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(STATIC_IMPORT_ALWAYS) | ||
AbstractDoubleAssert<?> after(double actual, double expected) { | ||
return assertThat(actual).isLessThanOrEqualTo(expected); | ||
} | ||
} | ||
|
||
static final class AssertThatIsGreaterThan { | ||
@BeforeTemplate | ||
AbstractBooleanAssert<?> before(double actual, double expected) { | ||
return Refaster.anyOf( | ||
assertThat(actual > expected).isTrue(), assertThat(actual <= expected).isFalse()); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(STATIC_IMPORT_ALWAYS) | ||
AbstractDoubleAssert<?> after(double actual, double expected) { | ||
return assertThat(actual).isGreaterThan(expected); | ||
} | ||
} | ||
|
||
static final class AssertThatIsGreaterThanOrEqualTo { | ||
@BeforeTemplate | ||
AbstractBooleanAssert<?> before(double actual, double expected) { | ||
return Refaster.anyOf( | ||
assertThat(actual >= expected).isTrue(), assertThat(actual < expected).isFalse()); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(STATIC_IMPORT_ALWAYS) | ||
AbstractDoubleAssert<?> after(double actual, double expected) { | ||
return assertThat(actual).isGreaterThanOrEqualTo(expected); | ||
} | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
...sources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestInput.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,33 @@ | ||
package tech.picnic.errorprone.refastertemplates; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.math.BigDecimal; | ||
import org.assertj.core.api.AbstractComparableAssert; | ||
import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; | ||
|
||
final class AssertJComparableTemplatesTest implements RefasterTemplateTestCase { | ||
AbstractComparableAssert<?, ?> testAssertThatIsEqualByComparingTo() { | ||
return assertThat(BigDecimal.ZERO.compareTo(BigDecimal.ONE)).isEqualTo(0); | ||
} | ||
|
||
AbstractComparableAssert<?, ?> testAssertThatIsNotEqualByComparingTo() { | ||
return assertThat(BigDecimal.ZERO.compareTo(BigDecimal.ONE)).isNotEqualTo(0); | ||
} | ||
|
||
AbstractComparableAssert<?, ?> testAssertThatIsLessThan() { | ||
return assertThat(BigDecimal.ZERO.compareTo(BigDecimal.ONE)).isNegative(); | ||
} | ||
|
||
AbstractComparableAssert<?, ?> testAssertThatIsLessThanOrEqualTo() { | ||
return assertThat(BigDecimal.ZERO.compareTo(BigDecimal.ONE)).isNotPositive(); | ||
} | ||
|
||
AbstractComparableAssert<?, ?> testAssertThatIsGreaterThan() { | ||
return assertThat(BigDecimal.ZERO.compareTo(BigDecimal.ONE)).isPositive(); | ||
} | ||
|
||
AbstractComparableAssert<?, ?> testAssertThatIsGreaterThanOrEqualTo() { | ||
return assertThat(BigDecimal.ZERO.compareTo(BigDecimal.ONE)).isNotNegative(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestOutput.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,33 @@ | ||
package tech.picnic.errorprone.refastertemplates; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.math.BigDecimal; | ||
import org.assertj.core.api.AbstractComparableAssert; | ||
import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; | ||
|
||
final class AssertJComparableTemplatesTest implements RefasterTemplateTestCase { | ||
AbstractComparableAssert<?, ?> testAssertThatIsEqualByComparingTo() { | ||
return assertThat(BigDecimal.ZERO).isEqualByComparingTo(BigDecimal.ONE); | ||
} | ||
|
||
AbstractComparableAssert<?, ?> testAssertThatIsNotEqualByComparingTo() { | ||
return assertThat(BigDecimal.ZERO).isNotEqualByComparingTo(BigDecimal.ONE); | ||
} | ||
|
||
AbstractComparableAssert<?, ?> testAssertThatIsLessThan() { | ||
return assertThat(BigDecimal.ZERO).isLessThan(BigDecimal.ONE); | ||
} | ||
|
||
AbstractComparableAssert<?, ?> testAssertThatIsLessThanOrEqualTo() { | ||
return assertThat(BigDecimal.ZERO).isLessThanOrEqualTo(BigDecimal.ONE); | ||
} | ||
|
||
AbstractComparableAssert<?, ?> testAssertThatIsGreaterThan() { | ||
return assertThat(BigDecimal.ZERO).isGreaterThan(BigDecimal.ONE); | ||
} | ||
|
||
AbstractComparableAssert<?, ?> testAssertThatIsGreaterThanOrEqualTo() { | ||
return assertThat(BigDecimal.ZERO).isGreaterThanOrEqualTo(BigDecimal.ONE); | ||
} | ||
} |
Oops, something went wrong.