Skip to content

Commit

Permalink
Core: Switch tests to JUnit5 in catalog,encryption,inmemory,io,view p…
Browse files Browse the repository at this point in the history
…ackages (#7767)
  • Loading branch information
skytin1004 authored Jun 15, 2023
1 parent 84b8338 commit c115f49
Show file tree
Hide file tree
Showing 15 changed files with 1,013 additions and 822 deletions.
1,196 changes: 665 additions & 531 deletions core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,44 @@
package org.apache.iceberg.catalog;

import org.assertj.core.api.Assertions;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class TestTableIdentifierParser {

@Test
public void testTableIdentifierToJson() {
String json = "{\"namespace\":[\"accounting\",\"tax\"],\"name\":\"paid\"}";
TableIdentifier identifier = TableIdentifier.of(Namespace.of("accounting", "tax"), "paid");
Assert.assertEquals(
"Should be able to serialize a table identifier with both namespace and name",
json,
TableIdentifierParser.toJson(identifier));
Assertions.assertThat(TableIdentifierParser.toJson(identifier))
.as("Should be able to serialize a table identifier with both namespace and name")
.isEqualTo(json);

TableIdentifier identifierWithEmptyNamespace = TableIdentifier.of(Namespace.empty(), "paid");
String jsonWithEmptyNamespace = "{\"namespace\":[],\"name\":\"paid\"}";
Assert.assertEquals(
"Should be able to serialize a table identifier that uses the empty namespace",
jsonWithEmptyNamespace,
TableIdentifierParser.toJson(identifierWithEmptyNamespace));
Assertions.assertThat(TableIdentifierParser.toJson(identifierWithEmptyNamespace))
.as("Should be able to serialize a table identifier that uses the empty namespace")
.isEqualTo(jsonWithEmptyNamespace);
}

@Test
public void testTableIdentifierFromJson() {
String json = "{\"namespace\":[\"accounting\",\"tax\"],\"name\":\"paid\"}";
TableIdentifier identifier = TableIdentifier.of(Namespace.of("accounting", "tax"), "paid");
Assert.assertEquals(
"Should be able to deserialize a valid table identifier",
identifier,
TableIdentifierParser.fromJson(json));
Assertions.assertThat(TableIdentifierParser.fromJson(json))
.as("Should be able to deserialize a valid table identifier")
.isEqualTo(identifier);

TableIdentifier identifierWithEmptyNamespace = TableIdentifier.of(Namespace.empty(), "paid");
String jsonWithEmptyNamespace = "{\"namespace\":[],\"name\":\"paid\"}";
Assert.assertEquals(
"Should be able to deserialize a valid multi-level table identifier",
identifierWithEmptyNamespace,
TableIdentifierParser.fromJson(jsonWithEmptyNamespace));
Assertions.assertThat(TableIdentifierParser.fromJson(jsonWithEmptyNamespace))
.as("Should be able to deserialize a valid multi-level table identifier")
.isEqualTo(identifierWithEmptyNamespace);

String identifierMissingNamespace = "{\"name\":\"paid\"}";
Assert.assertEquals(
"Should implicitly convert a missing namespace into the the empty namespace when parsing",
identifierWithEmptyNamespace,
TableIdentifierParser.fromJson(identifierMissingNamespace));
Assertions.assertThat(TableIdentifierParser.fromJson(identifierMissingNamespace))
.as(
"Should implicitly convert a missing namespace into the the empty namespace when parsing")
.isEqualTo(identifierWithEmptyNamespace);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
*/
package org.apache.iceberg.encryption;

import static org.assertj.core.api.Assertions.assertThat;

import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class TestCiphers {

Expand Down Expand Up @@ -49,7 +50,7 @@ private void testEncryptDecrypt(byte[] aad) {

Ciphers.AesGcmDecryptor decryptor = new Ciphers.AesGcmDecryptor(key);
byte[] decryptedText = decryptor.decrypt(ciphertext, aad);
Assert.assertArrayEquals("Key length " + keyLength, plaintext, decryptedText);
assertThat(decryptedText).as("Key length " + keyLength).isEqualTo(plaintext);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.iceberg.exceptions.AlreadyExistsException;
import org.apache.iceberg.exceptions.NotFoundException;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class TestInMemoryFileIO {
String location = "s3://foo/bar.txt";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.assertj.core.api.Assertions;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class TestInMemoryInputFile {
@Test
public void testReadAfterClose() throws IOException {
InMemoryInputFile inputFile =
new InMemoryInputFile("abc".getBytes(StandardCharsets.ISO_8859_1));
InputStream inputStream = inputFile.newStream();
Assert.assertEquals('a', inputStream.read());
Assertions.assertThat(inputStream.read()).isEqualTo('a');
inputStream.close();
Assertions.assertThatThrownBy(inputStream::read).hasMessage("Stream is closed");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class TestInMemoryOutputFile {
@Test
Expand Down
Loading

0 comments on commit c115f49

Please sign in to comment.