Migrate all tests to JUnit5
diff --git a/pom.xml b/pom.xml
index 6f85a88..f5f385a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -107,12 +107,6 @@
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
- <!-- Test dependencies -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.apache.accumulo</groupId>
<artifactId>accumulo-minicluster</artifactId>
@@ -123,6 +117,12 @@
<artifactId>accumulo-test</artifactId>
<scope>test</scope>
</dependency>
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
diff --git a/src/test/java/org/apache/accumulo/examples/ExamplesIT.java b/src/test/java/org/apache/accumulo/examples/ExamplesIT.java
index 11fcb9c..2840881 100644
--- a/src/test/java/org/apache/accumulo/examples/ExamplesIT.java
+++ b/src/test/java/org/apache/accumulo/examples/ExamplesIT.java
@@ -18,10 +18,11 @@
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
+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;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.BufferedWriter;
import java.io.File;
@@ -75,10 +76,9 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import com.google.common.collect.Iterators;
@@ -100,7 +100,7 @@
cfg.setProperty(Property.TSERV_NATIVEMAP_ENABLED, "false");
}
- @Before
+ @BeforeEach
public void setupTest() throws Exception {
c = Accumulo.newClient().from(getClientProps()).build();
String user = c.whoami();
@@ -111,7 +111,7 @@
String passwd = new String(((PasswordToken) getAdminToken()).getPassword(), UTF_8);
writeClientPropsFile(getClientPropsFile(), instance, keepers, user, passwd);
} else {
- Assert.fail("Unknown token type: " + token);
+ fail("Unknown token type: " + token);
}
fs = getCluster().getFileSystem();
dir = new Path(cluster.getTemporaryPath(), getClass().getName()).toString();
@@ -120,7 +120,7 @@
c.securityOperations().changeUserAuthorizations(user, new Authorizations(auths.split(",")));
}
- @After
+ @AfterEach
public void teardownTest() throws Exception {
if (null != origAuths) {
c.securityOperations().changeUserAuthorizations(getAdminPrincipal(), origAuths);
@@ -186,10 +186,10 @@
bw.flush();
Iterator<Entry<Key,Value>> iter = c.createScanner(table, Authorizations.EMPTY).iterator();
- assertTrue("Iterator had no results", iter.hasNext());
+ assertTrue(iter.hasNext(), "Iterator had no results");
Entry<Key,Value> e = iter.next();
- assertEquals("Results ", "1,3,4,2", e.getValue().toString());
- assertFalse("Iterator had additional results", iter.hasNext());
+ assertEquals("1,3,4,2", e.getValue().toString(), "Results ");
+ assertFalse(iter.hasNext(), "Iterator had additional results");
m = new Mutation("foo");
m.put("a", "b", "0,20,20,2");
@@ -197,10 +197,10 @@
bw.close();
iter = c.createScanner(table, Authorizations.EMPTY).iterator();
- assertTrue("Iterator had no results", iter.hasNext());
+ assertTrue(iter.hasNext(), "Iterator had no results");
e = iter.next();
- assertEquals("Results ", "0,20,24,4", e.getValue().toString());
- assertFalse("Iterator had additional results", iter.hasNext());
+ assertEquals("0,20,24,4", e.getValue().toString(), "Results ");
+ assertFalse(iter.hasNext(), "Iterator had additional results");
}
@Test
@@ -220,8 +220,10 @@
// should find ourselves
boolean thisFile = false;
for (String file : found) {
- if (file.endsWith("/ExamplesIT.java"))
+ if (file.endsWith("/ExamplesIT.java")) {
thisFile = true;
+ break;
+ }
}
assertTrue(thisFile);
@@ -280,7 +282,7 @@
assumeTrue(getAdminToken() instanceof PasswordToken);
Path readme = new Path(new Path(System.getProperty("user.dir")), "README.md");
if (!new File(readme.toString()).exists()) {
- Assert.fail("README.md does not exist!");
+ fail("README.md does not exist!");
}
fs.copyFromLocalFile(readme, new Path(dir + "/tmp/wc/README.md"));
String[] args = new String[] {"-c", getClientPropsFile(), "-i", dir + "/tmp/wc", "-t",
@@ -333,6 +335,6 @@
// We're already slurping stdout into memory (not redirecting to file). Might as well add it
// to error message.
pair = getClusterControl().execWithStdout(theClass, args);
- Assert.assertEquals("stdout=" + pair.getValue(), 0, pair.getKey().intValue());
+ assertEquals(0, pair.getKey().intValue(), "stdout=" + pair.getValue());
}
}
diff --git a/src/test/java/org/apache/accumulo/examples/constraints/AlphaNumKeyConstraintTest.java b/src/test/java/org/apache/accumulo/examples/constraints/AlphaNumKeyConstraintTest.java
index dc2cece..a114ed9 100644
--- a/src/test/java/org/apache/accumulo/examples/constraints/AlphaNumKeyConstraintTest.java
+++ b/src/test/java/org/apache/accumulo/examples/constraints/AlphaNumKeyConstraintTest.java
@@ -16,13 +16,13 @@
*/
package org.apache.accumulo.examples.constraints;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.Value;
import org.apache.hadoop.io.Text;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import com.google.common.collect.ImmutableList;
diff --git a/src/test/java/org/apache/accumulo/examples/constraints/NumericValueConstraintTest.java b/src/test/java/org/apache/accumulo/examples/constraints/NumericValueConstraintTest.java
index 8e89545..1b0c72e 100644
--- a/src/test/java/org/apache/accumulo/examples/constraints/NumericValueConstraintTest.java
+++ b/src/test/java/org/apache/accumulo/examples/constraints/NumericValueConstraintTest.java
@@ -16,13 +16,13 @@
*/
package org.apache.accumulo.examples.constraints;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.Value;
import org.apache.hadoop.io.Text;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import com.google.common.collect.Iterables;
diff --git a/src/test/java/org/apache/accumulo/examples/dirlist/CountIT.java b/src/test/java/org/apache/accumulo/examples/dirlist/CountIT.java
index 950b295..51f6f9a 100644
--- a/src/test/java/org/apache/accumulo/examples/dirlist/CountIT.java
+++ b/src/test/java/org/apache/accumulo/examples/dirlist/CountIT.java
@@ -16,8 +16,8 @@
*/
package org.apache.accumulo.examples.dirlist;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import java.util.ArrayList;
import java.util.Map.Entry;
@@ -39,9 +39,9 @@
import org.apache.accumulo.test.functional.ConfigurableMacBase;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Text;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
public class CountIT extends ConfigurableMacBase {
@@ -53,7 +53,7 @@
cfg.setProperty(Property.TSERV_NATIVEMAP_ENABLED, "false");
}
- @Before
+ @BeforeEach
public void setupInstance() throws Exception {
tableName = getUniqueNames(1)[0];
client = Accumulo.newClient().from(getClientProperties()).build();
@@ -75,7 +75,7 @@
bw.close();
}
- @After
+ @AfterEach
public void teardown() {
client.close();
}
diff --git a/src/test/java/org/apache/accumulo/examples/filedata/ChunkCombinerTest.java b/src/test/java/org/apache/accumulo/examples/filedata/ChunkCombinerTest.java
index e64f5fa..300637a 100644
--- a/src/test/java/org/apache/accumulo/examples/filedata/ChunkCombinerTest.java
+++ b/src/test/java/org/apache/accumulo/examples/filedata/ChunkCombinerTest.java
@@ -16,6 +16,11 @@
*/
package org.apache.accumulo.examples.filedata;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
@@ -33,10 +38,10 @@
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.iterators.IteratorEnvironment;
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
-import junit.framework.TestCase;
-
-public class ChunkCombinerTest extends TestCase {
+public class ChunkCombinerTest {
public static class MapIterator implements SortedKeyValueIterator<Key,Value> {
private Iterator<Entry<Key,Value>> iter;
@@ -76,7 +81,7 @@
}
@Override
- public void next() throws IOException {
+ public void next() {
entry = null;
while (iter.hasNext()) {
entry = iter.next();
@@ -92,8 +97,7 @@
}
@Override
- public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
- throws IOException {
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) {
if (!inclusive) {
throw new IllegalArgumentException("can only do inclusive colf filtering");
}
@@ -114,43 +118,34 @@
@Override
public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
- IteratorEnvironment env) throws IOException {
+ IteratorEnvironment env) {
throw new UnsupportedOperationException();
}
}
- private TreeMap<Key,Value> row1;
- private TreeMap<Key,Value> row2;
- private TreeMap<Key,Value> row3;
- private TreeMap<Key,Value> allRows;
+ private static TreeMap<Key,Value> allRows;
- private TreeMap<Key,Value> cRow1;
- private TreeMap<Key,Value> cRow2;
- private TreeMap<Key,Value> cRow3;
- private TreeMap<Key,Value> allCRows;
+ private static TreeMap<Key,Value> allCRows;
- private TreeMap<Key,Value> cOnlyRow1;
- private TreeMap<Key,Value> cOnlyRow2;
- private TreeMap<Key,Value> cOnlyRow3;
- private TreeMap<Key,Value> allCOnlyRows;
+ private static TreeMap<Key,Value> allCOnlyRows;
- private TreeMap<Key,Value> badrow;
+ private static TreeMap<Key,Value> badrow;
- @Override
- protected void setUp() {
- row1 = new TreeMap<>();
- row2 = new TreeMap<>();
- row3 = new TreeMap<>();
+ @BeforeAll
+ protected static void setUp() {
+ TreeMap<Key,Value> row1 = new TreeMap<>();
+ TreeMap<Key,Value> row2 = new TreeMap<>();
+ TreeMap<Key,Value> row3 = new TreeMap<>();
allRows = new TreeMap<>();
- cRow1 = new TreeMap<>();
- cRow2 = new TreeMap<>();
- cRow3 = new TreeMap<>();
+ TreeMap<Key,Value> cRow1 = new TreeMap<>();
+ TreeMap<Key,Value> cRow2 = new TreeMap<>();
+ TreeMap<Key,Value> cRow3 = new TreeMap<>();
allCRows = new TreeMap<>();
- cOnlyRow1 = new TreeMap<>();
- cOnlyRow2 = new TreeMap<>();
- cOnlyRow3 = new TreeMap<>();
+ TreeMap<Key,Value> cOnlyRow1 = new TreeMap<>();
+ TreeMap<Key,Value> cOnlyRow2 = new TreeMap<>();
+ TreeMap<Key,Value> cOnlyRow3 = new TreeMap<>();
allCOnlyRows = new TreeMap<>();
badrow = new TreeMap<>();
@@ -225,6 +220,7 @@
private static final Collection<ByteSequence> emptyColfs = new HashSet<>();
+ @Test
public void test1() throws IOException {
runTest(false, allRows, allCRows, emptyColfs);
runTest(true, allRows, allCRows, emptyColfs);
@@ -250,7 +246,7 @@
TreeMap<Key,Value> seen = new TreeMap<>();
while (iter.hasTop()) {
- assertFalse("already contains " + iter.getTopKey(), seen.containsKey(iter.getTopKey()));
+ assertFalse(seen.containsKey(iter.getTopKey()), "already contains " + iter.getTopKey());
seen.put(new Key(iter.getTopKey()), new Value(iter.getTopValue()));
if (reseek)
diff --git a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputFormatIT.java b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputFormatIT.java
index ee0900a..f24aa15 100644
--- a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputFormatIT.java
+++ b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputFormatIT.java
@@ -17,10 +17,10 @@
package org.apache.accumulo.examples.filedata;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import java.io.IOException;
@@ -48,10 +48,10 @@
import org.apache.hadoop.mapreduce.lib.output.NullOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
@@ -75,19 +75,19 @@
private AccumuloClient client;
private String tableName;
- @Before
+ @BeforeEach
public void setupInstance() throws Exception {
client = Accumulo.newClient().from(getClientProps()).build();
tableName = getUniqueNames(1)[0];
client.securityOperations().changeUserAuthorizations(client.whoami(), AUTHS);
}
- @After
+ @AfterEach
public void teardown() {
client.close();
}
- @BeforeClass
+ @BeforeAll
public static void setupClass() {
System.setProperty("hadoop.tmp.dir", System.getProperty("user.dir") + "/target/hadoop-tmp");
@@ -154,7 +154,7 @@
}
@Override
- protected void cleanup(Context context) throws IOException, InterruptedException {
+ protected void cleanup(Context context) {
String table = context.getConfiguration().get("MRTester_tableName");
assertNotNull(table);
@@ -203,8 +203,7 @@
public static class TestBadData
extends Mapper<List<Entry<Key,Value>>,InputStream,List<Entry<Key,Value>>,InputStream> {
@Override
- protected void map(List<Entry<Key,Value>> key, InputStream value, Context context)
- throws IOException, InterruptedException {
+ protected void map(List<Entry<Key,Value>> key, InputStream value, Context context) {
String table = context.getConfiguration().get("MRTester_tableName");
assertNotNull(table);
diff --git a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamIT.java b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamIT.java
index cf28d1d..66cb18c 100644
--- a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamIT.java
+++ b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamIT.java
@@ -17,8 +17,8 @@
package org.apache.accumulo.examples.filedata;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import java.io.IOException;
import java.util.ArrayList;
@@ -45,9 +45,9 @@
import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Text;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import com.google.common.collect.Iterators;
import com.google.common.collect.PeekingIterator;
@@ -67,19 +67,19 @@
private List<Entry<Key,Value>> baddata;
private List<Entry<Key,Value>> multidata;
- @Before
+ @BeforeEach
public void setupInstance() throws Exception {
client = Accumulo.newClient().from(getClientProps()).build();
tableName = getUniqueNames(1)[0];
client.securityOperations().changeUserAuthorizations(client.whoami(), AUTHS);
}
- @After
+ @AfterEach
public void teardown() {
client.close();
}
- @Before
+ @BeforeEach
public void setupData() {
data = new ArrayList<>();
addData(data, "a", "refs", "id\0ext", "A&B", "ext");
diff --git a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamTest.java b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamTest.java
index 2ff9892..e0bc356 100644
--- a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamTest.java
+++ b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputStreamTest.java
@@ -16,9 +16,9 @@
*/
package org.apache.accumulo.examples.filedata;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.util.ArrayList;
@@ -29,8 +29,8 @@
import org.apache.accumulo.core.data.KeyValue;
import org.apache.accumulo.core.data.Value;
import org.apache.hadoop.io.Text;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,7 +43,7 @@
private List<Entry<Key,Value>> baddata;
private List<Entry<Key,Value>> multidata;
- @Before
+ @BeforeEach
public void setupData() {
data = new ArrayList<>();
addData(data, "a", "refs", "id\0ext", "A&B", "ext");
diff --git a/src/test/java/org/apache/accumulo/examples/filedata/KeyUtilTest.java b/src/test/java/org/apache/accumulo/examples/filedata/KeyUtilTest.java
index 7f28882..245220a 100644
--- a/src/test/java/org/apache/accumulo/examples/filedata/KeyUtilTest.java
+++ b/src/test/java/org/apache/accumulo/examples/filedata/KeyUtilTest.java
@@ -16,11 +16,12 @@
*/
package org.apache.accumulo.examples.filedata;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import org.apache.hadoop.io.Text;
+import org.junit.jupiter.api.Test;
-import junit.framework.TestCase;
-
-public class KeyUtilTest extends TestCase {
+public class KeyUtilTest {
public static void checkSeps(String... s) {
Text t = KeyUtil.buildNullSepText(s);
String[] rets = KeyUtil.splitNullSepText(t);
@@ -34,6 +35,7 @@
assertEquals(s[i], rets[i]);
}
+ @Test
public void testNullSep() {
checkSeps("abc", "d", "", "efgh");
checkSeps("ab", "");
diff --git a/src/test/java/org/apache/accumulo/examples/mapreduce/MapReduceIT.java b/src/test/java/org/apache/accumulo/examples/mapreduce/MapReduceIT.java
index b77ae9e..1133195 100644
--- a/src/test/java/org/apache/accumulo/examples/mapreduce/MapReduceIT.java
+++ b/src/test/java/org/apache/accumulo/examples/mapreduce/MapReduceIT.java
@@ -16,7 +16,7 @@
*/
package org.apache.accumulo.examples.mapreduce;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.security.MessageDigest;
import java.util.Base64;
@@ -40,7 +40,7 @@
import org.apache.accumulo.test.functional.ConfigurableMacBase;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Text;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class MapReduceIT extends ConfigurableMacBase {