Skip to content

Commit 33422a9

Browse files
committed
Update DocumentExample for Hamcrest to AssertJ
To match blog
1 parent 7ca74a5 commit 33422a9

File tree

1 file changed

+41
-21
lines changed

1 file changed

+41
-21
lines changed

src/test/java/org/openrewrite/java/testing/hamcrest/MigrateHamcrestToAssertJTest.java

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,55 @@ public void defaults(RecipeSpec spec) {
5656
@Test
5757
@DocumentExample
5858
void isEqualTo() {
59+
//language=java
5960
rewriteRun(
60-
//language=java
6161
java("""
62-
import org.junit.jupiter.api.Test;
63-
import static org.hamcrest.MatcherAssert.assertThat;
64-
import static org.hamcrest.Matchers.is;
65-
import static org.hamcrest.Matchers.equalTo;
66-
67-
class ATest {
68-
@Test
69-
void testEquals() {
70-
String str1 = "Hello world!";
71-
String str2 = "Hello world!";
72-
assertThat(str1, is(equalTo(str2)));
62+
class Biscuit {
63+
String name;
64+
Biscuit(String name) {
65+
this.name = name;
66+
}
67+
68+
int getChocolateChipCount() {
69+
return 10;
70+
}
71+
72+
int getHazelnutCount() {
73+
return 3;
7374
}
7475
}
75-
""", """
76+
"""),
77+
java("""
7678
import org.junit.jupiter.api.Test;
77-
78-
import static org.assertj.core.api.Assertions.assertThat;
79-
80-
class ATest {
79+
80+
import static org.hamcrest.MatcherAssert.assertThat;
81+
import static org.hamcrest.Matchers.*;
82+
83+
public class BiscuitTest {
8184
@Test
82-
void testEquals() {
83-
String str1 = "Hello world!";
84-
String str2 = "Hello world!";
85-
assertThat(str1).isEqualTo(str2);
85+
public void biscuits() {
86+
Biscuit theBiscuit = new Biscuit("Ginger");
87+
Biscuit myBiscuit = new Biscuit("Ginger");
88+
assertThat(theBiscuit, equalTo(myBiscuit));
89+
assertThat("chocolate chips", theBiscuit.getChocolateChipCount(), equalTo(10));
90+
assertThat("hazelnuts", theBiscuit.getHazelnutCount(), equalTo(3));
8691
}
8792
}
93+
""", """
94+
import org.junit.jupiter.api.Test;
95+
96+
import static org.assertj.core.api.Assertions.assertThat;
97+
98+
public class BiscuitTest {
99+
@Test
100+
public void biscuits() {
101+
Biscuit theBiscuit = new Biscuit("Ginger");
102+
Biscuit myBiscuit = new Biscuit("Ginger");
103+
assertThat(theBiscuit).isEqualTo(myBiscuit);
104+
assertThat(theBiscuit.getChocolateChipCount()).as("chocolate chips").isEqualTo(10);
105+
assertThat(theBiscuit.getHazelnutCount()).as("hazelnuts").isEqualTo(3);
106+
}
107+
}
88108
"""));
89109
}
90110

0 commit comments

Comments
 (0)