Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //the feign client
- @FeignClient("user")
- public interface UserClient {
- UserEntity getUser();
- }
- //the implementation i use for the tests
- @Component
- @Primary //mark as primary implementation
- public class UserClientTestImpl implements UserClient {
- @Override public UserEntity getUser() {
- return someKindOfUser;
- }
- }
- public interface IWebClient {
- public String get(...);
- public String post(...);
- }
- public class FeignClientWrapper implements IWebClient {
- private feign = something
- public String get() {
- feign.get( ... )
- }
- public String post() {
- feign.post( ... )
- }
- }
- @RunWith(SpringRunner.class)
- @SpringBootTest(webEnvironment =
- SpringBootTest.WebEnvironment.DEFINED_PORT)
- public class TestYourComponent {
- @Configuration
- @Import({YourConfiguration.class})
- public static class TestConfiguration {
- }
- @MockBean
- private UserClient userClient;
- @Test
- public void someTest()
- {
- //...
- mockSomeBehavior();
- //...
- }
- private void mockSomeBehavior() {
- Mockito.doReturn(someKindOfUser).when(userClient).getUser();
- }
- }
Add Comment
Please, Sign In to add comment