Skip to content

HADOOP-19415. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-common Part12. #7672

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

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.avro.reflect.ReflectDatumReader;
import org.apache.avro.io.DecoderFactory;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class AvroTestUtil {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Progressable;
import org.apache.hadoop.conf.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;

/** Support for flat files of binary key/value pairs. */
public class TestArrayFile {
Expand Down Expand Up @@ -134,7 +134,7 @@ public void testArrayFileIteration() {
FileSystem fs = FileSystem.get(conf);
ArrayFile.Writer writer = new ArrayFile.Writer(conf, fs, TEST_FILE,
LongWritable.class, CompressionType.RECORD, defaultProgressable);
assertNotNull("testArrayFileIteration error !!!", writer);
assertNotNull(writer, "testArrayFileIteration error !!!");

for (int i = 0; i < SIZE; i++)
writer.append(new LongWritable(i));
Expand All @@ -149,15 +149,15 @@ public void testArrayFileIteration() {
assertThat(nextWritable.get()).isEqualTo(i);
}

assertTrue("testArrayFileIteration seek error !!!",
reader.seek(new LongWritable(6)));
assertTrue(reader.seek(new LongWritable(6)),
"testArrayFileIteration seek error !!!");
nextWritable = (LongWritable) reader.next(nextWritable);
assertThat(reader.key()).withFailMessage(
"testArrayFileIteration error !!!").isEqualTo(7);
assertThat(nextWritable).withFailMessage(
"testArrayFileIteration error !!!").isEqualTo(new LongWritable(7));
assertFalse("testArrayFileIteration error !!!",
reader.seek(new LongWritable(SIZE + 5)));
assertFalse(reader.seek(new LongWritable(SIZE + 5)),
"testArrayFileIteration error !!!");
reader.close();
} catch (Exception ex) {
fail("testArrayFileWriterConstruction error !!!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import java.util.Arrays;

import org.apache.hadoop.util.StringUtils;
import org.junit.Test;
import org.junit.Before;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;


/** Unit tests for {@link ArrayPrimitiveWritable} */
Expand All @@ -48,7 +48,7 @@ public class TestArrayPrimitiveWritable {
final DataOutputBuffer out = new DataOutputBuffer();
final DataInputBuffer in = new DataInputBuffer();

@Before
@BeforeEach
public void resetBuffers() throws IOException {
out.reset();
in.reset();
Expand Down Expand Up @@ -79,12 +79,11 @@ public void testMany() throws IOException {
//validate data structures and values
assertEquals(expectedResultSet.length, resultSet.length);
for (int x = 0; x < resultSet.length; x++) {
assertEquals("ComponentType of array " + x,
expectedResultSet[x].getClass().getComponentType(),
resultSet[x].getClass().getComponentType());
assertEquals(expectedResultSet[x].getClass().getComponentType(),
resultSet[x].getClass().getComponentType(), "ComponentType of array " + x);
}
assertTrue("In and Out arrays didn't match values",
Arrays.deepEquals(expectedResultSet, resultSet));
assertTrue(Arrays.deepEquals(expectedResultSet, resultSet),
"In and Out arrays didn't match values");
}

@Test
Expand All @@ -107,36 +106,35 @@ public void testObjectLabeling() throws IOException {
//Read the int[] object as written by ObjectWritable, but
//"going around" ObjectWritable
String className = UTF8.readString(in);
assertEquals("The int[] written by ObjectWritable was not labelled as "
+ "an ArrayPrimitiveWritable.Internal",
ArrayPrimitiveWritable.Internal.class.getName(), className);
assertEquals(ArrayPrimitiveWritable.Internal.class.getName(), className,
"The int[] written by ObjectWritable was not labelled as "
+ "an ArrayPrimitiveWritable.Internal");
ArrayPrimitiveWritable.Internal apwi =
new ArrayPrimitiveWritable.Internal();
apwi.readFields(in);
assertEquals("The ArrayPrimitiveWritable.Internal component type was corrupted",
int.class, apw.getComponentType());
assertTrue("The int[] written by ObjectWritable as "
+ "ArrayPrimitiveWritable.Internal was corrupted",
Arrays.equals(i, (int[])(apwi.get())));
assertEquals(int.class, apw.getComponentType(),
"The ArrayPrimitiveWritable.Internal component type was corrupted");
assertTrue(Arrays.equals(i, (int[])(apwi.get())), "The int[] written by ObjectWritable as "
+ "ArrayPrimitiveWritable.Internal was corrupted");

//Read the APW object as written by ObjectWritable, but
//"going around" ObjectWritable
String declaredClassName = UTF8.readString(in);
assertEquals("The APW written by ObjectWritable was not labelled as "
+ "declaredClass ArrayPrimitiveWritable",
ArrayPrimitiveWritable.class.getName(), declaredClassName);
assertEquals(ArrayPrimitiveWritable.class.getName(), declaredClassName,
"The APW written by ObjectWritable was not labelled as "
+ "declaredClass ArrayPrimitiveWritable");
className = UTF8.readString(in);
assertEquals("The APW written by ObjectWritable was not labelled as "
+ "class ArrayPrimitiveWritable",
ArrayPrimitiveWritable.class.getName(), className);
assertEquals(ArrayPrimitiveWritable.class.getName(), className,
"The APW written by ObjectWritable was not labelled as "
+ "class ArrayPrimitiveWritable");
ArrayPrimitiveWritable apw2 =
new ArrayPrimitiveWritable();
apw2.readFields(in);
assertEquals("The ArrayPrimitiveWritable component type was corrupted",
int.class, apw2.getComponentType());
assertTrue("The int[] written by ObjectWritable as "
+ "ArrayPrimitiveWritable was corrupted",
Arrays.equals(i, (int[])(apw2.get())));
assertEquals(int.class, apw2.getComponentType(),
"The ArrayPrimitiveWritable component type was corrupted");
assertTrue(Arrays.equals(i, (int[])(apw2.get())),
"The int[] written by ObjectWritable as "
+ "ArrayPrimitiveWritable was corrupted");
}

@Test
Expand All @@ -154,13 +152,14 @@ public void testOldFormat() throws IOException {
//"going around" ObjectWritable
@SuppressWarnings("deprecation")
String className = UTF8.readString(in);
assertEquals("The int[] written by ObjectWritable as a non-compact array "
+ "was not labelled as an array of int",
i.getClass().getName(), className);
assertEquals(i.getClass().getName(), className,
"The int[] written by ObjectWritable as a non-compact array "
+ "was not labelled as an array of int");

int length = in.readInt();
assertEquals("The int[] written by ObjectWritable as a non-compact array "
+ "was not expected length", i.length, length);
assertEquals(i.length, length,
"The int[] written by ObjectWritable as a non-compact array "
+ "was not expected length");

int[] readValue = new int[length];
try {
Expand All @@ -173,8 +172,9 @@ public void testOldFormat() throws IOException {
+ length + ". Got exception:\n"
+ StringUtils.stringifyException(e));
}
assertTrue("The int[] written by ObjectWritable as a non-compact array "
+ "was corrupted.", Arrays.equals(i, readValue));
assertTrue(Arrays.equals(i, readValue),
"The int[] written by ObjectWritable as a non-compact array "
+ "was corrupted.");

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@

package org.apache.hadoop.io;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;

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


/** Unit tests for ArrayWritable */
Expand Down Expand Up @@ -73,7 +74,8 @@ public void testArrayWritableToArray() {
arrayWritable.set(elements);
Object array = arrayWritable.toArray();

assertTrue("TestArrayWritable testArrayWritableToArray error!!! ", array instanceof Text[]);
assertTrue(array instanceof Text[],
"TestArrayWritable testArrayWritableToArray error!!! ");
Text[] destElements = (Text[]) array;

for (int i = 0; i < elements.length; i++) {
Expand All @@ -84,9 +86,11 @@ public void testArrayWritableToArray() {
/**
* test {@link ArrayWritable} constructor with null
*/
@Test(expected = IllegalArgumentException.class)
@Test
public void testNullArgument() {
new ArrayWritable((Class<? extends Writable>) null);
assertThrows(IllegalArgumentException.class, () -> {
new ArrayWritable((Class<? extends Writable>) null);
});
}

/**
Expand All @@ -96,10 +100,10 @@ public void testNullArgument() {
public void testArrayWritableStringConstructor() {
String[] original = { "test1", "test2", "test3" };
ArrayWritable arrayWritable = new ArrayWritable(original);
assertEquals("testArrayWritableStringConstructor class error!!!",
Text.class, arrayWritable.getValueClass());
assertArrayEquals("testArrayWritableStringConstructor toString error!!!",
original, arrayWritable.toStrings());
assertEquals(Text.class, arrayWritable.getValueClass(),
"testArrayWritableStringConstructor class error!!!");
assertArrayEquals(original, arrayWritable.toStrings(),
"testArrayWritableStringConstructor toString error!!!");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

package org.apache.hadoop.io;

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -42,13 +44,13 @@
import org.apache.hadoop.io.compress.Decompressor;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Progressable;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Before;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TestBloomMapFile {
private static final Logger LOG =
Expand All @@ -59,7 +61,7 @@ public class TestBloomMapFile {
private static final Path TEST_DIR = new Path(TEST_ROOT, "testfile");
private static final Path TEST_FILE = new Path(TEST_ROOT, "testfile");

@Before
@BeforeEach
public void setUp() throws Exception {
LocalFileSystem fs = FileSystem.getLocal(conf);
if (fs.exists(TEST_ROOT) && !fs.delete(TEST_ROOT, true)) {
Expand Down Expand Up @@ -134,8 +136,8 @@ private void checkMembershipVaryingSizedKeys(List<Text> keys)
reader = new BloomMapFile.Reader(fs, qualifiedDirName.toString(), conf);
Collections.reverse(keys);
for (Text key : keys) {
assertTrue("False negative for existing key " + key,
reader.probablyHasKey(key));
assertTrue(reader.probablyHasKey(key),
"False negative for existing key " + key);
}
reader.close();
fs.delete(qualifiedDirName, true);
Expand Down Expand Up @@ -171,7 +173,7 @@ public void testDeleteFile() {
writer = new BloomMapFile.Writer(conf, TEST_FILE,
MapFile.Writer.keyClass(IntWritable.class),
MapFile.Writer.valueClass(Text.class));
assertNotNull("testDeleteFile error !!!", writer);
assertNotNull(writer, "testDeleteFile error !!!");
writer.close();
BloomMapFile.delete(fs, TEST_FILE.toString());
} catch (Exception ex) {
Expand Down Expand Up @@ -201,8 +203,8 @@ public void testIOExceptionInWriterConstructor() {
reader = new BloomMapFile.Reader(dirNameSpy, conf,
MapFile.Reader.comparator(new WritableComparator(IntWritable.class)));

assertNull("testIOExceptionInWriterConstructor error !!!",
reader.getBloomFilter());
assertNull(reader.getBloomFilter(),
"testIOExceptionInWriterConstructor error !!!");
} catch (Exception ex) {
fail("unexpect ex in testIOExceptionInWriterConstructor !!!");
} finally {
Expand Down Expand Up @@ -232,12 +234,12 @@ public void testGetBloomMapFile() {
MapFile.Reader.comparator(new WritableComparator(IntWritable.class)));

for (int i = 0; i < SIZE; i++) {
assertNotNull("testGetBloomMapFile error !!!",
reader.get(new IntWritable(i), new Text()));
assertNotNull(reader.get(new IntWritable(i), new Text()),
"testGetBloomMapFile error !!!");
}

assertNull("testGetBloomMapFile error !!!",
reader.get(new IntWritable(SIZE + 5), new Text()));
assertNull(reader.get(new IntWritable(SIZE + 5), new Text()),
"testGetBloomMapFile error !!!");
} catch (Exception ex) {
fail("unexpect ex in testGetBloomMapFile !!!");
} finally {
Expand All @@ -258,34 +260,34 @@ public void testBloomMapFileConstructors() {
writer = new BloomMapFile.Writer(conf, ts,
testFileName, IntWritable.class, Text.class, CompressionType.BLOCK,
defaultCodec, defaultProgress);
assertNotNull("testBloomMapFileConstructors error !!!", writer);
assertNotNull(writer, "testBloomMapFileConstructors error !!!");
writer.close();
writer = new BloomMapFile.Writer(conf, ts,
testFileName, IntWritable.class, Text.class, CompressionType.BLOCK,
defaultProgress);
assertNotNull("testBloomMapFileConstructors error !!!", writer);
assertNotNull(writer, "testBloomMapFileConstructors error !!!");
writer.close();
writer = new BloomMapFile.Writer(conf, ts,
testFileName, IntWritable.class, Text.class, CompressionType.BLOCK);
assertNotNull("testBloomMapFileConstructors error !!!", writer);
assertNotNull(writer, "testBloomMapFileConstructors error !!!");
writer.close();
writer = new BloomMapFile.Writer(conf, ts,
testFileName, IntWritable.class, Text.class, CompressionType.RECORD,
defaultCodec, defaultProgress);
assertNotNull("testBloomMapFileConstructors error !!!", writer);
assertNotNull(writer, "testBloomMapFileConstructors error !!!");
writer.close();
writer = new BloomMapFile.Writer(conf, ts,
testFileName, IntWritable.class, Text.class, CompressionType.RECORD,
defaultProgress);
assertNotNull("testBloomMapFileConstructors error !!!", writer);
assertNotNull(writer, "testBloomMapFileConstructors error !!!");
writer.close();
writer = new BloomMapFile.Writer(conf, ts,
testFileName, IntWritable.class, Text.class, CompressionType.RECORD);
assertNotNull("testBloomMapFileConstructors error !!!", writer);
assertNotNull(writer, "testBloomMapFileConstructors error !!!");
writer.close();
writer = new BloomMapFile.Writer(conf, ts,
testFileName, WritableComparator.get(Text.class), Text.class);
assertNotNull("testBloomMapFileConstructors error !!!", writer);
assertNotNull(writer, "testBloomMapFileConstructors error !!!");
writer.close();
} catch (Exception ex) {
fail("testBloomMapFileConstructors error !!!");
Expand Down
Loading