### Question:
PreferenceApiService { public Collection<Preference> loadAll() { if (authManager.isAdmin()) { return preferenceManager.loadAll(); } else { return preferenceManager.loadVisible(); } }  Collection<Preference> loadAll(); @PreAuthorize(AclExpressions.ADMIN_ONLY) List<Preference> update(List<Preference> preference); @PostAuthorize("hasRole('ADMIN') OR (returnObject != null AND returnObject.visible)") Preference load(String name); @PreAuthorize(AclExpressions.ADMIN_ONLY) void delete(String name);  }### Answer:
@Test @WithMockUser @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class) public void testLoadPreferencesUser() { Collection<Preference> preferences = preferenceApiService.loadAll(); Assert.assertFalse(preferences.isEmpty()); Assert.assertTrue(preferences.stream().allMatch(Preference::isVisible)); }
@Test @WithMockUser(authorities = "ROLE_ADMIN") @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class) public void testLoadPreferencesAdmin() { Collection<Preference> preferences = preferenceApiService.loadAll(); Assert.assertFalse(preferences.isEmpty()); Assert.assertTrue(preferences.stream().anyMatch(Preference::isVisible)); Assert.assertTrue(preferences.stream().anyMatch(p -> !p.isVisible())); }