Skip to content

Commit 064dae6

Browse files
authored
Apply code style guide (#2388)
1 parent bbc47d0 commit 064dae6

File tree

13 files changed

+57
-60
lines changed

13 files changed

+57
-60
lines changed

aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/AwsXrayRemoteSamplerTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
import static java.util.Objects.requireNonNull;
99
import static org.assertj.core.api.Assertions.assertThat;
10+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1011
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
1112
import static org.awaitility.Awaitility.await;
12-
import static org.junit.jupiter.api.Assertions.assertThrows;
1313
import static org.mockito.Mockito.mock;
1414

1515
import com.google.common.io.ByteStreams;
@@ -179,16 +179,15 @@ void setAndResetSpanExporter() {
179179
try (AwsXrayRemoteSampler sampler = AwsXrayRemoteSampler.newBuilder(Resource.empty()).build()) {
180180
// Setting span exporter should only work once
181181
sampler.setSpanExporter(mock(SpanExporter.class));
182-
assertThrows(
183-
IllegalStateException.class, () -> sampler.setSpanExporter(mock(SpanExporter.class)));
182+
assertThatThrownBy(() -> sampler.setSpanExporter(mock(SpanExporter.class)))
183+
.isInstanceOf(IllegalStateException.class);
184184
}
185185
}
186186

187187
@Test
188188
void adaptSamplingWithoutSpanExporter() {
189-
assertThrows(
190-
IllegalStateException.class,
191-
() -> sampler.adaptSampling(mock(ReadableSpan.class), mock(SpanData.class)));
189+
assertThatThrownBy(() -> sampler.adaptSampling(mock(ReadableSpan.class), mock(SpanData.class)))
190+
.isInstanceOf(IllegalStateException.class);
192191
}
193192

194193
@Test
@@ -224,7 +223,8 @@ void setAdaptiveSamplingConfig() {
224223
AwsXrayAdaptiveSamplingConfig config =
225224
AwsXrayAdaptiveSamplingConfig.builder().setVersion(1.0).build();
226225
sampler.setAdaptiveSamplingConfig(config);
227-
assertThrows(IllegalStateException.class, () -> sampler.setAdaptiveSamplingConfig(config));
226+
assertThatThrownBy(() -> sampler.setAdaptiveSamplingConfig(config))
227+
.isInstanceOf(IllegalStateException.class);
228228
}
229229
}
230230

aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/XrayRulesSamplerTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import static io.opentelemetry.semconv.HttpAttributes.HTTP_RESPONSE_STATUS_CODE;
99
import static org.assertj.core.api.Assertions.assertThat;
10-
import static org.junit.jupiter.api.Assertions.assertThrows;
10+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1111
import static org.mockito.ArgumentMatchers.any;
1212
import static org.mockito.Mockito.mock;
1313
import static org.mockito.Mockito.when;
@@ -710,7 +710,8 @@ void setAdaptiveSamplingConfigTwice() {
710710
AwsXrayAdaptiveSamplingConfig config =
711711
AwsXrayAdaptiveSamplingConfig.builder().setVersion(1.0).build();
712712
sampler.setAdaptiveSamplingConfig(config);
713-
assertThrows(IllegalStateException.class, () -> sampler.setAdaptiveSamplingConfig(config));
713+
assertThatThrownBy(() -> sampler.setAdaptiveSamplingConfig(config))
714+
.isInstanceOf(IllegalStateException.class);
714715
}
715716

716717
@Test

cel-sampler/src/test/java/io/opentelemetry/contrib/sampler/cel/CelBasedSamplingExpressionTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66
package io.opentelemetry.contrib.sampler.cel;
77

8+
import static org.assertj.core.api.Assertions.assertThat;
89
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
9-
import static org.junit.jupiter.api.Assertions.assertEquals;
10-
import static org.junit.jupiter.api.Assertions.assertNotEquals;
1110

1211
import dev.cel.common.CelAbstractSyntaxTree;
1312
import dev.cel.common.CelValidationException;
@@ -35,7 +34,7 @@ void testToString() throws CelValidationException {
3534
CelBasedSamplingExpression celExpression =
3635
new CelBasedSamplingExpression(ast, Sampler.alwaysOn());
3736
String expected = "CelBasedSamplingExpression{expression='1 == 1', delegate=AlwaysOnSampler}";
38-
assertEquals(expected, celExpression.toString());
37+
assertThat(celExpression.toString()).isEqualTo(expected);
3938
}
4039

4140
@Test
@@ -45,28 +44,27 @@ void testEquals() throws CelValidationException {
4544
CelCompilerFactory.standardCelCompilerBuilder().build().compile("1 == 1").getAst(),
4645
Sampler.alwaysOn());
4746

48-
assertEquals(celExpressionOneEqualsOne1, celExpressionOneEqualsOne1);
49-
assertNotEquals(celExpressionOneEqualsOne1, null);
47+
assertThat(celExpressionOneEqualsOne1).isNotEqualTo(null);
5048

5149
CelBasedSamplingExpression celExpressionOneEqualsOne2 =
5250
new CelBasedSamplingExpression(
5351
CelCompilerFactory.standardCelCompilerBuilder().build().compile("1 == 1").getAst(),
5452
Sampler.alwaysOn());
5553

56-
assertEquals(celExpressionOneEqualsOne1, celExpressionOneEqualsOne2);
54+
assertThat(celExpressionOneEqualsOne1).isEqualTo(celExpressionOneEqualsOne2);
5755

5856
CelBasedSamplingExpression celExpressionTwoEqualsTwo =
5957
new CelBasedSamplingExpression(
6058
CelCompilerFactory.standardCelCompilerBuilder().build().compile("2 == 2").getAst(),
6159
Sampler.alwaysOn());
6260

63-
assertNotEquals(celExpressionOneEqualsOne1, celExpressionTwoEqualsTwo);
61+
assertThat(celExpressionOneEqualsOne1).isNotEqualTo(celExpressionTwoEqualsTwo);
6462

6563
CelBasedSamplingExpression celExpressionOneEqualsOneSamplerOff =
6664
new CelBasedSamplingExpression(
6765
CelCompilerFactory.standardCelCompilerBuilder().build().compile("1 == 1").getAst(),
6866
Sampler.alwaysOff());
69-
assertNotEquals(celExpressionOneEqualsOne1, celExpressionOneEqualsOneSamplerOff);
67+
assertThat(celExpressionOneEqualsOne1).isNotEqualTo(celExpressionOneEqualsOneSamplerOff);
7068
}
7169

7270
@Test
@@ -78,13 +76,13 @@ void testHashCode() throws CelValidationException {
7876
int expectedHashCode1 = celExpression1.hashCode();
7977
int expectedHashCode2 = celExpression1.hashCode();
8078

81-
assertEquals(expectedHashCode1, expectedHashCode2);
79+
assertThat(expectedHashCode1).isEqualTo(expectedHashCode2);
8280

8381
CelBasedSamplingExpression celExpression2 =
8482
new CelBasedSamplingExpression(
8583
CelCompilerFactory.standardCelCompilerBuilder().build().compile("1 == 1").getAst(),
8684
Sampler.alwaysOn());
8785

88-
assertEquals(expectedHashCode1, celExpression2.hashCode());
86+
assertThat(expectedHashCode1).isEqualTo(celExpression2.hashCode());
8987
}
9088
}

disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/storage/StorageTest.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import static io.opentelemetry.contrib.disk.buffering.internal.storage.TestData.THIRD_LOG_RECORD;
1414
import static io.opentelemetry.contrib.disk.buffering.internal.storage.TestData.getConfiguration;
1515
import static org.assertj.core.api.Assertions.assertThat;
16-
import static org.junit.jupiter.api.Assertions.assertNotNull;
17-
import static org.junit.jupiter.api.Assertions.assertNull;
18-
import static org.junit.jupiter.api.Assertions.fail;
16+
import static org.assertj.core.api.Assertions.fail;
1917

