@Test
public void preferencesFetchedOnlyOnce() throws Exception {

  DataModel dataModel = EasyMock.createMock(DataModel.class);
  ItemSimilarity itemSimilarity = EasyMock.createMock(ItemSimilarity.class);
  CandidateItemsStrategy candidateItemsStrategy = EasyMock.createMock(CandidateItemsStrategy.class);
  MostSimilarItemsCandidateItemsStrategy mostSimilarItemsCandidateItemsStrategy =
      EasyMock.createMock(MostSimilarItemsCandidateItemsStrategy.class);
  PreferenceArray preferencesFromUser = new GenericUserPreferenceArray(
      Arrays.asList(new GenericPreference(1L, 1L, 5.0f), new GenericPreference(1L, 2L, 4.0f)));
  EasyMock.expect(dataModel.getMinPreference()).andReturn(Float.NaN);
  EasyMock.expect(dataModel.getMaxPreference()).andReturn(Float.NaN);
  EasyMock.expect(dataModel.getPreferencesFromUser(1L)).andReturn(preferencesFromUser);
  EasyMock.expect(candidateItemsStrategy.getCandidateItems(1L, preferencesFromUser, dataModel, false))
      .andReturn(new FastIDSet(new long[] { 3L, 4L }));
  EasyMock.expect(itemSimilarity.itemSimilarities(3L, preferencesFromUser.getIDs()))
      .andReturn(new double[] { 0.5, 0.3 });
  EasyMock.expect(itemSimilarity.itemSimilarities(4L, preferencesFromUser.getIDs()))
      .andReturn(new double[] { 0.4, 0.1 });
  EasyMock.replay(dataModel, itemSimilarity, candidateItemsStrategy, mostSimilarItemsCandidateItemsStrategy);
  Recommender recommender = new GenericItemBasedRecommender(dataModel, itemSimilarity,
      candidateItemsStrategy, mostSimilarItemsCandidateItemsStrategy);
  recommender.recommend(1L, 3);
  EasyMock.verify(dataModel, itemSimilarity, candidateItemsStrategy, mostSimilarItemsCandidateItemsStrategy);
}