Skip to content

Commit e82ecf6

Browse files
authored
Aliyun: Remove AssertHelpers (apache#7116)
1 parent 49fb12e commit e82ecf6

File tree

4 files changed

+42
-54
lines changed

4 files changed

+42
-54
lines changed

aliyun/src/test/java/org/apache/iceberg/aliyun/oss/TestOSSInputFile.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
import java.util.Random;
3131
import java.util.UUID;
3232
import java.util.concurrent.ThreadLocalRandom;
33-
import org.apache.iceberg.AssertHelpers;
3433
import org.apache.iceberg.aliyun.AliyunProperties;
3534
import org.apache.iceberg.exceptions.ValidationException;
3635
import org.apache.iceberg.io.InputFile;
3736
import org.apache.iceberg.io.SeekableInputStream;
3837
import org.apache.iceberg.metrics.MetricsContext;
3938
import org.apache.iceberg.relocated.com.google.common.io.ByteStreams;
39+
import org.assertj.core.api.Assertions;
4040
import org.junit.Assert;
4141
import org.junit.Test;
4242

@@ -61,13 +61,12 @@ public void testReadFile() throws Exception {
6161
@Test
6262
public void testOSSInputFile() {
6363
OSSURI uri = randomURI();
64-
AssertHelpers.assertThrows(
65-
"File length should not be negative",
66-
ValidationException.class,
67-
"Invalid file length",
68-
() ->
69-
new OSSInputFile(
70-
ossClient().get(), uri, aliyunProperties, -1, MetricsContext.nullMetrics()));
64+
Assertions.assertThatThrownBy(
65+
() ->
66+
new OSSInputFile(
67+
ossClient().get(), uri, aliyunProperties, -1, MetricsContext.nullMetrics()))
68+
.isInstanceOf(ValidationException.class)
69+
.hasMessageContaining("Invalid file length");
7170
}
7271

7372
@Test

aliyun/src/test/java/org/apache/iceberg/aliyun/oss/TestOSSInputStream.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.iceberg.aliyun.oss;
2020

21-
import static org.apache.iceberg.AssertHelpers.assertThrows;
2221
import static org.junit.Assert.assertArrayEquals;
2322
import static org.junit.Assert.assertEquals;
2423

@@ -29,6 +28,7 @@
2928
import java.util.concurrent.ThreadLocalRandom;
3029
import org.apache.iceberg.io.SeekableInputStream;
3130
import org.apache.iceberg.relocated.com.google.common.io.ByteStreams;
31+
import org.assertj.core.api.Assertions;
3232
import org.junit.Test;
3333

3434
public class TestOSSInputStream extends AliyunOSSTestBase {
@@ -99,14 +99,9 @@ public void testClose() throws Exception {
9999
OSSURI uri = new OSSURI(location("closed.dat"));
100100
SeekableInputStream closed = new OSSInputStream(ossClient().get(), uri);
101101
closed.close();
102-
assertThrows(
103-
"Cannot seek the input stream after closed.",
104-
IllegalStateException.class,
105-
"Cannot seek: already closed",
106-
() -> {
107-
closed.seek(0);
108-
return null;
109-
});
102+
Assertions.assertThatThrownBy(() -> closed.seek(0))
103+
.isInstanceOf(IllegalStateException.class)
104+
.hasMessageContaining("Cannot seek: already closed");
110105
}
111106

112107
@Test

aliyun/src/test/java/org/apache/iceberg/aliyun/oss/TestOSSOutputFile.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
import java.util.Random;
2727
import java.util.UUID;
2828
import java.util.concurrent.ThreadLocalRandom;
29-
import org.apache.iceberg.AssertHelpers;
3029
import org.apache.iceberg.aliyun.AliyunProperties;
3130
import org.apache.iceberg.exceptions.AlreadyExistsException;
3231
import org.apache.iceberg.io.InputFile;
3332
import org.apache.iceberg.io.OutputFile;
3433
import org.apache.iceberg.metrics.MetricsContext;
3534
import org.apache.iceberg.relocated.com.google.common.io.ByteStreams;
35+
import org.assertj.core.api.Assertions;
3636
import org.junit.Assert;
3737
import org.junit.Test;
3838

@@ -63,11 +63,10 @@ public void testWriteFile() throws IOException {
6363

6464
@Test
6565
public void testFromLocation() {
66-
AssertHelpers.assertThrows(
67-
"Should catch null location when creating oss output file",
68-
NullPointerException.class,
69-
"location cannot be null",
70-
() -> OSSOutputFile.fromLocation(ossClient, null, aliyunProperties));
66+
Assertions.assertThatThrownBy(
67+
() -> OSSOutputFile.fromLocation(ossClient, null, aliyunProperties))
68+
.isInstanceOf(NullPointerException.class)
69+
.hasMessageContaining("location cannot be null");
7170
}
7271

7372
@Test
@@ -79,11 +78,10 @@ public void testCreate() {
7978
writeOSSData(uri, data);
8079

8180
OutputFile out = OSSOutputFile.fromLocation(ossClient, uri.location(), aliyunProperties);
82-
AssertHelpers.assertThrows(
83-
"Should complain about location already exists",
84-
AlreadyExistsException.class,
85-
"Location already exists",
86-
out::create);
81+
82+
Assertions.assertThatThrownBy(out::create)
83+
.isInstanceOf(AlreadyExistsException.class)
84+
.hasMessageContaining("Location already exists");
8785
}
8886

8987
@Test

aliyun/src/test/java/org/apache/iceberg/aliyun/oss/TestOSSURI.java

+22-26
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
import static com.aliyun.oss.internal.OSSUtils.OSS_RESOURCE_MANAGER;
2222

23-
import org.apache.iceberg.AssertHelpers;
2423
import org.apache.iceberg.exceptions.ValidationException;
2524
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
25+
import org.assertj.core.api.Assertions;
2626
import org.junit.Assert;
2727
import org.junit.Test;
2828

@@ -49,47 +49,43 @@ public void testEncodedString() {
4949

5050
@Test
5151
public void invalidBucket() {
52-
AssertHelpers.assertThrows(
53-
"Invalid bucket",
54-
IllegalArgumentException.class,
55-
OSS_RESOURCE_MANAGER.getFormattedString("BucketNameInvalid", "test_bucket"),
56-
() -> new OSSURI("https://test_bucket/path/to/file"));
52+
53+
Assertions.assertThatThrownBy(() -> new OSSURI("https://test_bucket/path/to/file"))
54+
.isInstanceOf(IllegalArgumentException.class)
55+
.hasMessageContaining(
56+
OSS_RESOURCE_MANAGER.getFormattedString("BucketNameInvalid", "test_bucket"));
5757
}
5858

5959
@Test
6060
public void missingKey() {
61-
AssertHelpers.assertThrows(
62-
"Missing key",
63-
ValidationException.class,
64-
"Missing key in OSS location",
65-
() -> new OSSURI("https://bucket/"));
61+
62+
Assertions.assertThatThrownBy(() -> new OSSURI("https://bucket/"))
63+
.isInstanceOf(ValidationException.class)
64+
.hasMessageContaining("Missing key in OSS location");
6665
}
6766

6867
@Test
6968
public void invalidKey() {
70-
AssertHelpers.assertThrows(
71-
"Invalid key",
72-
IllegalArgumentException.class,
73-
OSS_RESOURCE_MANAGER.getFormattedString("ObjectKeyInvalid", "\\path/to/file"),
74-
() -> new OSSURI("https://bucket/\\path/to/file"));
69+
Assertions.assertThatThrownBy(() -> new OSSURI("https://bucket/\\path/to/file"))
70+
.isInstanceOf(IllegalArgumentException.class)
71+
.hasMessageContaining(
72+
OSS_RESOURCE_MANAGER.getFormattedString("ObjectKeyInvalid", "\\path/to/file"));
7573
}
7674

7775
@Test
7876
public void relativePathing() {
79-
AssertHelpers.assertThrows(
80-
"Cannot use relative oss location.",
81-
ValidationException.class,
82-
"Invalid OSS location",
83-
() -> new OSSURI("/path/to/file"));
77+
78+
Assertions.assertThatThrownBy(() -> new OSSURI("/path/to/file"))
79+
.isInstanceOf(ValidationException.class)
80+
.hasMessageContaining("Invalid OSS location");
8481
}
8582

8683
@Test
8784
public void invalidScheme() {
88-
AssertHelpers.assertThrows(
89-
"Only support scheme: oss/https",
90-
ValidationException.class,
91-
"Invalid scheme",
92-
() -> new OSSURI("invalid://bucket/"));
85+
86+
Assertions.assertThatThrownBy(() -> new OSSURI("invalid://bucket/"))
87+
.isInstanceOf(ValidationException.class)
88+
.hasMessageContaining("Invalid scheme");
9389
}
9490

9591
@Test

0 commit comments

Comments
 (0)