Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. @RunWith(SpringJUnit4ClassRunner.class)
  2. @ContextConfiguration(classes = MyRealApplicationConfig.class)
  3. public final class MyApplicationSpringTest {
  4. @Inject MyApplication myApplication;
  5. @Mocked SomeService mockService;
  6.  
  7. @BeforeClass // runs before Spring configuration
  8. public static void setUpMocksForSpringConfiguration() {
  9. new MockUp<SomeService>() {
  10. @Mock String getName() { return "one"; }
  11. };
  12. }
  13.  
  14. @Test
  15. public void doSomethingUsingMockedService() {
  16. new Expectations() {{ mockService.doSomething(); result = "two"; }};
  17.  
  18. String result = myApplication.doSomething();
  19.  
  20. assertEquals("one two", result);
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement