Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Commit

Permalink
Gh-832: Upgrade JUnit 4 to JUnit 5 (#1003)
Browse files Browse the repository at this point in the history
* Change all tests to use JUnit 5

* Fix message that can be null

* Typo - missing call
  • Loading branch information
GCHQDeveloper314 authored Jul 12, 2022
1 parent 3b26700 commit 5fead5c
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@

package uk.gov.gchq.gaffer.miniaccumulocluster;

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

import java.io.File;

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

public class MiniAccumuloClusterControllerTest {
@Test
Expand Down Expand Up @@ -58,9 +56,9 @@ public void shouldStartAndStopCluster() throws Exception {
Thread.sleep(5000);

// Then
assertNull(null != accumuloException[0] ? accumuloException[0].getMessage() : "", accumuloException[0]);
assertTrue("store.properties was not generated", new File(miniAccumuloClusterName + "/store.properties").exists());
assertEquals(1024, runner[0].getHeapSize());
assertThat(accumuloException[0]).withFailMessage(null != accumuloException[0] ? accumuloException[0].getMessage() : "").isNull();
assertThat(new File(miniAccumuloClusterName + "/store.properties").exists()).withFailMessage("store.properties was not generated").isTrue();
assertThat(1024).isEqualTo(runner[0].getHeapSize());
} finally {
if (null != runner[0]) {
runner[0].stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
package uk.gov.gchq.gaffer.accumulostore.performancetesting.ingest;

import org.apache.hadoop.conf.Configuration;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import uk.gov.gchq.gaffer.accumulostore.AccumuloProperties;
import uk.gov.gchq.gaffer.accumulostore.AccumuloStore;
import uk.gov.gchq.gaffer.accumulostore.MiniAccumuloStore;
import uk.gov.gchq.gaffer.commonutil.CommonTestConstants;
import uk.gov.gchq.gaffer.commonutil.StreamUtil;
import uk.gov.gchq.gaffer.graph.Graph;
import uk.gov.gchq.gaffer.graph.GraphConfig;
Expand All @@ -33,12 +31,13 @@
import uk.gov.gchq.gaffer.store.StoreException;
import uk.gov.gchq.gaffer.store.schema.Schema;

import java.io.File;
import java.io.IOException;

public class TestAccumuloStoreRandomElementIngestTest {

@Rule
public TemporaryFolder tempFolder = new TemporaryFolder(CommonTestConstants.TMP_DIRECTORY);
@TempDir
public File tempFolder;

@Test
public void testAccumuloStoreRandomElementIngestTestRuns() throws StoreException, OperationException, IOException {
Expand All @@ -49,7 +48,7 @@ public void testAccumuloStoreRandomElementIngestTestRuns() throws StoreException
testProperties.setElementSupplierClass(RmatElementSupplier.class.getName());
testProperties.setRmatProbabilities(Constants.RMAT_PROBABILITIES);
testProperties.setRmatMaxNodeId(100L);
testProperties.setTempDirectory(tempFolder.newFolder().getCanonicalPath());
testProperties.setTempDirectory(tempFolder.getCanonicalPath());

final Schema schema = Schema.fromJson(StreamUtil.schemas(Constants.class));
final AccumuloProperties storeProperties = AccumuloProperties.loadStoreProperties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
package uk.gov.gchq.gaffer.performancetesting.ingest;

import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import uk.gov.gchq.gaffer.accumulostore.AccumuloProperties;
import uk.gov.gchq.gaffer.accumulostore.MiniAccumuloStore;
import uk.gov.gchq.gaffer.commonutil.CommonTestConstants;
import uk.gov.gchq.gaffer.commonutil.StreamUtil;
import uk.gov.gchq.gaffer.graph.Graph;
import uk.gov.gchq.gaffer.graph.GraphConfig;
Expand All @@ -34,12 +32,12 @@
import java.io.IOException;
import java.util.List;

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

public class TestElementIngestTest {

@Rule
public TemporaryFolder folder = new TemporaryFolder(CommonTestConstants.TMP_DIRECTORY);
@TempDir
public File folder;

@Test
public void testElementIngestTestRuns() {
Expand All @@ -65,7 +63,7 @@ public void testElementIngestTestRuns() {
final double result = test.run();

// Then
assertTrue(result > 0.0D);
assertThat(result > 0.0D).isTrue();
}

@Test
Expand All @@ -78,7 +76,7 @@ public void testElementIngestTestOutputsToListener() throws IOException {
testProperties.setRmatProbabilities(Constants.RMAT_PROBABILITIES);
testProperties.setRmatMaxNodeId(100L);
testProperties.setMetricsListenerClass(FileWriterMetricsListener.class.getName());
final File metricsResults = folder.newFile();
final File metricsResults = new File(folder, "metricsResults.txt");
final String metricsResultsFilename = metricsResults.getPath();
testProperties.setProperty(FileWriterMetricsListener.FILENAME, metricsResultsFilename);
final AccumuloProperties storeProperties = AccumuloProperties.loadStoreProperties(
Expand All @@ -97,15 +95,15 @@ public void testElementIngestTestOutputsToListener() throws IOException {
final List<String> lines = FileUtils.readLines(new File(metricsResultsFilename));

// Then
assertTrue(lines.size() > 0);
assertThat(lines.size() > 0).isTrue();
final int offsetBatch = IngestMetrics.ELEMENTS_PER_SECOND_BATCH.length() + 1;
final int offsetOverall = IngestMetrics.ELEMENTS_PER_SECOND_OVERALL.length() + 1;
for (int i = 0; i < lines.size() - 2; i++) {
final String[] tokens = lines.get(i).split(",");
assertTrue(tokens[0].replaceAll(" ", "").startsWith(IngestMetrics.ELEMENTS_PER_SECOND_BATCH + ":"));
assertTrue(nullOrPositive(tokens[0].substring(offsetBatch)));
assertTrue(tokens[1].replaceAll(" ", "").startsWith(IngestMetrics.ELEMENTS_PER_SECOND_OVERALL + ":"));
assertTrue(nullOrPositive(tokens[1].substring(offsetOverall)));
assertThat(tokens[0].replaceAll(" ", "").startsWith(IngestMetrics.ELEMENTS_PER_SECOND_BATCH + ":")).isTrue();
assertThat(nullOrPositive(tokens[0].substring(offsetBatch))).isTrue();
assertThat(tokens[1].replaceAll(" ", "").startsWith(IngestMetrics.ELEMENTS_PER_SECOND_OVERALL + ":")).isTrue();
assertThat(nullOrPositive(tokens[1].substring(offsetOverall))).isTrue();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
package uk.gov.gchq.gaffer.performancetesting.ingest;

import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import uk.gov.gchq.gaffer.accumulostore.AccumuloProperties;
import uk.gov.gchq.gaffer.accumulostore.MiniAccumuloStore;
import uk.gov.gchq.gaffer.commonutil.CommonTestConstants;
import uk.gov.gchq.gaffer.commonutil.StreamUtil;
import uk.gov.gchq.gaffer.graph.Graph;
import uk.gov.gchq.gaffer.graph.GraphConfig;
Expand All @@ -43,12 +41,12 @@
import java.util.List;
import java.util.stream.Stream;

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

public class TestQueryTest {

@Rule
public TemporaryFolder folder = new TemporaryFolder(CommonTestConstants.TMP_DIRECTORY);
@TempDir
public File folder;

@Test
public void testQueryTestRuns() throws OperationException {
Expand Down Expand Up @@ -79,7 +77,7 @@ public void testQueryTestRuns() throws OperationException {
final double result = test.run();

// Then
assertTrue(result > 0.0D);
assertThat(result > 0.0D).isTrue();
}

@Test
Expand All @@ -92,7 +90,7 @@ public void testQueryTestOutputsToListener() throws IOException, OperationExcept
testProperties.setRmatProbabilities(Constants.RMAT_PROBABILITIES);
testProperties.setRmatMaxNodeId(100L);
testProperties.setMetricsListenerClass(FileWriterMetricsListener.class.getName());
final File metricsResults = folder.newFile();
final File metricsResults = new File(folder, "metricsResults.txt");
final String metricsResultsFilename = metricsResults.getPath();
testProperties.setProperty(FileWriterMetricsListener.FILENAME, metricsResultsFilename);
final AccumuloProperties storeProperties = AccumuloProperties.loadStoreProperties(
Expand All @@ -116,13 +114,13 @@ public void testQueryTestOutputsToListener() throws IOException, OperationExcept
final List<String> lines = FileUtils.readLines(new File(metricsResultsFilename));

// Then
assertTrue(lines.size() > 0);
assertThat(lines.size() > 0).isTrue();
lines.forEach(line -> {
final String[] fields = line.split(", ");
assertTrue(fields[0].startsWith(QueryMetrics.RESULTS_PER_SECOND));
assertTrue(Double.parseDouble(fields[0].split(":")[1]) > 0.0D);
assertTrue(fields[1].startsWith(QueryMetrics.SEEDS_PER_SECOND));
assertTrue(Double.parseDouble(fields[1].split(":")[1]) > 0.0D);
assertThat(fields[0].startsWith(QueryMetrics.RESULTS_PER_SECOND)).isTrue();
assertThat(Double.parseDouble(fields[0].split(":")[1]) > 0.0D).isTrue();
assertThat(fields[1].startsWith(QueryMetrics.SEEDS_PER_SECOND)).isTrue();
assertThat(Double.parseDouble(fields[1].split(":")[1]) > 0.0D).isTrue();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package uk.gov.gchq.gaffer.randomelementgeneration.cache;

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

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -25,8 +25,7 @@
import java.util.Set;
import java.util.stream.IntStream;

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

public class TestPreferentialAttachmentCache {

Expand All @@ -43,7 +42,7 @@ public void testGetReturnsOneOfTheElementsAdded() {
IntStream.range(0, 100).forEach(i -> results.add(cache.get()));

// Then
results.forEach(i -> assertTrue(data.contains(i)));
results.forEach(i -> assertThat(data.contains(i)).isTrue());
}

@Test
Expand All @@ -56,7 +55,7 @@ public void testMaxSizeIsRespected() {
final long numberOfElements = cache.getNumberOfElements();

// Then
assertEquals(10, numberOfElements);
assertThat(numberOfElements).isEqualTo(10);
}

/**
Expand All @@ -83,6 +82,6 @@ public void testPowerLaw() {
final long minFrequency = itemToCount.values().stream().mapToLong(Long::longValue).min().getAsLong();

// Then
assertTrue(maxFrequency / minFrequency > 5);
assertThat(maxFrequency / minFrequency > 5).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
package uk.gov.gchq.gaffer.randomelementgeneration.cache;

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

import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.IntStream;

import static junit.framework.TestCase.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;

public class TestProbabilityGenerator {

Expand All @@ -46,7 +46,7 @@ public void testWhenUniform() {

// Then
final double ratio = ((double) counts.get("A")) / counts.get("B");
assertTrue(0.99D < ratio && ratio < 1.01D);
assertThat(0.99D < ratio && ratio < 1.01D).isTrue();
}

@Test
Expand All @@ -68,6 +68,6 @@ public void testWhenUnbalanced() {

// Then
final double ratio = ((double) counts.get("A")) / counts.get("B");
assertTrue(ratio > 100.0D);
assertThat(ratio > 100.0D).isTrue();
}
}
Loading

0 comments on commit 5fead5c

Please sign in to comment.