Guest User

Untitled

a guest
May 21st, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. public class ArticleManager {
  2. private User user;
  3. private ArticleDatabase database;
  4.  
  5. public ArticleManager(User user, ArticleDatabase database) {
  6. super();
  7. this.user = user;
  8. this.database = database;
  9. }
  10.  
  11. public void initialize() {
  12. database.addListener(new ArticleListener());
  13. }
  14. }
  15.  
  16. /**
  17. *This class can be constructed
  18. *via Mockito and its dependencies can be fulfilled
  19. *with mock objects as demonstrated by the following code snippet.
  20. **/
  21.  
  22.  
  23. @RunWith(MockitoJUnitRunner.class)
  24. public class ArticleManagerTest {
  25.  
  26. @Mock ArticleCalculator calculator;
  27. @Mock ArticleDatabase database;
  28. @Mock User user;
  29.  
  30. @Spy private UserProvider userProvider = new ConsumerUserProvider();
  31.  
  32. //creates an instance of ArticleManager and injects the mocks into it
  33.  
  34. @InjectMocks private ArticleManager manager;
  35.  
  36. @Test public void shouldDoSomething() {
  37. // calls addListener with an instance of ArticleListener
  38. manager.initialize();
  39.  
  40. // validate that addListener was called
  41. verify(database).addListener(any(ArticleListener.class));
  42. }
  43. }
Add Comment
Please, Sign In to add comment