@Test
public void recommend() throws Exception {

  DataModel dataModel = EasyMock.createMock(DataModel.class);
  PreferenceArray preferencesFromUser = EasyMock.createMock(PreferenceArray.class);
  CandidateItemsStrategy candidateItemsStrategy = EasyMock.createMock(CandidateItemsStrategy.class);
  Factorizer factorizer = EasyMock.createMock(Factorizer.class);
  Factorization factorization = EasyMock.createMock(Factorization.class);
  FastIDSet candidateItems = new FastIDSet();
  candidateItems.add(5L);
  candidateItems.add(3L);
  EasyMock.expect(factorizer.factorize()).andReturn(factorization);
  EasyMock.expect(dataModel.getPreferencesFromUser(1L)).andReturn(preferencesFromUser);
  EasyMock.expect(candidateItemsStrategy.getCandidateItems(1L, preferencesFromUser, dataModel, false))
      .andReturn(candidateItems);
  EasyMock.expect(factorization.getUserFeatures(1L)).andReturn(new double[] { 0.4, 2 });
  EasyMock.expect(factorization.getItemFeatures(5L)).andReturn(new double[] { 1, 0.3 });
  EasyMock.expect(factorization.getUserFeatures(1L)).andReturn(new double[] { 0.4, 2 });
  EasyMock.expect(factorization.getItemFeatures(3L)).andReturn(new double[] { 2, 0.6 });
  EasyMock.replay(dataModel, candidateItemsStrategy, factorizer, factorization);
  SVDRecommender svdRecommender = new SVDRecommender(dataModel, factorizer, candidateItemsStrategy);
  List<RecommendedItem> recommendedItems = svdRecommender.recommend(1L, 5);
  assertEquals(2, recommendedItems.size());
  assertEquals(3L, recommendedItems.get(0).getItemID());
  assertEquals(2.0f, recommendedItems.get(0).getValue(), EPSILON);
  assertEquals(5L, recommendedItems.get(1).getItemID());
  assertEquals(1.0f, recommendedItems.get(1).getValue(), EPSILON);
  EasyMock.verify(dataModel, candidateItemsStrategy, factorizer, factorization);
}