Skip to content

Commit a9ab482

Browse files
committed
Fix tests for the previous commit - new behavior
1 parent 887a089 commit a9ab482

File tree

2 files changed

+44
-61
lines changed

2 files changed

+44
-61
lines changed

spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
import org.aopalliance.aop.Advice;
4040
import org.aopalliance.intercept.MethodInterceptor;
4141
import org.apache.commons.logging.Log;
42-
import org.junit.Test;
43-
import org.junit.runner.RunWith;
42+
import org.junit.jupiter.api.Test;
4443

4544
import org.springframework.beans.DirectFieldAccessor;
4645
import org.springframework.beans.factory.FactoryBean;
@@ -127,7 +126,7 @@
127126
import org.springframework.stereotype.Component;
128127
import org.springframework.test.annotation.DirtiesContext;
129128
import org.springframework.test.context.ContextConfiguration;
130-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
129+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
131130
import org.springframework.util.ClassUtils;
132131
import org.springframework.util.MultiValueMap;
133132

@@ -141,10 +140,9 @@
141140
*
142141
* @since 4.0
143142
*/
144-
@ContextConfiguration(loader = NoBeansOverrideAnnotationConfigContextLoader.class,
145-
classes = { EnableIntegrationTests.ContextConfiguration.class,
146-
EnableIntegrationTests.ContextConfiguration2.class })
147-
@RunWith(SpringJUnit4ClassRunner.class)
143+
@ContextConfiguration(loader = NoBeansOverrideAnnotationConfigContextLoader.class)
144+
@SpringJUnitConfig(classes = { EnableIntegrationTests.ContextConfiguration.class,
145+
EnableIntegrationTests.ContextConfiguration2.class })
148146
@DirtiesContext
149147
public class EnableIntegrationTests {
150148

@@ -360,7 +358,7 @@ public void testAnnotatedServiceActivator() throws Exception {
360358
assertThat(messageHistory).isNotNull();
361359
String messageHistoryString = messageHistory.toString();
362360
assertThat(messageHistoryString).contains("input");
363-
assertThat(messageHistoryString).contains("annotationTestService.handle.serviceActivator.handler");
361+
assertThat(messageHistoryString).contains("annotationTestService.handle.serviceActivator");
364362
assertThat(messageHistoryString).doesNotContain("output");
365363

366364
receive = this.publishedChannel.receive(10_000);

spring-integration-core/src/test/java/org/springframework/integration/support/management/micrometer/MicrometerMetricsTests.java

Lines changed: 38 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
package org.springframework.integration.support.management.micrometer;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20-
import static org.assertj.core.api.Assertions.fail;
20+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2121

2222
import java.util.Set;
2323

24-
import org.junit.Test;
25-
import org.junit.runner.RunWith;
24+
import org.junit.jupiter.api.Test;
2625

2726
import org.springframework.beans.factory.annotation.Autowired;
2827
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -50,7 +49,7 @@
5049
import org.springframework.messaging.support.GenericMessage;
5150
import org.springframework.test.annotation.DirtiesContext;
5251
import org.springframework.test.context.TestExecutionListeners;
53-
import org.springframework.test.context.junit4.SpringRunner;
52+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
5453
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
5554

5655
import io.micrometer.core.instrument.MeterRegistry;
@@ -64,7 +63,7 @@
6463
* @since 5.0.2
6564
*
6665
*/
67-
@RunWith(SpringRunner.class)
66+
@SpringJUnitConfig
6867
@DirtiesContext
6968
@TestExecutionListeners(DependencyInjectionTestExecutionListener.class)
7069
public class MicrometerMetricsTests {
@@ -98,33 +97,25 @@ public class MicrometerMetricsTests {
9897
public void testSend() {
9998
GenericMessage<String> message = new GenericMessage<>("foo");
10099
this.channel.send(message);
101-
try {
102-
this.channel.send(this.source.receive()); // "bar"
103-
fail("Expected exception");
104-
}
105-
catch (MessagingException e) {
106-
assertThat(e.getCause().getMessage()).isEqualTo("testErrorCount");
107-
}
108-
try {
109-
this.channel.send(new GenericMessage<>("bar"));
110-
fail("Expected exception");
111-
}
112-
catch (MessagingException e) {
113-
assertThat(e.getCause().getMessage()).isEqualTo("testErrorCount");
114-
}
100+
assertThatExceptionOfType(MessagingException.class)
101+
.isThrownBy(() -> this.channel.send(this.source.receive())) // "bar"
102+
.withStackTraceContaining("testErrorCount");
103+
104+
assertThatExceptionOfType(MessagingException.class)
105+
.isThrownBy(() -> this.channel.send(new GenericMessage<>("bar")))
106+
.withStackTraceContaining("testErrorCount");
107+
115108
assertThat(TestUtils.getPropertyValue(this.channel, "meters", Set.class)).hasSize(2);
116109
this.channel2.send(message);
117110
this.queue.send(message);
118111
this.queue.send(message);
119112
this.queue.receive();
120113
this.badPoll.send(message);
121-
try {
122-
this.badPoll.receive();
123-
fail("Expected exception");
124-
}
125-
catch (RuntimeException e) {
126-
assertThat(e.getMessage()).isEqualTo("badPoll");
127-
}
114+
115+
assertThatExceptionOfType(RuntimeException.class)
116+
.isThrownBy(() -> this.badPoll.receive())
117+
.withMessage("badPoll");
118+
128119
nullChannel.send(message);
129120
MeterRegistry registry = this.meterRegistry;
130121
assertThat(registry.get("spring.integration.channels").gauge().value()).isEqualTo(6);
@@ -147,7 +138,7 @@ public void testSend() {
147138
.timer().count()).isEqualTo(1);
148139

149140
assertThat(registry.get("spring.integration.send")
150-
.tag("name", "eipMethod.handler")
141+
.tag("name", "eipMethod")
151142
.tag("result", "success")
152143
.timer().count()).isEqualTo(1);
153144

@@ -162,7 +153,7 @@ public void testSend() {
162153
.timer().count()).isEqualTo(2);
163154

164155
assertThat(registry.get("spring.integration.send")
165-
.tag("name", "eipMethod.handler")
156+
.tag("name", "eipMethod")
166157
.tag("result", "failure")
167158
.timer().count()).isEqualTo(2);
168159

@@ -194,32 +185,26 @@ public void testSend() {
194185
.tag("result", "success")
195186
.timer();
196187
newChannel.destroy();
197-
try {
198-
registry.get("spring.integration.send")
199-
.tag("name", "newChannel")
200-
.tag("result", "success")
201-
.timer();
202-
fail("Expected MeterNotFoundException");
203-
}
204-
catch (MeterNotFoundException e) {
205-
assertThat(e).hasMessageContaining("A meter with name 'spring.integration.send' was found");
206-
assertThat(e).hasMessageContaining("No meters have a tag 'name' with value 'newChannel'");
207-
}
188+
189+
assertThatExceptionOfType(MeterNotFoundException.class)
190+
.isThrownBy(() ->
191+
registry.get("spring.integration.send")
192+
.tag("name", "newChannel")
193+
.tag("result", "success")
194+
.timer())
195+
.withStackTraceContaining("A meter with name 'spring.integration.send' was found")
196+
.withStackTraceContaining("No meters have a tag 'name' with value 'newChannel'");
197+
208198
this.context.close();
209-
try {
210-
registry.get("spring.integration.send").timers();
211-
fail("Expected MeterNotFoundException");
212-
}
213-
catch (MeterNotFoundException e) {
214-
assertThat(e).hasMessageContaining("No meter with name 'spring.integration.send' was found");
215-
}
216-
try {
217-
registry.get("spring.integration.receive").counters();
218-
fail("Expected MeterNotFoundException");
219-
}
220-
catch (MeterNotFoundException e) {
221-
assertThat(e).hasMessageContaining("No meter with name 'spring.integration.receive' was found");
222-
}
199+
200+
assertThatExceptionOfType(MeterNotFoundException.class)
201+
.isThrownBy(() -> registry.get("spring.integration.send").timers())
202+
.withStackTraceContaining("No meter with name 'spring.integration.send' was found");
203+
204+
assertThatExceptionOfType(MeterNotFoundException.class)
205+
.isThrownBy(() -> registry.get("spring.integration.receive").counters())
206+
.withStackTraceContaining("No meter with name 'spring.integration.receive' was found");
207+
223208
this.channel.destroy();
224209
assertThat(TestUtils.getPropertyValue(this.channel, "meters", Set.class)).hasSize(0);
225210

0 commit comments

Comments
 (0)