@Bean public MockRestServiceServer mockRestServiceServer( MockServerRestTemplateCustomizer customizer) { try { return createDeferredMockRestServiceServer(customizer); } catch (Exception ex) { throw new IllegalStateException(ex); } }
private MockRestServiceServer createDeferredMockRestServiceServer( MockServerRestTemplateCustomizer customizer) throws Exception { Constructor<MockRestServiceServer> constructor = MockRestServiceServer.class .getDeclaredConstructor(RequestExpectationManager.class); constructor.setAccessible(true); return constructor.newInstance(new DeferredRequestExpectationManager(customizer)); }
@Bean public MockServerRestTemplateCustomizer mockServerRestTemplateCustomizer() { return new MockServerRestTemplateCustomizer(); }
DeferredRequestExpectationManager(MockServerRestTemplateCustomizer customizer) { this.customizer = customizer; }
@Test(expected = NoSuchBeanDefinitionException.class) public void mockServerRestTemplateCustomizerShouldNotBeRegistered() throws Exception { this.applicationContext.getBean(MockServerRestTemplateCustomizer.class); }