Guest User

Untitled

a guest
Feb 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. //the feign client
  2. @FeignClient("user")
  3. public interface UserClient {
  4. UserEntity getUser();
  5. }
  6.  
  7. //the implementation i use for the tests
  8. @Component
  9. @Primary //mark as primary implementation
  10. public class UserClientTestImpl implements UserClient {
  11. @Override public UserEntity getUser() {
  12. return someKindOfUser;
  13. }
  14. }
  15.  
  16. public interface IWebClient {
  17. public String get(...);
  18. public String post(...);
  19. }
  20.  
  21. public class FeignClientWrapper implements IWebClient {
  22. private feign = something
  23.  
  24. public String get() {
  25. feign.get( ... )
  26. }
  27.  
  28. public String post() {
  29. feign.post( ... )
  30. }
  31. }
  32.  
  33. @RunWith(SpringRunner.class)
  34. @SpringBootTest(webEnvironment =
  35. SpringBootTest.WebEnvironment.DEFINED_PORT)
  36. public class TestYourComponent {
  37. @Configuration
  38. @Import({YourConfiguration.class})
  39. public static class TestConfiguration {
  40. }
  41.  
  42. @MockBean
  43. private UserClient userClient;
  44.  
  45. @Test
  46. public void someTest()
  47. {
  48. //...
  49. mockSomeBehavior();
  50. //...
  51. }
  52.  
  53. private void mockSomeBehavior() {
  54. Mockito.doReturn(someKindOfUser).when(userClient).getUser();
  55. }
  56. }
Add Comment
Please, Sign In to add comment