Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ArticleManager {
- private User user;
- private ArticleDatabase database;
- public ArticleManager(User user, ArticleDatabase database) {
- super();
- this.user = user;
- this.database = database;
- }
- public void initialize() {
- database.addListener(new ArticleListener());
- }
- }
- /**
- *This class can be constructed
- *via Mockito and its dependencies can be fulfilled
- *with mock objects as demonstrated by the following code snippet.
- **/
- @RunWith(MockitoJUnitRunner.class)
- public class ArticleManagerTest {
- @Mock ArticleCalculator calculator;
- @Mock ArticleDatabase database;
- @Mock User user;
- @Spy private UserProvider userProvider = new ConsumerUserProvider();
- //creates an instance of ArticleManager and injects the mocks into it
- @InjectMocks private ArticleManager manager;
- @Test public void shouldDoSomething() {
- // calls addListener with an instance of ArticleListener
- manager.initialize();
- // validate that addListener was called
- verify(database).addListener(any(ArticleListener.class));
- }
- }
Add Comment
Please, Sign In to add comment