Skip to content

Commit fe05cc1

Browse files
findepijasonf20
authored andcommitted
Statically import methods from AssertJ Assertions (apache#10517)
1 parent 2efd317 commit fe05cc1

File tree

179 files changed

+3295
-3731
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+3295
-3731
lines changed

.baseline/checkstyle/checkstyle.xml

+4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
<property name="format" value="^\s*import\s+static\s+(?!\Qorg.assertj.core.api.Assertions.\E).*\.assertThatThrownBy;"/>
9393
<property name="message" value="assertThatThrownBy() should be statically imported from org.assertj.core.api.Assertions"/>
9494
</module>
95+
<module name="RegexpMultiline">
96+
<property name="format" value="^\s*import\s+\Qorg.assertj.core.api.Assertions;\E" />
97+
<property name="message" value="org.assertj.core.api.Assertions should only be used with static imports" />
98+
</module>
9599
<module name="SuppressionFilter"> <!-- baseline-gradle: README.md -->
96100
<property name="file" value="${config_loc}/checkstyle-suppressions.xml"/>
97101
</module>

aliyun/src/test/java/org/apache/iceberg/aliyun/TestAliyunClientFactories.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,32 @@
1818
*/
1919
package org.apache.iceberg.aliyun;
2020

21+
import static org.assertj.core.api.Assertions.assertThat;
22+
2123
import com.aliyun.oss.OSS;
2224
import java.util.Map;
2325
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
2426
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
25-
import org.assertj.core.api.Assertions;
2627
import org.junit.jupiter.api.Test;
2728

2829
public class TestAliyunClientFactories {
2930

3031
@Test
3132
public void testLoadDefault() {
32-
Assertions.assertThat(AliyunClientFactories.defaultFactory())
33+
assertThat(AliyunClientFactories.defaultFactory())
3334
.as("Default client should be singleton")
3435
.isEqualTo(AliyunClientFactories.defaultFactory());
3536

3637
AliyunClientFactory defaultFactory = AliyunClientFactories.from(Maps.newHashMap());
37-
Assertions.assertThat(defaultFactory)
38+
assertThat(defaultFactory)
3839
.as("Should load default when factory impl not configured")
3940
.isInstanceOf(AliyunClientFactories.DefaultAliyunClientFactory.class);
4041

41-
Assertions.assertThat(defaultFactory.aliyunProperties().accessKeyId())
42+
assertThat(defaultFactory.aliyunProperties().accessKeyId())
4243
.as("Should have no Aliyun properties set")
4344
.isNull();
4445

45-
Assertions.assertThat(defaultFactory.aliyunProperties().securityToken())
46+
assertThat(defaultFactory.aliyunProperties().securityToken())
4647
.as("Should have no security token")
4748
.isNull();
4849

@@ -53,15 +54,15 @@ public void testLoadDefault() {
5354
"key",
5455
AliyunProperties.CLIENT_SECURITY_TOKEN,
5556
"token"));
56-
Assertions.assertThat(defaultFactoryWithConfig)
57+
assertThat(defaultFactoryWithConfig)
5758
.as("Should load default when factory impl not configured")
5859
.isInstanceOf(AliyunClientFactories.DefaultAliyunClientFactory.class);
5960

60-
Assertions.assertThat(defaultFactoryWithConfig.aliyunProperties().accessKeyId())
61+
assertThat(defaultFactoryWithConfig.aliyunProperties().accessKeyId())
6162
.as("Should have access key set")
6263
.isEqualTo("key");
6364

64-
Assertions.assertThat(defaultFactoryWithConfig.aliyunProperties().securityToken())
65+
assertThat(defaultFactoryWithConfig.aliyunProperties().securityToken())
6566
.as("Should have security token set")
6667
.isEqualTo("token");
6768
}
@@ -70,7 +71,7 @@ public void testLoadDefault() {
7071
public void testLoadCustom() {
7172
Map<String, String> properties = Maps.newHashMap();
7273
properties.put(AliyunProperties.CLIENT_FACTORY, CustomFactory.class.getName());
73-
Assertions.assertThat(AliyunClientFactories.from(properties))
74+
assertThat(AliyunClientFactories.from(properties))
7475
.as("Should load custom class")
7576
.isInstanceOf(CustomFactory.class);
7677
}

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

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

21+
import static org.assertj.core.api.Assertions.assertThat;
22+
2123
import com.aliyun.oss.OSS;
2224
import com.aliyun.oss.OSSClient;
2325
import com.aliyun.oss.OSSClientBuilder;
@@ -39,7 +41,6 @@
3941
import org.apache.iceberg.relocated.com.google.common.io.ByteStreams;
4042
import org.apache.iceberg.util.SerializableSupplier;
4143
import org.apache.iceberg.util.SerializationUtil;
42-
import org.assertj.core.api.Assertions;
4344
import org.junit.jupiter.api.AfterEach;
4445
import org.junit.jupiter.api.BeforeEach;
4546
import org.junit.jupiter.api.Test;
@@ -73,33 +74,29 @@ public void testOutputFile() throws IOException {
7374
writeOSSData(out, data);
7475

7576
OSSURI uri = new OSSURI(location);
76-
Assertions.assertThat(ossClient().get().doesObjectExist(uri.bucket(), uri.key()))
77+
assertThat(ossClient().get().doesObjectExist(uri.bucket(), uri.key()))
7778
.as("OSS file should exist")
7879
.isTrue();
79-
Assertions.assertThat(out.location()).as("Should have expected location").isEqualTo(location);
80-
Assertions.assertThat(ossDataLength(uri)).as("Should have expected length").isEqualTo(dataSize);
81-
Assertions.assertThat(ossDataContent(uri, dataSize))
82-
.as("Should have expected content")
83-
.isEqualTo(data);
80+
assertThat(out.location()).as("Should have expected location").isEqualTo(location);
81+
assertThat(ossDataLength(uri)).as("Should have expected length").isEqualTo(dataSize);
82+
assertThat(ossDataContent(uri, dataSize)).as("Should have expected content").isEqualTo(data);
8483
}
8584

8685
@Test
8786
public void testInputFile() throws IOException {
8887
String location = randomLocation();
8988
InputFile in = fileIO().newInputFile(location);
90-
Assertions.assertThat(in.exists()).as("OSS file should not exist").isFalse();
89+
assertThat(in.exists()).as("OSS file should not exist").isFalse();
9190

9291
int dataSize = 1024 * 10;
9392
byte[] data = randomData(dataSize);
9493
OutputFile out = fileIO().newOutputFile(location);
9594
writeOSSData(out, data);
9695

97-
Assertions.assertThat(in.exists()).as("OSS file should exist").isTrue();
98-
Assertions.assertThat(in.location()).as("Should have expected location").isEqualTo(location);
99-
Assertions.assertThat(in.getLength()).as("Should have expected length").isEqualTo(dataSize);
100-
Assertions.assertThat(inFileContent(in, dataSize))
101-
.as("Should have expected content")
102-
.isEqualTo(data);
96+
assertThat(in.exists()).as("OSS file should exist").isTrue();
97+
assertThat(in.location()).as("Should have expected location").isEqualTo(location);
98+
assertThat(in.getLength()).as("Should have expected length").isEqualTo(dataSize);
99+
assertThat(inFileContent(in, dataSize)).as("Should have expected content").isEqualTo(data);
103100
}
104101

105102
@Test
@@ -111,22 +108,20 @@ public void testDeleteFile() throws IOException {
111108
writeOSSData(out, data);
112109

113110
InputFile in = fileIO().newInputFile(location);
114-
Assertions.assertThat(in.exists()).as("OSS file should exist").isTrue();
111+
assertThat(in.exists()).as("OSS file should exist").isTrue();
115112

116113
fileIO().deleteFile(in);
117-
Assertions.assertThat(fileIO().newInputFile(location).exists())
118-
.as("OSS file should not exist")
119-
.isFalse();
114+
assertThat(fileIO().newInputFile(location).exists()).as("OSS file should not exist").isFalse();
120115
}
121116

122117
@Test
123118
public void testLoadFileIO() {
124119
FileIO file = CatalogUtil.loadFileIO(OSS_IMPL_CLASS, ImmutableMap.of(), conf);
125-
Assertions.assertThat(file).as("Should be OSSFileIO").isInstanceOf(OSSFileIO.class);
120+
assertThat(file).as("Should be OSSFileIO").isInstanceOf(OSSFileIO.class);
126121

127122
byte[] data = SerializationUtil.serializeToBytes(file);
128123
FileIO expectedFileIO = SerializationUtil.deserializeFromBytes(data);
129-
Assertions.assertThat(expectedFileIO)
124+
assertThat(expectedFileIO)
130125
.as("The deserialized FileIO should be OSSFileIO")
131126
.isInstanceOf(OSSFileIO.class);
132127
}
@@ -143,22 +138,20 @@ public void serializeClient() throws URISyntaxException {
143138
SerializableSupplier<OSS> post = SerializationUtil.deserializeFromBytes(data);
144139

145140
OSS client = post.get();
146-
Assertions.assertThat(client)
147-
.as("Should be instance of oss client")
148-
.isInstanceOf(OSSClient.class);
141+
assertThat(client).as("Should be instance of oss client").isInstanceOf(OSSClient.class);
149142

150143
OSSClient oss = (OSSClient) client;
151-
Assertions.assertThat(oss.getEndpoint())
144+
assertThat(oss.getEndpoint())
152145
.as("Should have expected endpoint")
153146
.isEqualTo(new URI("http://" + endpoint));
154147

155-
Assertions.assertThat(oss.getCredentialsProvider().getCredentials().getAccessKeyId())
148+
assertThat(oss.getCredentialsProvider().getCredentials().getAccessKeyId())
156149
.as("Should have expected access key")
157150
.isEqualTo(accessKeyId);
158-
Assertions.assertThat(oss.getCredentialsProvider().getCredentials().getSecretAccessKey())
151+
assertThat(oss.getCredentialsProvider().getCredentials().getSecretAccessKey())
159152
.as("Should have expected secret key")
160153
.isEqualTo(accessSecret);
161-
Assertions.assertThat(oss.getCredentialsProvider().getCredentials().getSecurityToken())
154+
assertThat(oss.getCredentialsProvider().getCredentials().getSecurityToken())
162155
.as("Should have no security token")
163156
.isNull();
164157
}

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

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

21+
import static org.assertj.core.api.Assertions.assertThat;
22+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2123
import static org.mockito.AdditionalAnswers.delegatesTo;
2224
import static org.mockito.Mockito.mock;
2325
import static org.mockito.Mockito.reset;
@@ -36,7 +38,6 @@
3638
import org.apache.iceberg.io.SeekableInputStream;
3739
import org.apache.iceberg.metrics.MetricsContext;
3840
import org.apache.iceberg.relocated.com.google.common.io.ByteStreams;
39-
import org.assertj.core.api.Assertions;
4041
import org.junit.jupiter.api.Test;
4142

4243
public class TestOSSInputFile extends AliyunOSSTestBase {
@@ -60,7 +61,7 @@ public void testReadFile() throws Exception {
6061
@Test
6162
public void testOSSInputFile() {
6263
OSSURI uri = randomURI();
63-
Assertions.assertThatThrownBy(
64+
assertThatThrownBy(
6465
() ->
6566
new OSSInputFile(
6667
ossClient().get(), uri, aliyunProperties, -1, MetricsContext.nullMetrics()))
@@ -74,15 +75,15 @@ public void testExists() {
7475

7576
InputFile inputFile =
7677
new OSSInputFile(ossMock, uri, aliyunProperties, MetricsContext.nullMetrics());
77-
Assertions.assertThat(inputFile.exists()).as("OSS file should not exist").isFalse();
78+
assertThat(inputFile.exists()).as("OSS file should not exist").isFalse();
7879
verify(ossMock, times(1)).getSimplifiedObjectMeta(uri.bucket(), uri.key());
7980
reset(ossMock);
8081

8182
int dataSize = 1024;
8283
byte[] data = randomData(dataSize);
8384
writeOSSData(uri, data);
8485

85-
Assertions.assertThat(inputFile.exists()).as("OSS file should exist").isTrue();
86+
assertThat(inputFile.exists()).as("OSS file should exist").isTrue();
8687
inputFile.exists();
8788
verify(ossMock, times(1)).getSimplifiedObjectMeta(uri.bucket(), uri.key());
8889
reset(ossMock);
@@ -108,17 +109,15 @@ public void testGetLength() {
108109
private void readAndVerify(OSSURI uri, byte[] data) throws IOException {
109110
InputFile inputFile =
110111
new OSSInputFile(ossClient().get(), uri, aliyunProperties, MetricsContext.nullMetrics());
111-
Assertions.assertThat(inputFile.exists()).as("OSS file should exist").isTrue();
112-
Assertions.assertThat(inputFile.getLength())
113-
.as("Should have expected file length")
114-
.isEqualTo(data.length);
112+
assertThat(inputFile.exists()).as("OSS file should exist").isTrue();
113+
assertThat(inputFile.getLength()).as("Should have expected file length").isEqualTo(data.length);
115114

116115
byte[] actual = new byte[data.length];
117116
try (SeekableInputStream in = inputFile.newStream()) {
118117
ByteStreams.readFully(in, actual);
119118
}
120119

121-
Assertions.assertThat(actual).as("Should have same object content").isEqualTo(data);
120+
assertThat(actual).as("Should have same object content").isEqualTo(data);
122121
}
123122

124123
private void verifyLength(OSS ossClientMock, OSSURI uri, byte[] data, boolean isCache) {
@@ -132,9 +131,7 @@ private void verifyLength(OSS ossClientMock, OSSURI uri, byte[] data, boolean is
132131
new OSSInputFile(ossClientMock, uri, aliyunProperties, MetricsContext.nullMetrics());
133132
}
134133
inputFile.getLength();
135-
Assertions.assertThat(inputFile.getLength())
136-
.as("Should have expected file length")
137-
.isEqualTo(data.length);
134+
assertThat(inputFile.getLength()).as("Should have expected file length").isEqualTo(data.length);
138135
}
139136

140137
private OSSURI randomURI() {

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

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

21+
import static org.assertj.core.api.Assertions.assertThat;
22+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
23+
2124
import java.io.ByteArrayInputStream;
2225
import java.io.IOException;
2326
import java.util.Arrays;
2427
import java.util.Random;
2528
import java.util.concurrent.ThreadLocalRandom;
2629
import org.apache.iceberg.io.SeekableInputStream;
2730
import org.apache.iceberg.relocated.com.google.common.io.ByteStreams;
28-
import org.assertj.core.api.Assertions;
2931
import org.junit.jupiter.api.Test;
3032

3133
public class TestOSSInputStream extends AliyunOSSTestBase {
@@ -69,7 +71,7 @@ private void readAndCheck(
6971
SeekableInputStream in, long rangeStart, int size, byte[] original, boolean buffered)
7072
throws IOException {
7173
in.seek(rangeStart);
72-
Assertions.assertThat(in.getPos()).as("Should have the correct position").isEqualTo(rangeStart);
74+
assertThat(in.getPos()).as("Should have the correct position").isEqualTo(rangeStart);
7375

7476
long rangeEnd = rangeStart + size;
7577
byte[] actual = new byte[size];
@@ -83,9 +85,9 @@ private void readAndCheck(
8385
}
8486
}
8587

86-
Assertions.assertThat(in.getPos()).as("Should have the correct position").isEqualTo(rangeEnd);
88+
assertThat(in.getPos()).as("Should have the correct position").isEqualTo(rangeEnd);
8789

88-
Assertions.assertThat(actual)
90+
assertThat(actual)
8991
.as("Should have expected range data")
9092
.isEqualTo(Arrays.copyOfRange(original, (int) rangeStart, (int) rangeEnd));
9193
}
@@ -95,7 +97,7 @@ public void testClose() throws Exception {
9597
OSSURI uri = new OSSURI(location("closed.dat"));
9698
SeekableInputStream closed = new OSSInputStream(ossClient().get(), uri);
9799
closed.close();
98-
Assertions.assertThatThrownBy(() -> closed.seek(0))
100+
assertThatThrownBy(() -> closed.seek(0))
99101
.isInstanceOf(IllegalStateException.class)
100102
.hasMessageContaining("Cannot seek: already closed");
101103
}
@@ -111,7 +113,7 @@ public void testSeek() throws Exception {
111113
in.seek(expected.length / 2);
112114
byte[] actual = new byte[expected.length / 2];
113115
ByteStreams.readFully(in, actual);
114-
Assertions.assertThat(actual)
116+
assertThat(actual)
115117
.as("Should have expected seeking stream")
116118
.isEqualTo(Arrays.copyOfRange(expected, expected.length / 2, expected.length));
117119
}

0 commit comments

Comments
 (0)