Skip to content

Commit

Permalink
Replace Junit with testng (apache#3675)
Browse files Browse the repository at this point in the history
  • Loading branch information
Like authored and sijie committed Feb 25, 2019
1 parent ebc70de commit fe7311c
Show file tree
Hide file tree
Showing 25 changed files with 137 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertNotNull;

public class DeadLetterTopicTest extends ProducerConsumerBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import org.apache.pulsar.client.impl.MessageImpl;
import org.apache.pulsar.client.impl.TopicMessageImpl;
import org.apache.pulsar.common.api.proto.PulsarApi;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,32 @@
*/
package org.apache.flink.batch.connectors.pulsar;

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

import static org.testng.Assert.assertNotNull;

import static org.junit.Assert.assertNotNull;

/**
* Tests for Pulsar Avro Output Format
*/
public class PulsarAvroOutputFormatTest {

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarAvroOutputFormatConstructorWhenServiceUrlIsNull() {
new PulsarAvroOutputFormat(null, "testTopic");
}

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarAvroOutputFormatConstructorWhenTopicNameIsNull() {
new PulsarAvroOutputFormat("testServiceUrl", null);
}

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarAvroOutputFormatConstructorWhenTopicNameIsBlank() {
new PulsarAvroOutputFormat("testServiceUrl", " ");
}

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarAvroOutputFormatConstructorWhenServiceUrlIsBlank() {
new PulsarAvroOutputFormat(" ", "testTopic");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@
*/
package org.apache.flink.batch.connectors.pulsar;

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

import static org.junit.Assert.assertNotNull;
import static org.testng.Assert.assertNotNull;

/**
* Tests for Pulsar Csv Output Format
*/
public class PulsarCsvOutputFormatTest {

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarCsvOutputFormatConstructorWhenServiceUrlIsNull() {
new PulsarCsvOutputFormat(null, "testTopic");
}

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarCsvOutputFormatConstructorWhenTopicNameIsNull() {
new PulsarCsvOutputFormat("testServiceUrl", null);
}

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarCsvOutputFormatConstructorWhenTopicNameIsBlank() {
new PulsarCsvOutputFormat("testServiceUrl", " ");
}

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarCsvOutputFormatConstructorWhenServiceUrlIsBlank() {
new PulsarCsvOutputFormat(" ", "testTopic");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@
*/
package org.apache.flink.batch.connectors.pulsar;

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

import static org.junit.Assert.assertNotNull;
import static org.testng.Assert.assertNotNull;

/**
* Tests for Pulsar Json Output Format
*/
public class PulsarJsonOutputFormatTest {

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarJsonOutputFormatConstructorWhenServiceUrlIsNull() {
new PulsarJsonOutputFormat(null, "testTopic");
}

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarJsonOutputFormatConstructorWhenTopicNameIsNull() {
new PulsarJsonOutputFormat("testServiceUrl", null);
}

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarJsonOutputFormatConstructorWhenTopicNameIsBlank() {
new PulsarJsonOutputFormat("testServiceUrl", " ");
}

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarJsonOutputFormatConstructorWhenServiceUrlIsBlank() {
new PulsarJsonOutputFormat(" ", "testTopic");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,40 @@

import org.apache.commons.io.IOUtils;
import org.apache.flink.api.common.serialization.SerializationSchema;
import org.junit.Test;
import org.testng.annotations.Test;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

/**
* Tests for Pulsar Output Format
*/
public class PulsarOutputFormatTest {

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarOutputFormatConstructorWhenServiceUrlIsNull() {
new PulsarOutputFormat(null, "testTopic", text -> text.toString().getBytes());
}

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarOutputFormatConstructorWhenTopicNameIsNull() {
new PulsarOutputFormat("testServiceUrl", null, text -> text.toString().getBytes());
}

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarOutputFormatConstructorWhenTopicNameIsBlank() {
new PulsarOutputFormat("testServiceUrl", " ", text -> text.toString().getBytes());
}

@Test(expected = IllegalArgumentException.class)
@Test(expectedExceptions = IllegalArgumentException.class)
public void testPulsarOutputFormatConstructorWhenServiceUrlIsBlank() {
new PulsarOutputFormat(" ", "testTopic", text -> text.toString().getBytes());
}

@Test(expected = NullPointerException.class)
@Test(expectedExceptions = NullPointerException.class)
public void testPulsarOutputFormatConstructorWhenSerializationSchemaIsNull() {
new PulsarOutputFormat("testServiceUrl", "testTopic", null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import org.apache.avro.generic.GenericRecord;
import org.apache.flink.avro.generated.NasaMission;
import org.apache.flink.formats.avro.AvroDeserializationSchema;
import org.junit.Test;
import org.testng.annotations.Test;

import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static org.testng.Assert.assertEquals;

/**
* Tests for Avro Serialization Schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

import org.apache.commons.io.IOUtils;
import org.apache.flink.api.java.tuple.Tuple3;
import org.junit.Test;
import org.testng.annotations.Test;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

import static org.junit.Assert.assertEquals;
import static org.testng.Assert.assertEquals;

/**
* Tests for Csv Serialization Schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
package org.apache.flink.batch.connectors.pulsar.serialization;

import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.testng.annotations.Test;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

import static org.junit.Assert.assertEquals;
import static org.testng.Assert.assertEquals;

/**
* Tests for Json Serialization Schema
Expand All @@ -49,7 +49,7 @@ public void testJsonSerializationSchemaWithEmptyRecord() throws IOException {
assertEquals(jsonContent, "{\"id\":0,\"name\":null}");
}

@Test(expected = RuntimeException.class)
@Test(expectedExceptions = RuntimeException.class)
public void testJsonSerializationSchemaWithNotSerializableObject() {
NotSerializableObject notSerializableObject = new NotSerializableObject();
JsonSerializationSchema schema = new JsonSerializationSchema();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
import org.apache.flink.streaming.connectors.pulsar.partitioner.PulsarKeyExtractor;
import org.apache.flink.table.sinks.TableSink;
import org.apache.flink.types.Row;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import org.powermock.api.mockito.PowerMockito;
import org.testng.annotations.Test;

import static org.testng.Assert.assertNotNull;
import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;

/**
* Unit test of {@link PulsarAvroTableSink}.
Expand Down Expand Up @@ -58,10 +60,10 @@ public void testConfigure() throws Exception {

TableSink<Row> configuredSink = sink.configure(fieldNames, typeInformations);

Assert.assertArrayEquals(fieldNames, configuredSink.getFieldNames());
Assert.assertArrayEquals(typeInformations, configuredSink.getFieldTypes());
Assert.assertNotNull(((PulsarAvroTableSink) configuredSink).keyExtractor);
Assert.assertNotNull(((PulsarAvroTableSink) configuredSink).serializationSchema);
assertArrayEquals(fieldNames, configuredSink.getFieldNames());
assertArrayEquals(typeInformations, configuredSink.getFieldTypes());
assertNotNull(((PulsarAvroTableSink) configuredSink).keyExtractor);
assertNotNull(((PulsarAvroTableSink) configuredSink).serializationSchema);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.util.AbstractStreamOperatorTestHarness;

import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.ConsumerStats;
import org.apache.pulsar.client.api.Message;
Expand All @@ -40,11 +39,11 @@
import org.apache.pulsar.client.api.Schema;
import org.apache.pulsar.client.impl.MessageImpl;
import org.apache.pulsar.shade.io.netty.buffer.Unpooled;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.util.ArrayDeque;
import java.util.ArrayList;
Expand Down Expand Up @@ -82,7 +81,7 @@ public class PulsarConsumerSourceTests {

private Exception exception;

@Before
@BeforeMethod
public void before() {
context = new TestSourceContext();

Expand All @@ -95,7 +94,7 @@ public void before() {
});
}

@After
@AfterMethod
public void after() throws Exception {
if (source != null) {
source.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import org.apache.flink.streaming.connectors.pulsar.partitioner.PulsarKeyExtractor;
import org.apache.flink.table.sinks.TableSink;
import org.apache.flink.types.Row;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import org.powermock.api.mockito.PowerMockito;
import org.testng.Assert;
import org.testng.annotations.Test;

import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;

/**
* Unit test of {@link PulsarJsonTableSink}.
Expand All @@ -55,8 +57,8 @@ public void testConfigure() throws Exception {

TableSink<Row> configuredSink = sink.configure(fieldNames, typeInformations);

Assert.assertArrayEquals(fieldNames, configuredSink.getFieldNames());
Assert.assertArrayEquals(typeInformations, configuredSink.getFieldTypes());
assertArrayEquals(fieldNames, configuredSink.getFieldNames());
assertArrayEquals(typeInformations, configuredSink.getFieldTypes());
Assert.assertNotNull(((PulsarJsonTableSink) configuredSink).keyExtractor);
Assert.assertNotNull(((PulsarJsonTableSink) configuredSink).serializationSchema);
}
Expand Down
Loading

0 comments on commit fe7311c

Please sign in to comment.