Skip to content

Commit 1cad700

Browse files
committed
Use AssertJ instead of Hamcrest
And get rid of JUnit 4.
1 parent d73d4e1 commit 1cad700

14 files changed

+213
-306
lines changed

pom.xml

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@
6363
<jetty.version>9.4.19.v20190610</jetty.version>
6464
<junit.jupiter.version>5.5.1</junit.jupiter.version>
6565
<mockito.version>3.0.0</mockito.version>
66-
<hamcrest.version>2.0.0.0</hamcrest.version>
67-
<assertj.version>3.12.2</assertj.version>
66+
<assertj.version>3.13.2</assertj.version>
6867
<commons-lang3.version>3.9</commons-lang3.version>
6968
<jmh.version>1.21</jmh.version>
7069

@@ -169,27 +168,6 @@
169168
<version>${junit.jupiter.version}</version>
170169
<scope>test</scope>
171170
</dependency>
172-
<!-- To avoid compiler warnings about @API annotations in JUnit code -->
173-
<dependency>
174-
<groupId>org.apiguardian</groupId>
175-
<artifactId>apiguardian-api</artifactId>
176-
<version>1.0.0</version>
177-
<scope>test</scope>
178-
</dependency>
179-
180-
<!-- to support JUnit 4 rules -->
181-
<dependency>
182-
<groupId>org.junit.jupiter</groupId>
183-
<artifactId>junit-jupiter-migrationsupport</artifactId>
184-
<version>${junit.jupiter.version}</version>
185-
<exclusions>
186-
<exclusion>
187-
<groupId>org.hamcrest</groupId>
188-
<artifactId>hamcrest-core</artifactId>
189-
</exclusion>
190-
</exclusions>
191-
<scope>test</scope>
192-
</dependency>
193171

194172
<!-- for parameterized tests -->
195173
<dependency>
@@ -206,13 +184,6 @@
206184
<scope>test</scope>
207185
</dependency>
208186

209-
<dependency>
210-
<groupId>org.hamcrest</groupId>
211-
<artifactId>hamcrest-junit</artifactId>
212-
<version>${hamcrest.version}</version>
213-
<scope>test</scope>
214-
</dependency>
215-
216187
<dependency>
217188
<groupId>org.assertj</groupId>
218189
<artifactId>assertj-core</artifactId>

src/test/java/com/rabbitmq/perf/CachingRoutingKeyGeneratorTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,24 @@
2323
import java.util.function.Supplier;
2424
import java.util.stream.IntStream;
2525

26-
import static org.hamcrest.Matchers.hasSize;
27-
import static org.hamcrest.junit.MatcherAssert.assertThat;
26+
import static org.assertj.core.api.Assertions.assertThat;
2827
import static org.junit.jupiter.api.Assertions.assertThrows;
2928

