Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to JUnit Jupiter using OpenRewrite #3157

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions metrics-caffeine3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,23 @@
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,33 @@
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.github.benmanes.caffeine.cache.RemovalCause;
import io.dropwizard.metrics5.MetricRegistry;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* An example of exporting stats to Dropwizard Metrics (http://metrics.dropwizard.io).
*
* @author ben.manes@gmail.com (Ben Manes)
* @author John Karp
*/
public final class MetricsStatsCounterTest {
final class MetricsStatsCounterTest {

private static final String PREFIX = "foo";

private MetricsStatsCounter stats;
private MetricRegistry registry;

@Before
public void setUp() {
@BeforeEach
void setUp() {
registry = new MetricRegistry();
stats = new MetricsStatsCounter(registry, PREFIX);
}

@Test
public void basicUsage() {
void basicUsage() {
LoadingCache<Integer, Integer> cache = Caffeine.newBuilder()
.recordStats(() -> new MetricsStatsCounter(registry, PREFIX))
.build(key -> key);
Expand All @@ -60,31 +60,31 @@ public void basicUsage() {
}

@Test
public void hit() {
void hit() {
stats.recordHits(2);
assertThat(registry.counter(PREFIX + ".hits").getCount()).isEqualTo(2);
}

@Test
public void miss() {
void miss() {
stats.recordMisses(2);
assertThat(registry.counter(PREFIX + ".misses").getCount()).isEqualTo(2);
}

@Test
public void loadSuccess() {
void loadSuccess() {
stats.recordLoadSuccess(256);
assertThat(registry.timer(PREFIX + ".loads-success").getCount()).isEqualTo(1);
}

@Test
public void loadFailure() {
void loadFailure() {
stats.recordLoadFailure(256);
assertThat(registry.timer(PREFIX + ".loads-failure").getCount()).isEqualTo(1);
}

@Test
public void evictionWithCause() {
void evictionWithCause() {
// With JUnit 5, this would be better done with @ParameterizedTest + @EnumSource
for (RemovalCause cause : RemovalCause.values()) {
stats.recordEviction(3, cause);
Expand Down
18 changes: 12 additions & 6 deletions metrics-collectd/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,24 @@
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package io.dropwizard.metrics5.collectd;

import io.dropwizard.metrics5.MetricRegistry;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

public class CollectdReporterSecurityTest {
class CollectdReporterSecurityTest {

private final MetricRegistry registry = new MetricRegistry();

@Test
public void testUnableSetSecurityLevelToSignWithoutUsername() {
assertThatIllegalArgumentException().isThrownBy(()->
void testUnableSetSecurityLevelToSignWithoutUsername() {
assertThatIllegalArgumentException().isThrownBy(() ->
CollectdReporter.forRegistry(registry)
.withHostName("eddie")
.withSecurityLevel(SecurityLevel.SIGN)
.withPassword("t1_g3r")
.build(new Sender("localhost", 25826)))
.withHostName("eddie")
.withSecurityLevel(SecurityLevel.SIGN)
.withPassword("t1_g3r")
.build(new Sender("localhost", 25826)))
.withMessage("username is required for securityLevel: SIGN");
}

@Test
public void testUnableSetSecurityLevelToSignWithoutPassword() {
assertThatIllegalArgumentException().isThrownBy(()->
void testUnableSetSecurityLevelToSignWithoutPassword() {
assertThatIllegalArgumentException().isThrownBy(() ->
CollectdReporter.forRegistry(registry)
.withHostName("eddie")
.withSecurityLevel(SecurityLevel.SIGN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import io.dropwizard.metrics5.Snapshot;
import io.dropwizard.metrics5.Timer;
import org.collectd.api.ValueList;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.util.Collections;
import java.util.EnumSet;
Expand All @@ -27,47 +27,46 @@
import static org.mockito.Mockito.when;

public class CollectdReporterTest {

@ClassRule
@RegisterExtension
public static Receiver receiver = new Receiver(25826);

private final MetricRegistry registry = new MetricRegistry();
private CollectdReporter reporter;

@Before
public void setUp() {
@BeforeEach
void setUp() {
reporter = CollectdReporter.forRegistry(registry)
.withHostName("eddie")
.build(new Sender("localhost", 25826));
}

@Test
public void reportsByteGauges() throws Exception {
void reportsByteGauges() throws Exception {
reportsGauges((byte) 128);
}

@Test
public void reportsShortGauges() throws Exception {
void reportsShortGauges() throws Exception {
reportsGauges((short) 2048);
}

@Test
public void reportsIntegerGauges() throws Exception {
void reportsIntegerGauges() throws Exception {
reportsGauges(42);
}

@Test
public void reportsLongGauges() throws Exception {
void reportsLongGauges() throws Exception {
reportsGauges(Long.MAX_VALUE);
}

@Test
public void reportsFloatGauges() throws Exception {
void reportsFloatGauges() throws Exception {
reportsGauges(0.25);
}

@Test
public void reportsDoubleGauges() throws Exception {
void reportsDoubleGauges() throws Exception {
reportsGauges(0.125d);
}

Expand All @@ -83,7 +82,7 @@ private <T extends Number> void reportsGauges(T value) throws Exception {
}

@Test
public void reportsBooleanGauges() throws Exception {
void reportsBooleanGauges() throws Exception {
reporter.report(
map(MetricName.build("gauge"), () -> true),
map(),
Expand All @@ -104,7 +103,7 @@ public void reportsBooleanGauges() throws Exception {
}

@Test
public void doesNotReportStringGauges() throws Exception {
void doesNotReportStringGauges() throws Exception {
reporter.report(
map(MetricName.build("unsupported"), () -> "value"),
map(),
Expand All @@ -116,7 +115,7 @@ public void doesNotReportStringGauges() throws Exception {
}

@Test
public void reportsCounters() throws Exception {
void reportsCounters() throws Exception {
Counter counter = mock(Counter.class);
when(counter.getCount()).thenReturn(42L);

Expand All @@ -131,7 +130,7 @@ public void reportsCounters() throws Exception {
}

@Test
public void reportsMeters() throws Exception {
void reportsMeters() throws Exception {
Meter meter = mock(Meter.class);
when(meter.getCount()).thenReturn(1L);
when(meter.getOneMinuteRate()).thenReturn(2.0);
Expand All @@ -154,7 +153,7 @@ public void reportsMeters() throws Exception {
}

@Test
public void reportsHistograms() throws Exception {
void reportsHistograms() throws Exception {
Histogram histogram = mock(Histogram.class);
Snapshot snapshot = mock(Snapshot.class);
when(histogram.getCount()).thenReturn(1L);
Expand Down Expand Up @@ -183,7 +182,7 @@ public void reportsHistograms() throws Exception {
}

@Test
public void reportsTimers() throws Exception {
void reportsTimers() throws Exception {
Timer timer = mock(Timer.class);
Snapshot snapshot = mock(Snapshot.class);
when(timer.getSnapshot()).thenReturn(snapshot);
Expand Down Expand Up @@ -229,7 +228,7 @@ public void reportsTimers() throws Exception {
}

@Test
public void doesNotReportDisabledMetricAttributes() throws Exception {
void doesNotReportDisabledMetricAttributes() throws Exception {
final Meter meter = mock(Meter.class);
when(meter.getCount()).thenReturn(1L);
when(meter.getOneMinuteRate()).thenReturn(2.0);
Expand Down Expand Up @@ -259,7 +258,7 @@ public void doesNotReportDisabledMetricAttributes() throws Exception {
}

@Test
public void sanitizesMetricName() throws Exception {
void sanitizesMetricName() throws Exception {
Counter counter = registry.counter("dash-illegal.slash/illegal");
counter.inc();

Expand All @@ -270,7 +269,7 @@ public void sanitizesMetricName() throws Exception {
}

@Test
public void testUnableSetSecurityLevelToSignWithoutUsername() {
void testUnableSetSecurityLevelToSignWithoutUsername() {
assertThatIllegalArgumentException().isThrownBy(() ->
CollectdReporter.forRegistry(registry)
.withHostName("eddie")
Expand All @@ -281,7 +280,7 @@ public void testUnableSetSecurityLevelToSignWithoutUsername() {
}

@Test
public void testUnableSetSecurityLevelToSignWithoutPassword() {
void testUnableSetSecurityLevelToSignWithoutPassword() {
assertThatIllegalArgumentException().isThrownBy(() ->
CollectdReporter.forRegistry(registry)
.withHostName("eddie")
Expand All @@ -301,7 +300,7 @@ private <T> SortedMap<MetricName, T> map(MetricName name, T metric) {
}

@Test
public void sanitizesMetricNameWithCustomMaxLength() throws Exception {
void sanitizesMetricNameWithCustomMaxLength() throws Exception {
CollectdReporter customReporter = CollectdReporter.forRegistry(registry)
.withHostName("eddie")
.withMaxLength(20)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.dropwizard.metrics5.collectd;

import io.dropwizard.metrics5.collectd.SecurityLevel;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import javax.crypto.Cipher;
import javax.crypto.Mac;
Expand All @@ -19,7 +19,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.Offset.offset;

public class PacketWriterTest {
class PacketWriterTest {

private MetaData metaData = new MetaData.Builder("nw-1.alpine.example.com", 1520961345L, 100)
.type("gauge")
Expand All @@ -29,7 +29,7 @@ public class PacketWriterTest {
private String password = "t1_g$r";

@Test
public void testSignRequest() throws Exception {
void testSignRequest() throws Exception {
AtomicBoolean packetVerified = new AtomicBoolean();
Sender sender = new Sender("localhost", 4009) {
@Override
Expand Down Expand Up @@ -75,7 +75,7 @@ private byte[] sign(byte[] input, String password) {
}

@Test
public void testEncryptRequest() throws Exception {
void testEncryptRequest() throws Exception {
AtomicBoolean packetVerified = new AtomicBoolean();
Sender sender = new Sender("localhost", 4009) {
@Override
Expand Down
Loading