Skip to content
Permalink
Browse files
[FLINK-27662][tests] Migrate TypeInformationTestBase to JUnit5
  • Loading branch information
snuyanzin authored and zentol committed May 17, 2022
1 parent 3719369 commit 62d64eb48139473f7dfd622f6fff723d21e65a5c
Showing 33 changed files with 108 additions and 106 deletions.
@@ -23,8 +23,7 @@
import org.apache.flink.connector.file.sink.utils.FileSinkTestUtils;

/** Test for {@link CompactorRequestTypeInfo}. */
public class CompactorRequestTypeInfoTest
extends TypeInformationTestBase<CompactorRequestTypeInfo> {
class CompactorRequestTypeInfoTest extends TypeInformationTestBase<CompactorRequestTypeInfo> {

@Override
protected CompactorRequestTypeInfo[] getTestData() {
@@ -27,7 +27,7 @@
import java.io.IOException;

/** Test for {@link WritableTypeInfo}. */
public class WritableTypeInfoTest extends TypeInformationTestBase<WritableTypeInfo<?>> {
class WritableTypeInfoTest extends TypeInformationTestBase<WritableTypeInfo<?>> {

@Override
protected WritableTypeInfo<?>[] getTestData() {
@@ -21,7 +21,7 @@
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

/** Test for {@link BasicArrayTypeInfo}. */
public class BasicArrayTypeInfoTest extends TypeInformationTestBase<BasicArrayTypeInfo<?, ?>> {
class BasicArrayTypeInfoTest extends TypeInformationTestBase<BasicArrayTypeInfo<?, ?>> {

@Override
protected BasicArrayTypeInfo<?, ?>[] getTestData() {
@@ -21,7 +21,7 @@
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

/** Test for {@link BasicTypeInfo}. */
public class BasicTypeInfoTest extends TypeInformationTestBase<BasicTypeInfo<?>> {
class BasicTypeInfoTest extends TypeInformationTestBase<BasicTypeInfo<?>> {

@Override
protected BasicTypeInfo<?>[] getTestData() {
@@ -21,7 +21,7 @@
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

/** Test for {@link FractionalTypeInfo}. */
public class FractionalTypeInfoTest extends TypeInformationTestBase<FractionalTypeInfo<?>> {
class FractionalTypeInfoTest extends TypeInformationTestBase<FractionalTypeInfo<?>> {

@Override
protected FractionalTypeInfo<?>[] getTestData() {
@@ -21,7 +21,7 @@
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

/** Test for {@link IntegerTypeInfo}. */
public class IntegerTypeInfoTest extends TypeInformationTestBase<IntegerTypeInfo<?>> {
class IntegerTypeInfoTest extends TypeInformationTestBase<IntegerTypeInfo<?>> {

@Override
protected IntegerTypeInfo<?>[] getTestData() {
@@ -21,7 +21,7 @@
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

/** Test for {@link SqlTimeTypeInfo}. */
public class LocalTimeTypeInfoTest extends TypeInformationTestBase<LocalTimeTypeInfo<?>> {
class LocalTimeTypeInfoTest extends TypeInformationTestBase<LocalTimeTypeInfo<?>> {

@Override
protected LocalTimeTypeInfo<?>[] getTestData() {
@@ -21,7 +21,7 @@
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

/** Test for {@link NothingTypeInfo}. */
public class NothingTypeInfoTest extends TypeInformationTestBase<NothingTypeInfo> {
class NothingTypeInfoTest extends TypeInformationTestBase<NothingTypeInfo> {

@Override
protected NothingTypeInfo[] getTestData() {
@@ -21,7 +21,7 @@
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

/** Test for {@link NumericTypeInfo}. */
public class NumericTypeInfoTest extends TypeInformationTestBase<NumericTypeInfo<?>> {
class NumericTypeInfoTest extends TypeInformationTestBase<NumericTypeInfo<?>> {

@Override
protected NumericTypeInfo<?>[] getTestData() {
@@ -21,7 +21,7 @@
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

/** Test for {@link PrimitiveArrayTypeInfoTest}. */
public class PrimitiveArrayTypeInfoTest extends TypeInformationTestBase<PrimitiveArrayTypeInfo<?>> {
class PrimitiveArrayTypeInfoTest extends TypeInformationTestBase<PrimitiveArrayTypeInfo<?>> {

@Override
protected PrimitiveArrayTypeInfo<?>[] getTestData() {
@@ -21,7 +21,7 @@
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

/** Test for {@link SqlTimeTypeInfo}. */
public class SqlTimeTypeInfoTest extends TypeInformationTestBase<SqlTimeTypeInfo<?>> {
class SqlTimeTypeInfoTest extends TypeInformationTestBase<SqlTimeTypeInfo<?>> {

@Override
protected SqlTimeTypeInfo<?>[] getTestData() {
@@ -21,24 +21,23 @@
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.util.InstantiationUtil;
import org.apache.flink.util.TestLogger;
import org.apache.flink.util.TestLoggerExtension;

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

import java.io.IOException;

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

/** Abstract test base for type information. */
public abstract class TypeInformationTestBase<T extends TypeInformation<?>> extends TestLogger {
@ExtendWith(TestLoggerExtension.class)
public abstract class TypeInformationTestBase<T extends TypeInformation<?>> {

protected abstract T[] getTestData();

@Test
public void testHashcodeAndEquals() throws Exception {
void testHashcodeAndEquals() throws Exception {
final T[] testData = getTestData();
final TypeInformation<?> unrelatedTypeInfo = new UnrelatedTypeInfo();

@@ -60,25 +59,26 @@ public void testHashcodeAndEquals() throws Exception {
for (T otherTypeInfo : testData) {
// test equality
if (typeInfo == otherTypeInfo) {
assertTrue(
"hashCode() returns inconsistent results.",
typeInfo.hashCode() == otherTypeInfo.hashCode());
assertEquals("equals() is false for same object.", typeInfo, otherTypeInfo);
assertThat(typeInfo.hashCode())
.as("hashCode() returns inconsistent results.")
.isEqualTo(otherTypeInfo.hashCode());
assertThat(typeInfo)
.as("equals() is false for same object.")
.isEqualTo(otherTypeInfo);
}
// test inequality
else {
assertNotEquals(
"equals() returned true for different objects.",
typeInfo,
otherTypeInfo);
assertThat(typeInfo)
.as("equals() returned true for different objects.")
.isNotEqualTo(otherTypeInfo);
}
}

// compare with unrelated type
assertFalse(
"Type information allows to compare with unrelated type.",
typeInfo.canEqual(unrelatedTypeInfo));
assertNotEquals(typeInfo, unrelatedTypeInfo);
assertThat(typeInfo.canEqual(unrelatedTypeInfo))
.as("Type information allows to compare with unrelated type.")
.isFalse();
assertThat(typeInfo).isNotEqualTo(unrelatedTypeInfo);
}
}

@@ -112,7 +112,9 @@ public void testSerialization() {
public void testGetTotalFields() {
final T[] testData = getTestData();
for (T typeInfo : testData) {
assertTrue("Number of total fields must be at least 1", typeInfo.getTotalFields() > 0);
assertThat(typeInfo.getTotalFields())
.as("Number of total fields must be at least 1")
.isGreaterThan(0);
}
}

@@ -23,7 +23,7 @@
import org.apache.flink.api.java.tuple.Tuple2;

/** Test for {@link EitherTypeInfo}. */
public class EitherTypeInfoTest extends TypeInformationTestBase<EitherTypeInfo<?, ?>> {
class EitherTypeInfoTest extends TypeInformationTestBase<EitherTypeInfo<?, ?>> {

@Override
protected EitherTypeInfo<?, ?>[] getTestData() {
@@ -21,7 +21,7 @@
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

/** Test for {@link EnumTypeInfo}. */
public class EnumTypeInfoTest extends TypeInformationTestBase<EnumTypeInfo<?>> {
class EnumTypeInfoTest extends TypeInformationTestBase<EnumTypeInfo<?>> {

@Override
@SuppressWarnings("unchecked")
@@ -21,7 +21,7 @@
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

/** Test for {@link GenericTypeInfo}. */
public class GenericTypeInfoTest extends TypeInformationTestBase<GenericTypeInfo<?>> {
class GenericTypeInfoTest extends TypeInformationTestBase<GenericTypeInfo<?>> {

@Override
protected GenericTypeInfo<?>[] getTestData() {
@@ -22,7 +22,7 @@
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

/** Test for {@link ListTypeInfo}. */
public class ListTypeInfoTest extends TypeInformationTestBase<ListTypeInfo<?>> {
class ListTypeInfoTest extends TypeInformationTestBase<ListTypeInfo<?>> {

@Override
protected ListTypeInfo<?>[] getTestData() {
@@ -22,7 +22,7 @@
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

/** Test for {@link MapTypeInfo}. */
public class MapTypeInfoTest extends TypeInformationTestBase<MapTypeInfo<?, ?>> {
class MapTypeInfoTest extends TypeInformationTestBase<MapTypeInfo<?, ?>> {

@Override
protected MapTypeInfo<?, ?>[] getTestData() {
@@ -21,7 +21,7 @@
import org.apache.flink.api.common.functions.InvalidTypesException;
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

public class MissingTypeInfoTest extends TypeInformationTestBase<MissingTypeInfo> {
class MissingTypeInfoTest extends TypeInformationTestBase<MissingTypeInfo> {
private static final String functionName = "foobar";
private static final InvalidTypesException testException =
new InvalidTypesException("Test exception.");
@@ -22,7 +22,7 @@
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

/** Test for {@link MultisetTypeInfo}. */
public class MultisetTypeInfoTest extends TypeInformationTestBase<MultisetTypeInfo<?>> {
class MultisetTypeInfoTest extends TypeInformationTestBase<MultisetTypeInfo<?>> {

@Override
protected MultisetTypeInfo<?>[] getTestData() {
@@ -23,7 +23,7 @@
import java.util.ArrayList;

/** Test for {@link ObjectArrayTypeInfo}. */
public class ObjectArrayTypeInfoTest extends TypeInformationTestBase<ObjectArrayTypeInfo<?, ?>> {
class ObjectArrayTypeInfoTest extends TypeInformationTestBase<ObjectArrayTypeInfo<?, ?>> {

@Override
protected ObjectArrayTypeInfo<?, ?>[] getTestData() {
@@ -21,7 +21,7 @@
import org.apache.flink.api.common.typeutils.TypeInformationTestBase;

/** Test for {@link PojoTypeInfo}. */
public class PojoTypeInfoTest extends TypeInformationTestBase<PojoTypeInfo<?>> {
class PojoTypeInfoTest extends TypeInformationTestBase<PojoTypeInfo<?>> {

@Override
protected PojoTypeInfo<?>[] getTestData() {

0 comments on commit 62d64eb

Please sign in to comment.