3029
public class CachingRoutingKeyGeneratorTest {
3130

3231
Supplier<String> generator;
3332

3433
@ParameterizedTest
35-
@ValueSource(ints = { 1, 10, 100 })
34+
@ValueSource(ints = {1, 10, 100})
3635
public void cacheValues(int cacheSize) {
3736
generator = new Producer.CachingRoutingKeyGenerator(cacheSize);
3837
Set<String> keys = new HashSet<>();
3938
IntStream.range(0, 1000).forEach(i -> keys.add(generator.get()));
40-
assertThat(keys, hasSize(cacheSize));
39+
assertThat(keys).hasSize(cacheSize);
4140
}
4241

4342
@ParameterizedTest
44-
@ValueSource(ints = { 0, -1, -10 })
43+
@ValueSource(ints = {0, -1, -10})
4544
public void cacheSizeMustBeGreaterThanZero(int size) {
4645
assertThrows(IllegalArgumentException.class, () -> new Producer.CachingRoutingKeyGenerator(size));
4746
}

src/test/java/com/rabbitmq/perf/CliTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727

2828
import static com.rabbitmq.perf.PerfTest.getOptions;
2929
import static com.rabbitmq.perf.PerfTest.getParser;
30-
import static org.hamcrest.Matchers.hasItems;
31-
import static org.hamcrest.Matchers.hasSize;
32-
import static org.hamcrest.junit.MatcherAssert.assertThat;
30+
import static org.assertj.core.api.Assertions.assertThat;
3331
import static org.junit.jupiter.api.Assertions.assertEquals;
3432

3533
public class CliTest {
@@ -94,10 +92,10 @@ public void lstArg(String commandLine, String expectedAsString) throws ParseExce
9492
String[] expectedValues = expectedAsString.split(" ");
9593
if (expectedValues.length > 0 && !expectedValues[0].isEmpty()) {
9694
for (String expectedValue : expectedValues) {
97-
assertThat(value, hasItems(expectedValue));
95+
assertThat(value).contains(expectedValue);
9896
}
9997
} else {
100-
assertThat(value, hasSize(0));
98+
assertThat(value).hasSize(0);
10199
}
102100
}
103101

src/test/java/com/rabbitmq/perf/LocalFilesMessageBodySourceTest.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515

1616
package com.rabbitmq.perf;
1717

18-
import org.junit.Rule;
1918
import org.junit.jupiter.api.Test;
20-
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
21-
import org.junit.rules.TemporaryFolder;
19+
import org.junit.jupiter.api.io.TempDir;
2220

2321
import java.io.File;
2422
import java.io.FileWriter;
@@ -29,15 +27,22 @@
2927
import static org.junit.jupiter.api.Assertions.assertEquals;
3028
import static org.junit.jupiter.api.Assertions.fail;
3129

32-
@EnableRuleMigrationSupport
3330
public class LocalFilesMessageBodySourceTest {
3431

35-
@Rule
36-
public TemporaryFolder folder = new TemporaryFolder();
32+
@TempDir
33+
File folder;
34+
35+
private static void write(File file, String content) throws Exception {
36+
FileWriter writer = new FileWriter(file);
37+
writer.append(content);
38+
writer.flush();
39+
writer.close();
40+
}
3741

3842
@Test
3943
public void createOneFileThatExists() throws Exception {
40-
File file = folder.newFile("content.txt");
44+
File file = new File(folder, "content.txt");
45+
file.createNewFile();
4146
String content = "dummy content";
4247
write(file, content);
4348
MessageBodySource creator = new LocalFilesMessageBodySource(asList(file.getAbsolutePath()));
@@ -47,10 +52,12 @@ public void createOneFileThatExists() throws Exception {
4752
assertEquals(content, new String(body2, "UTF-8"));
4853
}
4954

50-
@Test public void createSeveralFileThatExists() throws Exception {
55+
@Test
56+
public void createSeveralFileThatExists() throws Exception {
5157
List<String> files = new ArrayList<String>();
52-
for(int i = 0; i < 3 ; i++) {
53-
File file = folder.newFile("content" + i +".txt");
58+
for (int i = 0; i < 3; i++) {
59+
File file = new File(folder, "content" + i + ".txt");
60+
file.createNewFile();
5461
String content = "content" + i;
5562
write(file, content);
5663
files.add(file.getAbsolutePath());
@@ -67,8 +74,9 @@ public void createOneFileThatExists() throws Exception {
6774
assertEquals("content0", new String(body4, "UTF-8"));
6875
}
6976

70-
@Test public void createFileDoesNotExist() throws Exception {
71-
File file = new File(folder.getRoot(), "dummy.txt");
77+
@Test
78+
public void createFileDoesNotExist() throws Exception {
79+
File file = new File(folder, "dummy.txt");
7280
try {
7381
new LocalFilesMessageBodySource(asList(file.getAbsolutePath()));
7482
fail("File does not exist, exception should have thrown");
@@ -77,11 +85,4 @@ public void createOneFileThatExists() throws Exception {
7785
}
7886
}
7987

80-
private static void write(File file, String content) throws Exception {
81-
FileWriter writer = new FileWriter(file);
82-
writer.append(content);
83-
writer.flush();
84-
writer.close();
85-
}
86-
8788
}

0 commit comments

Comments
 (0)