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