|
16 | 16 |
|
17 | 17 | package org.springframework.amqp.rabbit.logback;
|
18 | 18 |
|
| 19 | +import static org.hamcrest.Matchers.containsString; |
| 20 | +import static org.hamcrest.Matchers.instanceOf; |
| 21 | +import static org.junit.Assert.assertEquals; |
19 | 22 | import static org.junit.Assert.assertFalse;
|
20 |
| -import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 23 | +import static org.junit.Assert.assertThat; |
21 | 24 | import static org.mockito.ArgumentMatchers.any;
|
22 | 25 | import static org.mockito.ArgumentMatchers.anyBoolean;
|
23 | 26 | import static org.mockito.ArgumentMatchers.anyString;
|
|
35 | 38 |
|
36 | 39 | import org.springframework.amqp.UncategorizedAmqpException;
|
37 | 40 | import org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean;
|
| 41 | +import org.springframework.amqp.utils.test.TestUtils; |
38 | 42 | import org.springframework.core.io.ClassPathResource;
|
39 | 43 | import org.springframework.test.util.ReflectionTestUtils;
|
40 | 44 |
|
|
47 | 51 | *
|
48 | 52 | * @author Stephen Oakey
|
49 | 53 | * @author Artem Bilan
|
| 54 | + * @author Gary Russell |
50 | 55 | *
|
51 | 56 | * @since 2.0
|
52 | 57 | */
|
@@ -214,30 +219,34 @@ public void testSasl() {
|
214 | 219 | verify(bean).setUseSSL(eq(true));
|
215 | 220 | ArgumentCaptor<SaslConfig> captor = ArgumentCaptor.forClass(SaslConfig.class);
|
216 | 221 | verify(bean).setSaslConfig(captor.capture());
|
217 |
| - assertThat(captor.getValue()) |
218 |
| - .isInstanceOf(DefaultSaslConfig.class) |
219 |
| - .hasFieldOrPropertyWithValue("mechanism", "PLAIN"); |
| 222 | + SaslConfig saslConfig = captor.getValue(); |
| 223 | + assertThat(saslConfig, instanceOf(DefaultSaslConfig.class)); |
| 224 | + assertEquals("PLAIN", TestUtils.getPropertyValue(saslConfig, "mechanism")); |
220 | 225 | appender.setSaslConfig("DefaultSaslConfig.EXTERNAL");
|
221 | 226 | appender.configureRabbitConnectionFactory(bean);
|
222 | 227 | verify(bean, times(2)).setSaslConfig(captor.capture());
|
223 |
| - assertThat(captor.getValue()) |
224 |
| - .isInstanceOf(DefaultSaslConfig.class) |
225 |
| - .hasFieldOrPropertyWithValue("mechanism", "EXTERNAL"); |
| 228 | + saslConfig = captor.getValue(); |
| 229 | + assertThat(saslConfig, instanceOf(DefaultSaslConfig.class)); |
| 230 | + assertEquals("EXTERNAL", TestUtils.getPropertyValue(saslConfig, "mechanism")); |
226 | 231 | appender.setSaslConfig("JDKSaslConfig");
|
227 | 232 | appender.configureRabbitConnectionFactory(bean);
|
228 | 233 | verify(bean, times(3)).setSaslConfig(captor.capture());
|
229 |
| - assertThat(captor.getValue()) |
230 |
| - .isInstanceOf(JDKSaslConfig.class); |
| 234 | + assertThat(captor.getValue(), instanceOf(JDKSaslConfig.class)); |
231 | 235 | appender.setSaslConfig("CRDemoSaslConfig");
|
232 | 236 | appender.configureRabbitConnectionFactory(bean);
|
233 | 237 | verify(bean, times(4)).setSaslConfig(captor.capture());
|
234 |
| - assertThat(captor.getValue()) |
235 |
| - .isInstanceOf(CRDemoMechanism.CRDemoSaslConfig.class); |
| 238 | + assertThat(captor.getValue(), instanceOf(CRDemoMechanism.CRDemoSaslConfig.class)); |
236 | 239 | appender.setSaslConfig("junk");
|
237 |
| - assertThatThrownBy(() -> appender.configureRabbitConnectionFactory(bean)) |
238 |
| - .isInstanceOf(UncategorizedAmqpException.class) |
239 |
| - .hasCauseInstanceOf(IllegalStateException.class) |
240 |
| - .withFailMessage("Unrecognized SaslConfig: junk"); |
| 240 | + |
| 241 | + |
| 242 | + try { |
| 243 | + appender.configureRabbitConnectionFactory(bean); |
| 244 | + } |
| 245 | + catch (Exception e) { |
| 246 | + assertThat(e, instanceOf(UncategorizedAmqpException.class)); |
| 247 | + assertThat(e.getCause(), instanceOf(IllegalStateException.class)); |
| 248 | + assertThat(e.getMessage(), containsString("Unrecognized SaslConfig: junk")); |
| 249 | + } |
241 | 250 | }
|
242 | 251 |
|
243 | 252 |
|
|
0 commit comments