• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 package org.mockitousage.examples.use;
6 
7 import java.util.List;
8 
9 public class ArticleManager {
10 
11     private final ArticleCalculator calculator;
12     private final ArticleDatabase database;
13 
ArticleManager(ArticleCalculator calculator, ArticleDatabase database)14     public ArticleManager(ArticleCalculator calculator, ArticleDatabase database) {
15         this.calculator = calculator;
16         this.database = database;
17     }
18 
updateArticleCounters(String newspaper)19     public void updateArticleCounters(String newspaper) {
20         int articles = calculator.countArticles(newspaper);
21         int polishArticles = calculator.countArticlesInPolish(newspaper);
22 
23         database.updateNumberOfArticles(newspaper, articles);
24         database.updateNumberOfPolishArticles(newspaper, polishArticles);
25         database.updateNumberOfEnglishArticles(newspaper, articles - polishArticles);
26     }
27 
updateRelatedArticlesCounters(String newspaper)28     public void updateRelatedArticlesCounters(String newspaper) {
29         List<Article> articles = database.getArticlesFor("Guardian");
30         for (Article article : articles) {
31             int numberOfRelatedArticles = calculator.countNumberOfRelatedArticles(article);
32             article.setNumberOfRelatedArticles(numberOfRelatedArticles);
33             database.save(article);
34         }
35     }
36 }
37