Skip to content

Commit 04df831

Browse files
committed
fixing tests erroreprone
1 parent caa8783 commit 04df831

File tree

9 files changed

+68
-79
lines changed

9 files changed

+68
-79
lines changed

ibm-mq-metrics/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ dependencies {
4848
// testImplementation(libs.org.mockito.mockito.core)
4949
// testImplementation(libs.org.mockito.mockito.junit.jupiter)
5050
// testImplementation(libs.org.assertj.assertj.core)
51-
// testImplementation(libs.io.opentelemetry.opentelemetry.sdk.testing)
51+
testImplementation("com.google.guava:guava")
52+
testImplementation("io.opentelemetry:opentelemetry-sdk-testing:1.50.0")
5253
// testImplementation(libs.com.ibm.mq.com.ibm.mq.jakarta.client)
5354
// testImplementation(libs.jakarta.jms.jakarta.jms.api)
5455
// testImplementation(libs.org.junit.jupiter.junit.jupiter.engine)

ibm-mq-metrics/src/test/java/io/opentelemetry/ibm/mq/metricscollector/ChannelMetricsCollectorTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import static io.opentelemetry.ibm.mq.metricscollector.MetricAssert.assertThatMetric;
1111
import static org.assertj.core.api.Assertions.assertThat;
1212
import static org.junit.jupiter.params.provider.Arguments.arguments;
13-
import static org.mockito.Mockito.any;
13+
import static org.mockito.ArgumentMatchers.any;
1414
import static org.mockito.Mockito.when;
1515

1616
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -25,6 +25,7 @@
2525
import io.opentelemetry.sdk.metrics.data.MetricData;
2626
import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension;
2727
import java.util.ArrayList;
28+
import java.util.Arrays;
2829
import java.util.List;
2930
import java.util.stream.Stream;
3031
import org.junit.jupiter.api.BeforeEach;
@@ -69,7 +70,7 @@ void testPublishMetrics() throws Exception {
6970

7071
List<String> metricsList =
7172
new ArrayList<>(
72-
List.of(
73+
Arrays.asList(
7374
"mq.message.count",
7475
"mq.status",
7576
"mq.byte.sent",
@@ -133,7 +134,7 @@ void testPublishMetrics() throws Exception {
133134
MQCFIN [type: 3, strucLength: 16, parameter: 1609 (MQIACH_CHANNEL_SUBSTATE), value: 300]
134135
*/
135136

136-
private PCFMessage[] createPCFResponseForInquireChannelStatusCmd() {
137+
private static PCFMessage[] createPCFResponseForInquireChannelStatusCmd() {
137138
PCFMessage response1 = new PCFMessage(2, CMQCFC.MQCMD_INQUIRE_CHANNEL_STATUS, 1, true);
138139
response1.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, "DEV.ADMIN.SVRCONN");
139140
response1.addParameter(CMQCFC.MQIACH_CHANNEL_TYPE, 7);

ibm-mq-metrics/src/test/java/io/opentelemetry/ibm/mq/metricscollector/InquireChannelCmdCollectorTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.opentelemetry.sdk.metrics.data.MetricData;
2222
import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension;
2323
import java.util.ArrayList;
24+
import java.util.Arrays;
2425
import java.util.List;
2526
import org.junit.jupiter.api.BeforeEach;
2627
import org.junit.jupiter.api.Test;
@@ -60,7 +61,7 @@ public void testProcessPCFRequestAndPublishQMetricsForInquireQStatusCmd() throws
6061
classUnderTest.accept(context);
6162
List<String> metricsList =
6263
new ArrayList<>(
63-
List.of(
64+
Arrays.asList(
6465
"mq.message.retry.count", "mq.message.received.count", "mq.message.sent.count"));
6566
for (MetricData metric : otelTesting.getMetrics()) {
6667
if (metricsList.remove(metric.getName())) {
@@ -81,7 +82,7 @@ public void testProcessPCFRequestAndPublishQMetricsForInquireQStatusCmd() throws
8182
assertThat(metricsList).isEmpty();
8283
}
8384

84-
private PCFMessage[] createPCFResponseForInquireChannelCmd() {
85+
private static PCFMessage[] createPCFResponseForInquireChannelCmd() {
8586
PCFMessage response1 = new PCFMessage(2, CMQCFC.MQCMD_INQUIRE_CHANNEL, 1, true);
8687
response1.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, "my.channel");
8788
response1.addParameter(CMQCFC.MQIACH_CHANNEL_TYPE, CMQXC.MQCHT_SVRCONN);

ibm-mq-metrics/src/test/java/io/opentelemetry/ibm/mq/metricscollector/ListenerMetricsCollectorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
package io.opentelemetry.ibm.mq.metricscollector;
77

88
import static org.assertj.core.api.Assertions.assertThat;
9-
import static org.mockito.Mockito.any;
9+
import static org.mockito.ArgumentMatchers.any;
1010
import static org.mockito.Mockito.when;
1111

1212
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -84,7 +84,7 @@ public void testPublishMetrics() throws Exception {
8484
MQCFIN [type: 3, strucLength: 16, parameter: 1599 (MQIACH_LISTENER_STATUS), value: 2]
8585
*/
8686

87-
private PCFMessage[] createPCFResponseForInquireListenerStatusCmd() {
87+
private static PCFMessage[] createPCFResponseForInquireListenerStatusCmd() {
8888
PCFMessage response1 = new PCFMessage(2, CMQCFC.MQCMD_INQUIRE_LISTENER_STATUS, 1, true);
8989
response1.addParameter(CMQCFC.MQCACH_LISTENER_NAME, "DEV.DEFAULT.LISTENER.TCP");
9090
response1.addParameter(CMQCFC.MQIACH_LISTENER_STATUS, 2);

ibm-mq-metrics/src/test/java/io/opentelemetry/ibm/mq/metricscollector/QueueCollectionBuddyTest.java

Lines changed: 37 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import static org.mockito.Mockito.when;
1010

1111
import com.fasterxml.jackson.databind.ObjectMapper;
12+
import com.google.common.collect.ImmutableMap;
1213
import com.ibm.mq.constants.CMQC;
1314
import com.ibm.mq.constants.CMQCFC;
1415
import com.ibm.mq.headers.pcf.PCFMessage;
@@ -66,32 +67,24 @@ void testProcessPcfRequestAndPublishQMetricsForInquireQStatusCmd() throws Except
6667
collectorContext, request, "*", InquireQStatusCmdCollector.ATTRIBUTES);
6768

6869
Map<String, Map<String, Long>> expectedValues =
69-
new HashMap<String, Map<String, Long>>() {
70-
{
71-
put(
70+
new HashMap<String, Map<String, Long>>(
71+
ImmutableMap.of(
7272
"DEV.DEAD.LETTER.QUEUE",
73-
new HashMap<String, Long>() {
74-
{
75-
put("mq.oldest.msg.age", -1L);
76-
put("mq.uncommitted.messages", 0L);
77-
put("mq.onqtime.1", -1L);
78-
put("mq.onqtime.2", -1L);
79-
put("mq.queue.depth", 0L);
80-
}
81-
});
82-
put(
73+
new HashMap<>(
74+
ImmutableMap.of(
75+
"mq.oldest.msg.age", -1L,
76+
"mq.uncommitted.messages", 0L,
77+
"mq.onqtime.1", -1L,
78+
"mq.onqtime.2", -1L,
79+
"mq.queue.depth", 0L)),
8380
"DEV.QUEUE.1",
84-
new HashMap<String, Long>() {
85-
{
86-
put("mq.oldest.msg.age", -1L);
87-
put("mq.uncommitted.messages", 10L);
88-
put("mq.onqtime.1", -1L);
89-
put("mq.onqtime.2", -1L);
90-
put("mq.queue.depth", 1L);
91-
}
92-
});
93-
}
94-
};
81+
new HashMap<String, Long>(
82+
ImmutableMap.of(
83+
"mq.oldest.msg.age", -1L,
84+
"mq.uncommitted.messages", 10L,
85+
"mq.onqtime.1", -1L,
86+
"mq.onqtime.2", -1L,
87+
"mq.queue.depth", 1L))));
9588

9689
for (MetricData metric : otelTesting.getMetrics()) {
9790
for (LongPointData d : metric.getLongGaugeData().getPoints()) {
@@ -115,30 +108,22 @@ void testProcessPcfRequestAndPublishQMetricsForInquireQCmd() throws Exception {
115108
collectorContext, request, "*", InquireQCmdCollector.ATTRIBUTES);
116109

117110
Map<String, Map<String, Long>> expectedValues =
118-
new HashMap<String, Map<String, Long>>() {
119-
{
120-
put(
111+
new HashMap<>(
112+
ImmutableMap.of(
121113
"DEV.DEAD.LETTER.QUEUE",
122-
new HashMap<String, Long>() {
123-
{
124-
put("mq.queue.depth", 2L);
125-
put("mq.max.queue.depth", 5000L);
126-
put("mq.open.input.count", 2L);
127-
put("mq.open.output.count", 2L);
128-
}
129-
});
130-
put(
114+
new HashMap<>(
115+
ImmutableMap.of(
116+
"mq.queue.depth", 2L,
117+
"mq.max.queue.depth", 5000L,
118+
"mq.open.input.count", 2L,
119+
"mq.open.output.count", 2L)),
131120
"DEV.QUEUE.1",
132-
new HashMap<String, Long>() {
133-
{
134-
put("mq.queue.depth", 3L);
135-
put("mq.max.queue.depth", 5000L);
136-
put("mq.open.input.count", 3L);
137-
put("mq.open.output.count", 3L);
138-
}
139-
});
140-
}
141-
};
121+
new HashMap<>(
122+
ImmutableMap.of(
123+
"mq.queue.depth", 3L,
124+
"mq.max.queue.depth", 5000L,
125+
"mq.open.input.count", 3L,
126+
"mq.open.output.count", 3L))));
142127

143128
for (MetricData metric : otelTesting.getMetrics()) {
144129
for (LongPointData d : metric.getLongGaugeData().getPoints()) {
@@ -183,7 +168,7 @@ void testProcessPcfRequestAndPublishQMetricsForResetQStatsCmd() throws Exception
183168
MQCFST [type: 4, strucLength: 24, parameter: 2016 (MQCA_Q_NAME), codedCharSetId: 0, stringLength: 1, string: *]
184169
MQCFIL [type: 5, strucLength: 32, parameter: 1026 (MQIACF_Q_STATUS_ATTRS), count: 4, values: {2016, 1226, 1227, 1027}]
185170
*/
186-
private PCFMessage createPCFRequestForInquireQStatusCmd() {
171+
private static PCFMessage createPCFRequestForInquireQStatusCmd() {
187172
PCFMessage request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q_STATUS);
188173
request.addParameter(CMQC.MQCA_Q_NAME, "*");
189174
request.addParameter(CMQCFC.MQIACF_Q_STATUS_ATTRS, new int[] {2016, 1226, 1227, 1027});
@@ -218,7 +203,7 @@ private PCFMessage createPCFRequestForInquireQStatusCmd() {
218203
MQCFIL [type: 5, strucLength: 24, parameter: 1226 (MQIACF_Q_TIME_INDICATOR), count: 2, values: {-1, -1}]
219204
MQCFIN [type: 3, strucLength: 16, parameter: 1027 (MQIACF_UNCOMMITTED_MSGS), value: 0]"
220205
*/
221-
private PCFMessage[] createPCFResponseForInquireQStatusCmd() {
206+
private static PCFMessage[] createPCFResponseForInquireQStatusCmd() {
222207
PCFMessage response1 = new PCFMessage(2, CMQCFC.MQCMD_INQUIRE_Q_STATUS, 1, false);
223208
response1.addParameter(CMQC.MQCA_Q_NAME, "AMQ.5AF1608820C7D76E");
224209
response1.addParameter(CMQCFC.MQIACF_Q_STATUS_TYPE, 1105);
@@ -253,7 +238,7 @@ private PCFMessage[] createPCFResponseForInquireQStatusCmd() {
253238
MQCFIN [type: 3, strucLength: 16, parameter: 20 (MQIA_Q_TYPE), value: 1001]
254239
MQCFIL [type: 5, strucLength: 36, parameter: 1002 (MQIACF_Q_ATTRS), count: 5, values: {2016, 15, 3, 17, 18}]
255240
*/
256-
private PCFMessage createPCFRequestForInquireQCmd() {
241+
private static PCFMessage createPCFRequestForInquireQCmd() {
257242
PCFMessage request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q);
258243
request.addParameter(CMQC.MQCA_Q_NAME, "*");
259244
request.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_ALL);
@@ -290,7 +275,7 @@ private PCFMessage createPCFRequestForInquireQCmd() {
290275
MQCFIN [type: 3, strucLength: 16, parameter: 18 (MQIA_OPEN_OUTPUT_COUNT), value: 0]"
291276
*/
292277

293-
private PCFMessage[] createPCFResponseForInquireQCmd() {
278+
private static PCFMessage[] createPCFResponseForInquireQCmd() {
294279
PCFMessage response1 = new PCFMessage(2, CMQCFC.MQCMD_INQUIRE_Q, 1, false);
295280
response1.addParameter(CMQC.MQCA_Q_NAME, "AMQ.5AF1608820C76D80");
296281
response1.addParameter(CMQC.MQIA_Q_TYPE, 1);
@@ -326,7 +311,7 @@ private PCFMessage[] createPCFResponseForInquireQCmd() {
326311
MQCFH [type: 1, strucLength: 36, version: 1, command: 17 (MQCMD_RESET_Q_STATS), msgSeqNumber: 1, control: 1, compCode: 0, reason: 0, parameterCount: 1]
327312
MQCFST [type: 4, strucLength: 24, parameter: 2016 (MQCA_Q_NAME), codedCharSetId: 0, stringLength: 1, string: *]
328313
*/
329-
private PCFMessage createPCFRequestForResetQStatsCmd() {
314+
private static PCFMessage createPCFRequestForResetQStatsCmd() {
330315
PCFMessage request = new PCFMessage(CMQCFC.MQCMD_RESET_Q_STATS);
331316
request.addParameter(CMQC.MQCA_Q_NAME, "*");
332317
return request;
@@ -341,7 +326,7 @@ private PCFMessage createPCFRequestForResetQStatsCmd() {
341326
MQCFIN [type: 3, strucLength: 16, parameter: 36 (MQIA_HIGH_Q_DEPTH), value: 0]
342327
MQCFIN [type: 3, strucLength: 16, parameter: 35 (MQIA_TIME_SINCE_RESET), value: 65]"
343328
*/
344-
private PCFMessage[] createPCFResponseForResetQStatsCmd() {
329+
private static PCFMessage[] createPCFResponseForResetQStatsCmd() {
345330
PCFMessage response1 = new PCFMessage(2, CMQCFC.MQCMD_RESET_Q_STATS, 1, false);
346331
response1.addParameter(CMQC.MQCA_Q_NAME, "DEV.DEAD.LETTER.QUEUE");
347332
response1.addParameter(CMQC.MQIA_MSG_ENQ_COUNT, 3);

ibm-mq-metrics/src/test/java/io/opentelemetry/ibm/mq/metricscollector/QueueManagerMetricsCollectorTest.java

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

66
package io.opentelemetry.ibm.mq.metricscollector;
77

8+
import static java.util.Collections.singletonList;
89
import static org.assertj.core.api.Assertions.assertThat;
9-
import static org.mockito.Mockito.any;
10+
import static org.mockito.ArgumentMatchers.any;
1011
import static org.mockito.Mockito.when;
1112

1213
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -57,7 +58,7 @@ public void testProcessPCFRequestAndPublishQMetricsForInquireQStatusCmd() throws
5758
new QueueManagerMetricsCollector(
5859
otelTesting.getOpenTelemetry().getMeter("opentelemetry.io/mq"));
5960
classUnderTest.accept(context);
60-
List<String> metricsList = new ArrayList<>(List.of("mq.manager.status"));
61+
List<String> metricsList = new ArrayList<>(singletonList("mq.manager.status"));
6162

6263
for (MetricData metric : otelTesting.getMetrics()) {
6364
if (metricsList.remove(metric.getName())) {
@@ -100,7 +101,7 @@ public void testProcessPCFRequestAndPublishQMetricsForInquireQStatusCmd() throws
100101
MQCFST [type: 4, strucLength: 28, parameter: 3176 (null), codedCharSetId: 819, stringLength: 8, string: 08.32.08]
101102
*/
102103

103-
private PCFMessage[] createPCFResponseForInquireQMgrStatusCmd() {
104+
private static PCFMessage[] createPCFResponseForInquireQMgrStatusCmd() {
104105
PCFMessage response1 = new PCFMessage(2, CMQCFC.MQCMD_INQUIRE_Q_MGR_STATUS, 1, true);
105106
response1.addParameter(CMQC.MQCA_Q_MGR_NAME, "QM1");
106107
response1.addParameter(CMQCFC.MQIACF_Q_MGR_STATUS, 2);

ibm-mq-metrics/src/test/java/io/opentelemetry/ibm/mq/metricscollector/TopicMetricsCollectorTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
package io.opentelemetry.ibm.mq.metricscollector;
77

88
import static org.assertj.core.api.Assertions.assertThat;
9-
import static org.mockito.Mockito.*;
9+
import static org.mockito.ArgumentMatchers.any;
10+
import static org.mockito.Mockito.when;
1011

1112
import com.fasterxml.jackson.databind.ObjectMapper;
1213
import com.ibm.mq.constants.CMQC;
@@ -20,6 +21,7 @@
2021
import io.opentelemetry.sdk.metrics.data.MetricData;
2122
import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension;
2223
import java.util.ArrayList;
24+
import java.util.Arrays;
2325
import java.util.HashSet;
2426
import java.util.List;
2527
import java.util.Set;
@@ -61,7 +63,7 @@ void testPublishMetrics() throws Exception {
6163
classUnderTest.accept(context);
6264

6365
List<String> metricsList =
64-
new ArrayList<>(List.of("mq.publish.count", "mq.subscription.count"));
66+
new ArrayList<>(Arrays.asList("mq.publish.count", "mq.subscription.count"));
6567

6668
for (MetricData metric : otelTesting.getMetrics()) {
6769
if (metricsList.remove(metric.getName())) {
@@ -90,7 +92,7 @@ void testPublishMetrics() throws Exception {
9092
assertThat(metricsList).isEmpty();
9193
}
9294

93-
private PCFMessage[] createPCFResponseForInquireTopicStatusCmd() {
95+
private static PCFMessage[] createPCFResponseForInquireTopicStatusCmd() {
9496
PCFMessage response1 = new PCFMessage(2, CMQCFC.MQCMD_INQUIRE_TOPIC_STATUS, 1, false);
9597
response1.addParameter(CMQC.MQCA_TOPIC_STRING, "test");
9698
response1.addParameter(CMQC.MQIA_PUB_COUNT, 2);

ibm-mq-metrics/src/test/java/io/opentelemetry/ibm/mq/opentelemetry/ConfigTest.java

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

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

10+
import com.google.common.collect.ImmutableMap;
1011
import java.util.HashMap;
1112
import java.util.Map;
1213
import java.util.Properties;
@@ -29,14 +30,12 @@ public void cacheSystemProperties() {
2930
@Test
3031
void testSSLConnection() {
3132
Config.setUpSslConnection(
32-
new HashMap<String, Object>() {
33-
{
34-
put("keyStorePath", "foo");
35-
put("trustStorePath", "bar");
36-
put("keyStorePassword", "password");
37-
put("trustStorePassword", "password1");
38-
}
39-
});
33+
new HashMap<String, Object>(
34+
ImmutableMap.of(
35+
"keyStorePath", "foo",
36+
"trustStorePath", "bar",
37+
"keyStorePassword", "password",
38+
"trustStorePassword", "password1")));
4039

4140
assertThat(System.getProperties().get("javax.net.ssl.keyStore")).isEqualTo("foo");
4241
assertThat(System.getProperties().get("javax.net.ssl.trustStorePath")).isEqualTo("bar");

ibm-mq-metrics/src/test/java/io/opentelemetry/ibm/mq/opentelemetry/ConfigWrapperTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import static java.util.Collections.singletonList;
99
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
1010

11-
import java.io.FileNotFoundException;
1211
import java.time.Duration;
1312
import java.time.temporal.ChronoUnit;
1413
import org.junit.jupiter.api.BeforeEach;
@@ -24,25 +23,25 @@ void setUp() {
2423
}
2524

2625
@Test
27-
void testQueueManagerNames() throws FileNotFoundException {
26+
void testQueueManagerNames() throws Exception {
2827
ConfigWrapper config = ConfigWrapper.parse(file);
2928
assertThat(config.getQueueManagerNames()).isEqualTo(singletonList("QM1"));
3029
}
3130

3231
@Test
33-
void testNumberOfThreads() throws FileNotFoundException {
32+
void testNumberOfThreads() throws Exception {
3433
ConfigWrapper config = ConfigWrapper.parse(file);
3534
assertThat(config.getNumberOfThreads()).isEqualTo(20);
3635
}
3736

3837
@Test
39-
void testTaskDelay() throws FileNotFoundException {
38+
void testTaskDelay() throws Exception {
4039
ConfigWrapper config = ConfigWrapper.parse(file);
4140
assertThat(config.getTaskDelay()).isEqualTo(Duration.of(27, ChronoUnit.SECONDS));
4241
}
4342

4443
@Test
45-
void testTaskInitialDelay() throws FileNotFoundException {
44+
void testTaskInitialDelay() throws Exception {
4645
ConfigWrapper config = ConfigWrapper.parse(file);
4746
assertThat(config.getTaskInitialDelaySeconds()).isEqualTo(0);
4847
}

0 commit comments

Comments
 (0)