2018
import io.opentelemetry.contrib.disk.buffering.internal.serialization.deserializers.SignalDeserializer;
2119
import io.opentelemetry.contrib.disk.buffering.internal.serialization.serializers.SignalSerializer;
@@ -65,15 +63,15 @@ void writeAndRead() throws IOException {
6563
forwardToReadTime();
6664

6765
ReadableResult<LogRecordData> readResult = storage.readNext(DESERIALIZER);
68-
assertNotNull(readResult);
66+
assertThat(readResult).isNotNull();
6967
assertThat(readResult.getContent()).containsExactly(FIRST_LOG_RECORD, SECOND_LOG_RECORD);
7068
assertThat(destinationDir.list()).hasSize(1);
7169

7270
// Delete result and read again
7371
readResult.delete();
7472
readResult.close();
7573
ReadableResult<LogRecordData> readResult2 = storage.readNext(DESERIALIZER);
76-
assertNotNull(readResult2);
74+
assertThat(readResult2).isNotNull();
7775
assertThat(readResult2.getContent()).containsExactly(THIRD_LOG_RECORD);
7876
assertThat(destinationDir.list()).hasSize(1);
7977

@@ -88,7 +86,7 @@ void writeAndRead() throws IOException {
8886

8987
// Read again when no more data is available (delete file)
9088
readResult2.close();
91-
assertNull(storage.readNext(DESERIALIZER));
89+
assertThat(storage.readNext(DESERIALIZER)).isNull();
9290
assertThat(destinationDir.list()).isEmpty();
9391
}
9492

@@ -100,7 +98,7 @@ void interactionAfterClosed() throws IOException {
10098
forwardToReadTime();
10199

102100
// Reading
103-
assertNull(storage.readNext(DESERIALIZER));
101+
assertThat(storage.readNext(DESERIALIZER)).isNull();
104102

105103
// Writing
106104
assertThat(write(Collections.singletonList(THIRD_LOG_RECORD))).isFalse();
@@ -125,7 +123,7 @@ void whenTheReadTimeExpires_lookForNewFileToRead() throws IOException {
125123

126124
// Read
127125
ReadableResult<LogRecordData> result = storage.readNext(DESERIALIZER);
128-
assertNotNull(result);
126+
assertThat(result).isNotNull();
129127
assertThat(result.getContent()).containsExactly(THIRD_LOG_RECORD);
130128
assertThat(destinationDir.list())
131129
.containsExactlyInAnyOrder(
@@ -156,7 +154,7 @@ void whenNoMoreLinesToRead_lookForNewFileToRead() throws IOException {
156154

157155
// Read
158156
ReadableResult<LogRecordData> result = storage.readNext(DESERIALIZER);
159-
assertNotNull(result);
157+
assertThat(result).isNotNull();
160158
assertThat(result.getContent()).containsExactly(FIRST_LOG_RECORD, SECOND_LOG_RECORD);
161159
assertThat(destinationDir.list())
162160
.containsExactlyInAnyOrder(
@@ -166,7 +164,7 @@ void whenNoMoreLinesToRead_lookForNewFileToRead() throws IOException {
166164

167165
// Read again
168166
ReadableResult<LogRecordData> result2 = storage.readNext(DESERIALIZER);
169-
assertNotNull(result2);
167+
assertThat(result2).isNotNull();
170168
assertThat(result2.getContent()).containsExactly(THIRD_LOG_RECORD);
171169
assertThat(destinationDir.list()).containsExactly(String.valueOf(secondFileWriteTime));
172170
result2.close();
@@ -188,7 +186,7 @@ void deleteFilesWithCorruptedData() throws IOException {
188186
currentTimeMillis.set(4000 + MIN_FILE_AGE_FOR_READ_MILLIS);
189187

190188
// Read
191-
assertNull(storage.readNext(DESERIALIZER));
189+
assertThat(storage.readNext(DESERIALIZER)).isNull();
192190
assertThat(destinationDir.list()).containsExactly("4000"); // it tries 3 times max per call.
193191
}
194192

disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/storage/files/ReadableFileTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import static io.opentelemetry.contrib.disk.buffering.internal.storage.TestData.getConfiguration;
1313
import static java.util.concurrent.TimeUnit.MILLISECONDS;
1414
import static org.assertj.core.api.Assertions.assertThat;
15-
import static org.junit.jupiter.api.Assertions.fail;
15+
import static org.assertj.core.api.Assertions.fail;
1616
import static org.mockito.Mockito.mock;
1717
import static org.mockito.Mockito.when;
1818

jmx-metrics/src/main/groovy/io/opentelemetry/contrib/jmxmetrics/ClientCallbackHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public class ClientCallbackHandler implements CallbackHandler {
2626
* @param password - authenticating password (plaintext)
2727
* @param realm - authenticating realm
2828
*/
29-
public ClientCallbackHandler(final String username, final String password, final String realm) {
29+
public ClientCallbackHandler(String username, String password, String realm) {
3030
this.username = username;
3131
this.password = password != null ? password.toCharArray() : null;
3232
this.realm = realm;
3333
}
3434

3535
@Override
36-
public void handle(final Callback[] callbacks) throws UnsupportedCallbackException {
36+
public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
3737
for (Callback callback : callbacks) {
3838
if (callback instanceof NameCallback) {
3939
((NameCallback) callback).setName(this.username);

jmx-metrics/src/main/groovy/io/opentelemetry/contrib/jmxmetrics/ConfigurationException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
public class ConfigurationException extends RuntimeException {
99
private static final long serialVersionUID = 0L;
1010

11-
public ConfigurationException(final String message, final Throwable cause) {
11+
public ConfigurationException(String message, Throwable cause) {
1212
super(message, cause);
1313
}
1414

15-
public ConfigurationException(final String message) {
15+
public ConfigurationException(String message) {
1616
super(message);
1717
}
1818
}

jmx-metrics/src/main/groovy/io/opentelemetry/contrib/jmxmetrics/GroovyMetricEnvironment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public GroovyMetricEnvironment(
119119
*
120120
* @param config - used to establish exporter type (logging by default) and connection info
121121
*/
122-
public GroovyMetricEnvironment(final JmxConfig config) {
122+
public GroovyMetricEnvironment(JmxConfig config) {
123123
this(
124124
config,
125125
"io.opentelemetry.contrib.jmxmetrics",
@@ -131,7 +131,7 @@ public void flush() {
131131
meterProvider.forceFlush().join(10, TimeUnit.SECONDS);
132132
}
133133

134-
protected static Attributes mapToAttributes(@Nullable final Map<String, String> labelMap) {
134+
protected static Attributes mapToAttributes(@Nullable Map<String, String> labelMap) {
135135
if (labelMap == null) {
136136
return Attributes.empty();
137137
}

jmx-metrics/src/main/groovy/io/opentelemetry/contrib/jmxmetrics/GroovyRunner.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class GroovyRunner {
4444
List<String> scriptSources = new ArrayList<>();
4545
try {
4646
if (config.targetSystems.size() != 0) {
47-
for (final String target : config.targetSystems) {
47+
for (String target : config.targetSystems) {
4848
String systemResourcePath = "target-systems/" + target + ".groovy";
4949
scriptSources.add(getTargetSystemResourceAsString(systemResourcePath));
5050
}
@@ -59,7 +59,7 @@ public class GroovyRunner {
5959

6060
this.scripts = new ArrayList<>();
6161
try {
62-
for (final String source : scriptSources) {
62+
for (String source : scriptSources) {
6363
this.scripts.add(new GroovyShell().parse(source));
6464
}
6565
} catch (CompilationFailedException e) {
@@ -74,18 +74,18 @@ public class GroovyRunner {
7474
new OtelHelper(jmxClient, this.groovyMetricEnvironment, config.aggregateAcrossMBeans);
7575
binding.setVariable("otel", otelHelper);
7676

77-
for (final Script script : scripts) {
77+
for (Script script : scripts) {
7878
script.setBinding(binding);
7979
}
8080
}
8181

82-
private static String getFileAsString(final String fileName) throws IOException {
82+
private static String getFileAsString(String fileName) throws IOException {
8383
try (InputStream is = new FileInputStream(fileName)) {
8484
return getFileFromInputStream(is);
8585
}
8686
}
8787

88-
private String getTargetSystemResourceAsString(final String targetSystem) throws IOException {
88+
private String getTargetSystemResourceAsString(String targetSystem) throws IOException {
8989
URL res = getClass().getClassLoader().getResource(targetSystem);
9090
if (res == null) {
9191
throw new ConfigurationException("Failed to load " + targetSystem);
@@ -98,15 +98,15 @@ private String getTargetSystemResourceAsString(final String targetSystem) throws
9898
}
9999

100100
private static String getTargetSystemResourceFromJarAsString(URL res) throws IOException {
101-
final String[] array = res.toString().split("!");
101+
String[] array = res.toString().split("!");
102102
if (array.length != 2) {
103103
throw new ConfigurationException(
104104
"Invalid path for target system resource from jar: " + res.toString());
105105
}
106106

107-
final Map<String, String> env = Collections.emptyMap();
107+
Map<String, String> env = Collections.emptyMap();
108108
try {
109-
try (final FileSystem fs = FileSystems.newFileSystem(URI.create(array[0]), env)) {
109+
try (FileSystem fs = FileSystems.newFileSystem(URI.create(array[0]), env)) {
110110
Path path = fs.getPath(array[1]);
111111
try (InputStream is = Files.newInputStream(path)) {
112112
return getFileFromInputStream(is);
@@ -117,7 +117,7 @@ private static String getTargetSystemResourceFromJarAsString(URL res) throws IOE
117117
}
118118
}
119119

120-
private static String getFileFromInputStream(final InputStream is) throws IOException {
120+
private static String getFileFromInputStream(InputStream is) throws IOException {
121121
if (is == null) {
122122
return null;
123123
}
@@ -134,7 +134,7 @@ private static String getFileFromInputStream(final InputStream is) throws IOExce
134134
}
135135

136136
public void run() {
137-
for (final Script script : scripts) {
137+
for (Script script : scripts) {
138138
script.run();
139139
}
140140
}

jmx-metrics/src/main/groovy/io/opentelemetry/contrib/jmxmetrics/JmxClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class JmxClient {
3333
private final boolean registrySsl;
3434
@Nullable private JMXConnector jmxConn;
3535

36-
JmxClient(final JmxConfig config) throws MalformedURLException {
36+
JmxClient(JmxConfig config) throws MalformedURLException {
3737
this.url = new JMXServiceURL(config.serviceUrl);
3838
this.username = config.username;
3939
this.password = config.password;
@@ -65,7 +65,7 @@ public MBeanServerConnection getConnection() {
6565
env.put(
6666
"jmx.remote.sasl.callback.handler",
6767
new ClientCallbackHandler(this.username, this.password, this.realm));
68-
} catch (final ReflectiveOperationException e) {
68+
} catch (ReflectiveOperationException e) {
6969
logger.warning("SASL unsupported in current environment: " + e.getMessage());
7070
}
7171

@@ -83,7 +83,7 @@ public MBeanServerConnection getConnection() {
8383
* @param objectName ObjectName to query
8484
* @return the sorted list of applicable ObjectName instances found by server
8585
*/
86-
public List<ObjectName> query(final ObjectName objectName) {
86+
public List<ObjectName> query(ObjectName objectName) {
8787
MBeanServerConnection mbsc = getConnection();
8888
if (mbsc == null) {
8989
return Collections.emptyList();

0 commit comments

Comments
 (0)