Skip to content

Bump JUnit 4.x to JUnit Jupiter 5 #152

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

Merged
merged 2 commits into from
May 19, 2024
Merged
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
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -67,9 +67,12 @@ jar {
dependencies {
api 'org.slf4j:slf4j-api:' + slf4jVersion
testImplementation 'org.slf4j:slf4j-simple:' + slf4jVersion
testImplementation 'junit:junit:4.12'
testImplementation 'org.awaitility:awaitility:2.0.0'
testImplementation "org.hamcrest:hamcrest:2.2"
testImplementation 'com.github.ben-manes.caffeine:caffeine:2.9.0'
testImplementation platform('org.junit:junit-bom:5.10.2')
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}

task sourcesJar(type: Jar) {
@@ -96,6 +99,7 @@ test {
testLogging {
exceptionFormat = 'full'
}
useJUnitPlatform()
}

publishing {
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.dataloader;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.HashMap;
@@ -14,8 +14,8 @@
import static java.util.Collections.singletonList;
import static org.dataloader.DataLoaderFactory.newDataLoader;
import static org.dataloader.DataLoaderFactory.newMappedDataLoader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

/**
* Tests related to context. DataLoaderTest is getting to big and needs refactoring
4 changes: 2 additions & 2 deletions src/test/java/org/dataloader/DataLoaderCacheMapTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.dataloader;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CompletableFuture;

import static org.dataloader.DataLoaderFactory.newDataLoader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

/**
* Tests for cacheMap functionality..
4 changes: 2 additions & 2 deletions src/test/java/org/dataloader/DataLoaderIfPresentTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.dataloader;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

import static org.dataloader.DataLoaderFactory.newDataLoader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.assertThat;

/**
* Tests for IfPresent and IfCompleted functionality.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.dataloader;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Collection;
@@ -19,10 +19,10 @@
import static org.dataloader.fixtures.TestKit.futureError;
import static org.dataloader.fixtures.TestKit.listFrom;
import static org.dataloader.impl.CompletableFutureKit.cause;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

/**
* Much of the tests that related to {@link MappedBatchLoader} also related to
4 changes: 2 additions & 2 deletions src/test/java/org/dataloader/DataLoaderRegistryTest.java
Original file line number Diff line number Diff line change
@@ -2,16 +2,16 @@

import org.dataloader.stats.SimpleStatisticsCollector;
import org.dataloader.stats.Statistics;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.concurrent.CompletableFuture;

import static java.util.Arrays.asList;
import static org.dataloader.DataLoaderFactory.newDataLoader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.assertThat;

public class DataLoaderRegistryTest {
final BatchLoader<Object, Object> identityBatchLoader = CompletableFuture::completedFuture;
4 changes: 2 additions & 2 deletions src/test/java/org/dataloader/DataLoaderStatsTest.java
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
import org.dataloader.stats.context.IncrementCacheHitCountStatisticsContext;
import org.dataloader.stats.context.IncrementLoadCountStatisticsContext;
import org.dataloader.stats.context.IncrementLoadErrorCountStatisticsContext;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
@@ -19,9 +19,9 @@
import static java.util.Collections.singletonList;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.dataloader.DataLoaderFactory.newDataLoader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;

/**
* Tests related to stats. DataLoaderTest is getting to big and needs refactoring
6 changes: 3 additions & 3 deletions src/test/java/org/dataloader/DataLoaderTest.java
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
import org.dataloader.fixtures.User;
import org.dataloader.fixtures.UserManager;
import org.dataloader.impl.CompletableFutureKit;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Collection;
@@ -43,12 +43,12 @@
import static org.dataloader.DataLoaderOptions.newOptions;
import static org.dataloader.fixtures.TestKit.listFrom;
import static org.dataloader.impl.CompletableFutureKit.cause;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

/**
* Tests for {@link DataLoader}.
4 changes: 2 additions & 2 deletions src/test/java/org/dataloader/DataLoaderTimeTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.dataloader;

import org.dataloader.fixtures.TestingClock;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.time.Instant;

import static org.dataloader.fixtures.TestKit.keysAsValues;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

@SuppressWarnings("UnusedReturnValue")
public class DataLoaderTimeTest {
10 changes: 5 additions & 5 deletions src/test/java/org/dataloader/DataLoaderValueCacheTest.java
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
import org.dataloader.fixtures.CaffeineValueCache;
import org.dataloader.fixtures.CustomValueCache;
import org.dataloader.impl.DataLoaderAssertionException;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
@@ -22,11 +22,11 @@
import static org.dataloader.fixtures.TestKit.snooze;
import static org.dataloader.fixtures.TestKit.sort;
import static org.dataloader.impl.CompletableFutureKit.failedFuture;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class DataLoaderValueCacheTest {

4 changes: 2 additions & 2 deletions src/test/java/org/dataloader/DataLoaderWithTryTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.dataloader;

import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.HashMap;
@@ -12,9 +12,9 @@
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.dataloader.DataLoaderFactory.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;

public class DataLoaderWithTryTest {

12 changes: 6 additions & 6 deletions src/test/java/org/dataloader/TryTest.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package org.dataloader;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TryTest {

@@ -29,7 +29,7 @@ private void expectThrowable(RunThatCanThrow runnable, Class<? extends Throwable
return;
}
}
Assert.fail("Expected throwable : " + throwableClass.getName());
Assertions.fail("Expected throwable : " + throwableClass.getName());
}

@SuppressWarnings("SameParameterValue")
4 changes: 2 additions & 2 deletions src/test/java/org/dataloader/impl/PromisedValuesImplTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.dataloader.impl;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;
@@ -12,12 +12,12 @@
import static java.util.Arrays.asList;
import static java.util.concurrent.CompletableFuture.supplyAsync;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;

public class PromisedValuesImplTest {

Original file line number Diff line number Diff line change
@@ -4,12 +4,12 @@
import org.dataloader.DataLoader;
import org.dataloader.fixtures.TestKit;
import org.dataloader.fixtures.TestingClock;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.time.Duration;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class DispatchPredicateTest {

Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
import org.dataloader.BatchLoader;
import org.dataloader.DataLoader;
import org.dataloader.DataLoaderRegistry;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.time.Duration;
import java.util.concurrent.CompletableFuture;
@@ -12,10 +12,9 @@
import static org.awaitility.Awaitility.await;
import static org.dataloader.DataLoaderFactory.newDataLoader;
import static org.dataloader.fixtures.TestKit.asSet;
import static org.dataloader.registries.DispatchPredicate.DISPATCH_NEVER;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

public class ScheduledDataLoaderRegistryPredicateTest {
final BatchLoader<Object, Object> identityBatchLoader = CompletableFuture::completedFuture;
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.dataloader.registries;

import junit.framework.TestCase;
import org.awaitility.core.ConditionTimeoutException;
import org.dataloader.DataLoader;
import org.dataloader.DataLoaderFactory;
import org.dataloader.DataLoaderRegistry;
import org.dataloader.fixtures.TestKit;
import org.junit.jupiter.api.Test;

import java.time.Duration;
import java.util.ArrayList;
@@ -22,17 +22,22 @@
import static org.awaitility.Duration.TWO_SECONDS;
import static org.dataloader.fixtures.TestKit.keysAsValues;
import static org.dataloader.fixtures.TestKit.snooze;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

public class ScheduledDataLoaderRegistryTest extends TestCase {
public class ScheduledDataLoaderRegistryTest {

DispatchPredicate alwaysDispatch = (key, dl) -> true;
DispatchPredicate neverDispatch = (key, dl) -> false;


public void test_basic_setup_works_like_a_normal_dlr() {
@Test
public void basic_setup_works_like_a_normal_dlr() {

List<List<String>> aCalls = new ArrayList<>();
List<List<String>> bCalls = new ArrayList<>();
@@ -63,7 +68,8 @@ public void test_basic_setup_works_like_a_normal_dlr() {
assertThat(bCalls, equalTo(singletonList(asList("BK1", "BK2"))));
}

public void test_predicate_always_false() {
@Test
public void predicate_always_false() {

List<List<String>> calls = new ArrayList<>();
DataLoader<String, String> dlA = DataLoaderFactory.newDataLoader(keysAsValues(calls));
@@ -92,7 +98,8 @@ public void test_predicate_always_false() {
assertThat(calls.size(), equalTo(0));
}

public void test_predicate_that_eventually_returns_true() {
@Test
public void predicate_that_eventually_returns_true() {


AtomicInteger counter = new AtomicInteger();
@@ -123,7 +130,8 @@ public void test_predicate_that_eventually_returns_true() {
assertTrue(p2.isDone());
}

public void test_dispatchAllWithCountImmediately() {
@Test
public void dispatchAllWithCountImmediately() {
List<List<String>> calls = new ArrayList<>();
DataLoader<String, String> dlA = DataLoaderFactory.newDataLoader(keysAsValues(calls));
dlA.load("K1");
@@ -140,7 +148,8 @@ public void test_dispatchAllWithCountImmediately() {
assertThat(calls, equalTo(singletonList(asList("K1", "K2"))));
}

public void test_dispatchAllImmediately() {
@Test
public void dispatchAllImmediately() {
List<List<String>> calls = new ArrayList<>();
DataLoader<String, String> dlA = DataLoaderFactory.newDataLoader(keysAsValues(calls));
dlA.load("K1");
@@ -156,7 +165,8 @@ public void test_dispatchAllImmediately() {
assertThat(calls, equalTo(singletonList(asList("K1", "K2"))));
}

public void test_rescheduleNow() {
@Test
public void rescheduleNow() {
AtomicInteger i = new AtomicInteger();
DispatchPredicate countingPredicate = (dataLoaderKey, dataLoader) -> i.incrementAndGet() > 5;

@@ -179,7 +189,8 @@ public void test_rescheduleNow() {
assertThat(calls, equalTo(singletonList(asList("K1", "K2"))));
}

public void test_it_will_take_out_the_schedule_once_it_dispatches() {
@Test
public void it_will_take_out_the_schedule_once_it_dispatches() {
AtomicInteger counter = new AtomicInteger();
DispatchPredicate countingPredicate = (dataLoaderKey, dataLoader) -> counter.incrementAndGet() > 5;

@@ -220,7 +231,8 @@ public void test_it_will_take_out_the_schedule_once_it_dispatches() {
assertThat(calls, equalTo(asList(asList("K1", "K2"), asList("K3", "K4"))));
}

public void test_close_is_a_one_way_door() {
@Test
public void close_is_a_one_way_door() {
AtomicInteger counter = new AtomicInteger();
DispatchPredicate countingPredicate = (dataLoaderKey, dataLoader) -> {
counter.incrementAndGet();
@@ -264,7 +276,8 @@ public void test_close_is_a_one_way_door() {
assertEquals(counter.get(), countThen + 1);
}

public void test_can_tick_after_first_dispatch_for_chain_data_loaders() {
@Test
public void can_tick_after_first_dispatch_for_chain_data_loaders() {

// delays much bigger than the tick rate will mean multiple calls to dispatch
DataLoader<String, String> dlA = TestKit.idLoaderAsync(Duration.ofMillis(100));
@@ -293,7 +306,8 @@ public void test_can_tick_after_first_dispatch_for_chain_data_loaders() {
registry.close();
}

public void test_chain_data_loaders_will_hang_if_not_in_ticker_mode() {
@Test
public void chain_data_loaders_will_hang_if_not_in_ticker_mode() {

// delays much bigger than the tick rate will mean multiple calls to dispatch
DataLoader<String, String> dlA = TestKit.idLoaderAsync(Duration.ofMillis(100));
@@ -325,7 +339,8 @@ public void test_chain_data_loaders_will_hang_if_not_in_ticker_mode() {
registry.close();
}

public void test_executors_are_shutdown() {
@Test
public void executors_are_shutdown() {
ScheduledDataLoaderRegistry registry = ScheduledDataLoaderRegistry.newScheduledRegistry().build();

ScheduledExecutorService executorService = registry.getScheduledExecutorService();
@@ -345,4 +360,4 @@ public void test_executors_are_shutdown() {


}
}
}
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
import org.dataloader.BatchLoaderEnvironment;
import org.dataloader.DataLoader;
import org.dataloader.DataLoaderOptions;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Map;
@@ -20,8 +20,8 @@
import static org.dataloader.fixtures.TestKit.keysAsValues;
import static org.dataloader.fixtures.TestKit.keysAsValuesWithContext;
import static org.dataloader.fixtures.TestKit.snooze;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

public class BatchLoaderSchedulerTest {

Original file line number Diff line number Diff line change
@@ -5,13 +5,13 @@
import org.dataloader.stats.context.IncrementCacheHitCountStatisticsContext;
import org.dataloader.stats.context.IncrementLoadCountStatisticsContext;
import org.dataloader.stats.context.IncrementLoadErrorCountStatisticsContext;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.concurrent.CompletableFuture;

import static java.util.Collections.singletonList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

public class StatisticsCollectorTest {

4 changes: 2 additions & 2 deletions src/test/java/org/dataloader/stats/StatisticsTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.dataloader.stats;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Map;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

public class StatisticsTest {