Skip to content

Commit

Permalink
Migrate tests to JUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
martint committed Oct 29, 2023
1 parent 9d6d75b commit 92728e7
Show file tree
Hide file tree
Showing 26 changed files with 75 additions and 51 deletions.
10 changes: 8 additions & 2 deletions lib/trino-hive-formats/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<artifactId>junit-extensions</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<artifactId>testing</artifactId>
Expand Down Expand Up @@ -208,8 +214,8 @@
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import io.airlift.slice.Slice;
import io.airlift.slice.Slices;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package io.trino.hive.formats;

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

import java.time.LocalDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import io.airlift.slice.SliceOutput;
import io.airlift.slice.Slices;
import org.apache.hadoop.io.WritableUtils;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import io.trino.filesystem.TrinoInputFile;
import io.trino.filesystem.TrinoInputStream;
import io.trino.filesystem.memory.MemoryInputFile;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayOutputStream;
import java.io.EOFException;
Expand All @@ -40,6 +40,7 @@
import static io.airlift.slice.SizeOf.sizeOfByteArray;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

@SuppressWarnings("resource")
public class TestTrinoDataInputStream
Expand Down Expand Up @@ -486,36 +487,44 @@ public void testEmptyRead()
assertThat(input.read()).isEqualTo(-1);
}

@Test(expectedExceptions = EOFException.class)
@Test
public void testReadByteBeyondEnd()
throws Exception
{
TrinoDataInputStream input = createTrinoDataInputStream(new byte[0]);
input.readByte();
assertThatThrownBy(() -> {
TrinoDataInputStream input = createTrinoDataInputStream(new byte[0]);
input.readByte();
})
.isInstanceOf(EOFException.class);
}

@Test(expectedExceptions = EOFException.class)
@Test
public void testReadShortBeyondEnd()
throws Exception
{
TrinoDataInputStream input = createTrinoDataInputStream(new byte[1]);
input.readShort();
assertThatThrownBy(() -> {
TrinoDataInputStream input = createTrinoDataInputStream(new byte[1]);
input.readShort();
})
.isInstanceOf(EOFException.class);
}

@Test(expectedExceptions = EOFException.class)
@Test
public void testReadIntBeyondEnd()
throws Exception
{
TrinoDataInputStream input = createTrinoDataInputStream(new byte[3]);
input.readInt();
assertThatThrownBy(() -> {
TrinoDataInputStream input = createTrinoDataInputStream(new byte[3]);
input.readInt();
})
.isInstanceOf(EOFException.class);
}

@Test(expectedExceptions = EOFException.class)
@Test
public void testReadLongBeyondEnd()
throws Exception
{
TrinoDataInputStream input = createTrinoDataInputStream(new byte[7]);
input.readLong();
assertThatThrownBy(() -> {
TrinoDataInputStream input = createTrinoDataInputStream(new byte[7]);
input.readLong();
})
.isInstanceOf(EOFException.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@
import org.apache.avro.generic.GenericRecordBuilder;
import org.apache.avro.util.RandomData;
import org.apache.avro.util.Utf8;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down Expand Up @@ -83,7 +84,9 @@
import static java.lang.Float.floatToIntBits;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.within;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;

@TestInstance(PER_CLASS)
public abstract class TestAvroBase
{
protected static final TypeOperators TYPE_OPERATORS = new TypeOperators();
Expand Down Expand Up @@ -185,7 +188,7 @@ public abstract class TestAvroBase
ALL_TYPES_PAGE = new Page(allTypeBlocks.build().toArray(Block[]::new));
}

@BeforeClass
@BeforeAll
public void setup()
{
try {
Expand Down Expand Up @@ -269,7 +272,7 @@ public void testSerdeCycles()
}
}

@AfterClass(alwaysRun = true)
@AfterAll
public void cleanup()
{
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
import org.apache.avro.SchemaBuilder;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericRecord;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import java.io.IOException;
import java.math.BigInteger;
Expand All @@ -57,7 +58,9 @@
import static io.trino.hive.formats.avro.NativeLogicalTypesAvroTypeManager.padBigEndianToSize;
import static io.trino.spi.type.Decimals.MAX_SHORT_PRECISION;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;

@TestInstance(PER_CLASS)
public class TestAvroPageDataReaderWithAvroNativeTypeManagement
extends TestAvroBase
{
Expand Down Expand Up @@ -166,7 +169,7 @@ public class TestAvroPageDataReaderWithAvroNativeTypeManagement
ALL_SUPPORTED_PAGE = new Page(blocks.build().toArray(Block[]::new));
}

@BeforeClass
@BeforeAll
public void testStatics()
{
// Identity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.util.RandomData;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.apache.avro.file.DataFileReader;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericRecord;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import com.google.common.primitives.Longs;
import io.trino.spi.type.Int128;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import io.airlift.slice.Slice;
import io.airlift.slice.Slices;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayOutputStream;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.google.common.collect.DiscreteDomain;
import com.google.common.collect.Range;
import io.trino.hadoop.HadoopNative;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package io.trino.hive.formats.line;

import com.google.common.collect.ImmutableList;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package io.trino.hive.formats.line;

import com.google.common.primitives.Bytes;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.math.BigDecimal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import io.starburst.openjson.JSONException;
import io.starburst.openjson.JSONObject;
import io.starburst.openjson.JSONTokener;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.junit.jupiter.api.Test;
import org.openx.data.jsonserde.JsonSerDe;
import org.testng.annotations.Test;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.math.BigDecimal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.FileInputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import io.trino.filesystem.memory.MemoryInputFile;
import io.trino.hive.formats.line.LineBuffer;
import io.trino.hive.formats.line.LineReader;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.math.BigDecimal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.google.common.collect.ImmutableSet;
import io.trino.hive.formats.compression.CompressionKind;
import io.trino.hive.formats.line.LineBuffer;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import io.trino.filesystem.memory.MemoryInputFile;
import io.trino.hive.formats.line.LineBuffer;
import io.trino.hive.formats.line.LineReader;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.nio.charset.StandardCharsets;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import io.trino.spi.type.SqlDecimal;
import io.trino.spi.type.SqlVarbinary;
import org.joda.time.DateTimeZone;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import java.math.BigInteger;
import java.util.ArrayList;
Expand All @@ -49,7 +50,9 @@
import static java.util.Collections.nCopies;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;

@TestInstance(PER_CLASS)
public abstract class AbstractTestRcFileReader
{
private static final DecimalType DECIMAL_TYPE_PRECISION_2 = DecimalType.createDecimalType(2, 1);
Expand All @@ -66,7 +69,7 @@ public AbstractTestRcFileReader(RcFileTester tester)
this.tester = tester;
}

@BeforeClass
@BeforeAll
public void setUp()
{
assertThat(DateTimeZone.getDefault()).isEqualTo(RcFileTester.HIVE_STORAGE_TIME_ZONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.trino.hive.formats.encodings.binary.BinaryColumnEncodingFactory;
import io.trino.spi.block.Block;
import org.joda.time.DateTimeZone;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;
Expand Down

0 comments on commit 92728e7

Please sign in to comment.