PlusAnonymousConcurrentUserDataModel extends PlusAnonymousUserDataModel { @Override public PreferenceArray getPreferencesFromUser(long userID) throws TasteException { if (isAnonymousUser(userID)) { return tempPrefs.get(userID); } return getDelegate().getPreferencesFromUser(userID); } PlusAnonymousConcurrentUserDataModel(DataModel delegate, int maxConcurrentUsers); Long takeAvailableUser(); boolean releaseUser(Long userID); void setTempPrefs(PreferenceArray prefs, long anonymousUserID); void clearTempPrefs(long anonymousUserID); @Override LongPrimitiveIterator getUserIDs(); @Override PreferenceArray getPreferencesFromUser(long userID); @Override FastIDSet getItemIDsFromUser(long userID); @Override PreferenceArray getPreferencesForItem(long itemID); @Override Float getPreferenceValue(long userID, long itemID); @Override Long getPreferenceTime(long userID, long itemID); @Override int getNumUsers(); @Override int getNumUsersWithPreferenceFor(long itemID); @Override int getNumUsersWithPreferenceFor(long itemID1, long itemID2); @Override void setPreference(long userID, long itemID, float value); @Override void removePreference(long userID, long itemID);  }
@Test public void testGetPreferencesForNonAnonymousUser() throws TasteException { PreferenceArray prefs = new GenericUserPreferenceArray(1); long sampleUserID = 1; prefs.setUserID(0, sampleUserID); long sampleItemID = 11; prefs.setItemID(0, sampleItemID); FastByIDMap<PreferenceArray> delegatePreferences = new FastByIDMap<PreferenceArray>(); delegatePreferences.put(sampleUserID, prefs); PlusAnonymousConcurrentUserDataModel instance = getTestableWithDelegateData(10, delegatePreferences); assertEquals(prefs, instance.getPreferencesFromUser(sampleUserID)); }
@Test(expected=NoSuchUserException.class) public void testGetPreferencesForNonExistingUser() throws TasteException { PlusAnonymousConcurrentUserDataModel instance = getTestableWithoutDelegateData(10); instance.getPreferencesFromUser(1); }
@Test public void testGetPreferencesForNonAnonymousUser() throws TasteException { PreferenceArray prefs = new GenericUserPreferenceArray(1); long sampleUserID = 1; prefs.setUserID(0, sampleUserID); long sampleItemID = 11; prefs.setItemID(0, sampleItemID); FastByIDMap<PreferenceArray> delegatePreferences = new FastByIDMap<>(); delegatePreferences.put(sampleUserID, prefs); PlusAnonymousConcurrentUserDataModel instance = getTestableWithDelegateData(10, delegatePreferences); assertEquals(prefs, instance.getPreferencesFromUser(sampleUserID)); }