### Question:
StatefulPreferencesUsageService implements UsageService { @Override public List<Module> getMostRecentlyUsed() { List<ModuleUsage> used = dataStore.getUsages(); used.sort((a, b) -> Long.compare(b.getLastSeen(), a.getLastSeen())); return used.stream().map(u -> modulesMap.get(u.getModuleId())).filter(m -> m != null).collect(toList()); } @Inject  StatefulPreferencesUsageService(List<Module> modules, PreferencesUsageDataStore dataStore); @Override void incrementUsageFor(String moduleId); @Override List<Module> getMostUsed(); @Override List<Module> getMostRecentlyUsed(); @Override void clear(); @Override long getTotalUsage();  }### Answer:
@Test public void getMostRecentlyUsed() { List<ModuleUsage> usages = Arrays .asList(new ModuleUsage[] { usage("IDontExist", 1), usage("module1", 2), usage("module2", 3) }); when(injector.instance(PreferencesUsageDataStore.class).getUsages()).thenReturn(usages); List<Module> mostUsed = injector.instance(StatefulPreferencesUsageService.class).getMostRecentlyUsed(); assertEquals(2, mostUsed.size()); assertEquals("module2", mostUsed.get(0).id()); }