diff --git a/mini-accumulo-cluster/src/test/java/uk/gov/gchq/gaffer/miniaccumulocluster/MiniAccumuloClusterControllerTest.java b/mini-accumulo-cluster/src/test/java/uk/gov/gchq/gaffer/miniaccumulocluster/MiniAccumuloClusterControllerTest.java index 3b63e23ec..85e046111 100644 --- a/mini-accumulo-cluster/src/test/java/uk/gov/gchq/gaffer/miniaccumulocluster/MiniAccumuloClusterControllerTest.java +++ b/mini-accumulo-cluster/src/test/java/uk/gov/gchq/gaffer/miniaccumulocluster/MiniAccumuloClusterControllerTest.java @@ -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 @@ -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(); diff --git a/performance-testing/performance-testing-accumulo-store/src/test/java/uk/gov/gchq/gaffer/accumulostore/performancetesting/ingest/TestAccumuloStoreRandomElementIngestTest.java b/performance-testing/performance-testing-accumulo-store/src/test/java/uk/gov/gchq/gaffer/accumulostore/performancetesting/ingest/TestAccumuloStoreRandomElementIngestTest.java index ac827f46b..0a22bbf87 100644 --- a/performance-testing/performance-testing-accumulo-store/src/test/java/uk/gov/gchq/gaffer/accumulostore/performancetesting/ingest/TestAccumuloStoreRandomElementIngestTest.java +++ b/performance-testing/performance-testing-accumulo-store/src/test/java/uk/gov/gchq/gaffer/accumulostore/performancetesting/ingest/TestAccumuloStoreRandomElementIngestTest.java @@ -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; @@ -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 { @@ -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( diff --git a/performance-testing/performance-testing-core/src/test/java/uk/gov/gchq/gaffer/performancetesting/ingest/TestElementIngestTest.java b/performance-testing/performance-testing-core/src/test/java/uk/gov/gchq/gaffer/performancetesting/ingest/TestElementIngestTest.java index 2603c6795..1847abed1 100644 --- a/performance-testing/performance-testing-core/src/test/java/uk/gov/gchq/gaffer/performancetesting/ingest/TestElementIngestTest.java +++ b/performance-testing/performance-testing-core/src/test/java/uk/gov/gchq/gaffer/performancetesting/ingest/TestElementIngestTest.java @@ -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; @@ -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() { @@ -65,7 +63,7 @@ public void testElementIngestTestRuns() { final double result = test.run(); // Then - assertTrue(result > 0.0D); + assertThat(result > 0.0D).isTrue(); } @Test @@ -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( @@ -97,15 +95,15 @@ public void testElementIngestTestOutputsToListener() throws IOException { final List 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(); } } diff --git a/performance-testing/performance-testing-core/src/test/java/uk/gov/gchq/gaffer/performancetesting/ingest/TestQueryTest.java b/performance-testing/performance-testing-core/src/test/java/uk/gov/gchq/gaffer/performancetesting/ingest/TestQueryTest.java index c2ee7cd5a..937e927cc 100644 --- a/performance-testing/performance-testing-core/src/test/java/uk/gov/gchq/gaffer/performancetesting/ingest/TestQueryTest.java +++ b/performance-testing/performance-testing-core/src/test/java/uk/gov/gchq/gaffer/performancetesting/ingest/TestQueryTest.java @@ -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; @@ -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 { @@ -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 @@ -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( @@ -116,13 +114,13 @@ public void testQueryTestOutputsToListener() throws IOException, OperationExcept final List 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(); }); } } diff --git a/random-element-generation/src/test/java/uk/gov/gchq/gaffer/randomelementgeneration/cache/TestPreferentialAttachmentCache.java b/random-element-generation/src/test/java/uk/gov/gchq/gaffer/randomelementgeneration/cache/TestPreferentialAttachmentCache.java index cf429e1ca..10fd0dce6 100644 --- a/random-element-generation/src/test/java/uk/gov/gchq/gaffer/randomelementgeneration/cache/TestPreferentialAttachmentCache.java +++ b/random-element-generation/src/test/java/uk/gov/gchq/gaffer/randomelementgeneration/cache/TestPreferentialAttachmentCache.java @@ -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; @@ -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 { @@ -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 @@ -56,7 +55,7 @@ public void testMaxSizeIsRespected() { final long numberOfElements = cache.getNumberOfElements(); // Then - assertEquals(10, numberOfElements); + assertThat(numberOfElements).isEqualTo(10); } /** @@ -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(); } } diff --git a/random-element-generation/src/test/java/uk/gov/gchq/gaffer/randomelementgeneration/cache/TestProbabilityGenerator.java b/random-element-generation/src/test/java/uk/gov/gchq/gaffer/randomelementgeneration/cache/TestProbabilityGenerator.java index a97d9b19c..3777da4a4 100644 --- a/random-element-generation/src/test/java/uk/gov/gchq/gaffer/randomelementgeneration/cache/TestProbabilityGenerator.java +++ b/random-element-generation/src/test/java/uk/gov/gchq/gaffer/randomelementgeneration/cache/TestProbabilityGenerator.java @@ -15,7 +15,7 @@ */ 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; @@ -23,7 +23,7 @@ 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 { @@ -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 @@ -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(); } } diff --git a/ui/src/test/java/uk/gov/gchq/gaffer/ui/QueryBuilderST.java b/ui/src/test/java/uk/gov/gchq/gaffer/ui/QueryBuilderST.java index d748c3ada..fc71984cf 100644 --- a/ui/src/test/java/uk/gov/gchq/gaffer/ui/QueryBuilderST.java +++ b/ui/src/test/java/uk/gov/gchq/gaffer/ui/QueryBuilderST.java @@ -18,10 +18,10 @@ package uk.gov.gchq.gaffer.ui; import com.google.common.collect.Maps; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; import org.openqa.selenium.Keys; @@ -45,9 +45,7 @@ import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * UI system test. Runs a simple query for road use around junction M5:10. @@ -122,9 +120,9 @@ public class QueryBuilderST { private static String url; private static int slowFactor; - @BeforeClass + @BeforeAll public static void beforeClass() throws OperationException { - assertNotNull("System property " + GECKO_PROPERTY + " has not been set", System.getProperty(GECKO_PROPERTY)); + assertThat(System.getProperty(GECKO_PROPERTY)).withFailMessage("System property %s has not been set", GECKO_PROPERTY).isNotNull(); url = System.getProperty(URL_PROPERTY, DEFAULT_URL); slowFactor = Integer.parseInt(System.getProperty(SLOW_FACTOR_PROPERTY, DEFAULT_SLOW_FACTOR)); @@ -141,7 +139,7 @@ public static void beforeClass() throws OperationException { addNamedOperation(); } - @AfterClass + @AfterAll public static void afterClass() { try { driver.close(); @@ -151,7 +149,7 @@ public static void afterClass() { } } - @Before + @BeforeEach public void before() throws InterruptedException { driver.get(url); Thread.sleep(slowFactor * 1000); @@ -172,13 +170,14 @@ public void shouldFindRoadUseAroundJunctionM5_10() throws InterruptedException { click("execute-chain"); click("open-raw"); - assertEquals(EXPECTED_OPERATION_JSON, getElement("operation-0-json").getText().trim()); + assertThat(getElement("operation-0-json").getText().trim()).isEqualTo(EXPECTED_OPERATION_JSON); clickTab("Results"); final String results = getElement("raw-edge-results").getText().trim(); for (final String expectedResult : EXPECTED_RESULTS) { - assertTrue("Results did not contain: \n" + expectedResult - + "\nActual results: \n" + results, results.contains(expectedResult)); + assertThat(results.contains(expectedResult)) + .withFailMessage("Results did not contain: \n %s\nActual results: \n %s", expectedResult, results) + .isTrue(); } } @@ -196,7 +195,7 @@ public void shouldNotThrowErrorIfPageIsReloadedWithCustomView() throws Interrupt String result = getElement("raw-entity-results").getText().trim(); JSONSerialiser json = JSONSerialiser.getInstance(); List results = json.deserialise(result, List.class); - assertEquals(1, results.size()); + assertThat(results.size()).isEqualTo(1); } @Test @@ -212,8 +211,9 @@ public void shouldFindRoadUseAroundJunctionM5_10WithDatePicker() throws Interrup clickTab("Results"); final String results = getElement("raw-edge-results").getText().trim(); for (final String expectedResult : EXPECTED_RESULTS) { - assertTrue("Results did not contain: \n" + expectedResult - + "\nActual results: \n" + results, results.contains(expectedResult)); + assertThat(results.contains(expectedResult)) + .withFailMessage("Results did not contain: \n %s\nActual results: \n %s", expectedResult, results) + .isTrue(); } } @@ -252,7 +252,7 @@ public void shouldBeAbleToDeleteFiltersOnceCreated() throws InterruptedException " ]\n"; - assert (getElement("operation-0-json").getText().trim().contains(expectedString)); + assertThat(getElement("operation-0-json").getText().trim().contains(expectedString)).isTrue(); } @@ -270,7 +270,7 @@ public void shouldBeAbleToRunParameterisedQueries() throws InterruptedException, final String results = getElement("raw-other-results").getText().trim(); final List resultList = JSONSerialiser.deserialise(results.getBytes(), ArrayList.class); - assertEquals(2, resultList.size()); + assertThat(resultList.size()).isEqualTo(2); } @Test @@ -292,7 +292,7 @@ public void shouldBeAbleToSaveOperationChain() throws InterruptedException { click("md-confirm-button"); autoComplete("operation-name", "A Test Nam"); String text = getElement("operation-name").getAttribute("value"); - assertEquals("A Test Name", text); + assertThat(text).isEqualTo("A Test Name"); } private void enterText(final String id, final String value) throws InterruptedException { @@ -341,7 +341,7 @@ private void selectMultiOption(final String id, final String... values) throws I choice.click(); } - assertNotNull("You must provide at least one option", choice); + assertThat(choice).withFailMessage("You must provide at least one option").isNotNull(); choice.sendKeys(Keys.ESCAPE);