-
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
AssertJPrimitiveTemplates
and move some templates
- Loading branch information
Showing
7 changed files
with
358 additions
and
327 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
111 changes: 111 additions & 0 deletions
111
...ib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJPrimitivesTemplates.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 AssertJPrimitivesTemplates { | ||
private AssertJPrimitivesTemplates() {} | ||
|
||
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
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
Oops, something went wrong.