Extended JUnitAssertToAssertJ inspection to convert JUnit assume-Statements, too.
Improved JUnitAssertToAssertJ quick fix to swap expected and actual expressions if the actual one is a constant.
This commit is contained in:
+36
@@ -1,12 +1,18 @@
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||
import static org.assertj.core.data.Offset.offset;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
public class JUnitAssertToAssertJ {
|
||||
|
||||
private void jUnitAssertToAssertJ() {
|
||||
String foo = "foo";
|
||||
String bar = "bar";
|
||||
int someInt = 1;
|
||||
double someDouble = 1.0;
|
||||
float someFloat = 1.0f;
|
||||
|
||||
assertThat(foo == "foo").isTrue();
|
||||
assertThat(foo == "foo").as("oh no!").isTrue();
|
||||
assertThat(foo == "bar").isFalse();
|
||||
@@ -52,5 +58,35 @@ public class JUnitAssertToAssertJ {
|
||||
assertThat(new double[1]).as("array equals").containsExactly(new double[2], offset(1.0));
|
||||
assertThat(new float[1]).containsExactly(new float[2], offset(1.0f));
|
||||
assertThat(new float[1]).as("array equals").containsExactly(new float[2], offset(1.0f));
|
||||
|
||||
assertThat(foo).isEqualTo("bar");
|
||||
assertThat(bar).as("equals").isEqualTo("foo");
|
||||
assertThat(bar).isNotEqualTo("foo");
|
||||
assertThat(foo).as("equals").isNotEqualTo("bar");
|
||||
|
||||
assertThat(someInt).isEqualTo(2);
|
||||
assertThat(someDouble).isCloseTo(2.0, offset(0.1));
|
||||
assertThat(someDouble).as("equals").isEqualTo(1.0);
|
||||
assertThat(someDouble).as("equals").isCloseTo(1.0, offset(0.1));
|
||||
assertThat(someFloat).isEqualTo(1.0f);
|
||||
assertThat(someFloat).isCloseTo(2.0f, offset(0.1f));
|
||||
|
||||
fail();
|
||||
fail("oh no!")
|
||||
}
|
||||
|
||||
private void jUnitAssumeToAssertJ() {
|
||||
String foo = "foo";
|
||||
String bar = "bar";
|
||||
assumeThat(foo == "foo").isTrue();
|
||||
assumeThat(foo == "foo").as("oh no!").isTrue();
|
||||
assumeThat(foo == "bar").isFalse();
|
||||
assumeThat(foo == "bar").as("boom!").isFalse();
|
||||
|
||||
assumeThat(foo).isNotNull();
|
||||
assumeNotNull(foo, bar);
|
||||
|
||||
assumeThat(new IllegalArgumentException()).doesNotThrowAnyException();
|
||||
assumeThat(new IllegalArgumentException()).as("oh no!").doesNotThrowAnyException();
|
||||
}
|
||||
}
|
||||
|
||||
+35
@@ -1,10 +1,15 @@
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
public class JUnitAssertToAssertJ {
|
||||
|
||||
private void jUnitAssertToAssertJ() {
|
||||
String foo = "foo";
|
||||
String bar = "bar";
|
||||
int someInt = 1;
|
||||
double someDouble = 1.0;
|
||||
float someFloat = 1.0f;
|
||||
|
||||
assertTrue(foo == "foo");
|
||||
assertTrue("oh no!", foo == "foo");
|
||||
assertFalse(foo == "bar");
|
||||
@@ -50,5 +55,35 @@ public class JUnitAssertToAssertJ {
|
||||
assertArrayEquals("array equals", new double[2], new double[1], 1.0);
|
||||
assertArrayEquals(new float[2], new float[1], 1.0f);
|
||||
assertArrayEquals("array equals", new float[2], new float[1], 1.0f);
|
||||
|
||||
assertEquals("bar", foo);
|
||||
assertEquals("equals", bar, "foo");
|
||||
assertNotEquals(bar, "foo");
|
||||
assertNotEquals("equals", "bar", foo);
|
||||
|
||||
assertEquals(someInt, 2);
|
||||
assertEquals(someDouble, 2.0, 0.1);
|
||||
assertEquals("equals",1.0, someDouble);
|
||||
assertEquals("equals",1.0, someDouble, 0.1);
|
||||
assertEquals(1.0f, someFloat);
|
||||
assertEquals(someFloat, 2.0f, 0.1f);
|
||||
|
||||
fail();
|
||||
fail("oh no!")
|
||||
}
|
||||
|
||||
private void jUnitAssumeToAssertJ() {
|
||||
String foo = "foo";
|
||||
String bar = "bar";
|
||||
assumeTrue(foo == "foo");
|
||||
assumeTrue("oh no!", foo == "foo");
|
||||
assumeFalse(foo == "bar");
|
||||
assumeFalse("boom!", foo == "bar");
|
||||
|
||||
assumeNotNull(foo);
|
||||
assumeNotNull(foo, bar);
|
||||
|
||||
assumeNoException(new IllegalArgumentException());
|
||||
assumeNoException("oh no!", new IllegalArgumentException());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user