@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))
.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()))