@Test @WithMockUser(value = USERNAME, roles = ROLE_SU) void testGetRecoveryCodes() { User molgenisUser = mock(User.class); RecoveryCode recoveryCode = mock(RecoveryCode.class); when(userService.getUser(USERNAME)).thenReturn(molgenisUser); when(molgenisUser.getId()).thenReturn("1234"); @SuppressWarnings("unchecked") Query<RecoveryCode> query = mock(Query.class, RETURNS_SELF); when(dataService.query(RecoveryCodeMetadata.RECOVERY_CODE, RecoveryCode.class)) .thenReturn(query); when(query.eq(USER_ID, molgenisUser.getId()).findAll()) .thenReturn(IntStream.range(0, 1).mapToObj(i -> recoveryCode)); when(dataService .query(RECOVERY_CODE, RecoveryCode.class) .eq(USER_ID, molgenisUser.getId()) .findAll()) .thenReturn(Stream.of(recoveryCode)); Stream<RecoveryCode> recoveryCodeList = recoveryServiceImpl.getRecoveryCodes(); assertEquals(recoveryCodeList.count(), 1); }
@Override public Stream<RecoveryCode> getRecoveryCodes() { String userId = getUser().getId(); return runAsSystem( () -> dataService.query(RECOVERY_CODE, RecoveryCode.class).eq(USER_ID, userId).findAll()); }
RecoveryServiceImpl implements RecoveryService { @Override public Stream<RecoveryCode> getRecoveryCodes() { String userId = getUser().getId(); return runAsSystem( () -> dataService.query(RECOVERY_CODE, RecoveryCode.class).eq(USER_ID, userId).findAll()); } }
RecoveryServiceImpl implements RecoveryService { @Override public Stream<RecoveryCode> getRecoveryCodes() { String userId = getUser().getId(); return runAsSystem( () -> dataService.query(RECOVERY_CODE, RecoveryCode.class).eq(USER_ID, userId).findAll()); } RecoveryServiceImpl(
      DataService dataService,
      UserService userService,
      RecoveryCodeFactory recoveryCodeFactory,
      IdGenerator idGenerator); }
RecoveryServiceImpl implements RecoveryService { @Override public Stream<RecoveryCode> getRecoveryCodes() { String userId = getUser().getId(); return runAsSystem( () -> dataService.query(RECOVERY_CODE, RecoveryCode.class).eq(USER_ID, userId).findAll()); } RecoveryServiceImpl(
      DataService dataService,
      UserService userService,
      RecoveryCodeFactory recoveryCodeFactory,
      IdGenerator idGenerator); @Override @Transactional Stream<RecoveryCode> generateRecoveryCodes(); @Override @Transactional void useRecoveryCode(String recoveryCode); @Override Stream<RecoveryCode> getRecoveryCodes(); }
RecoveryServiceImpl implements RecoveryService { @Override public Stream<RecoveryCode> getRecoveryCodes() { String userId = getUser().getId(); return runAsSystem( () -> dataService.query(RECOVERY_CODE, RecoveryCode.class).eq(USER_ID, userId).findAll()); } RecoveryServiceImpl(
      DataService dataService,
      UserService userService,
      RecoveryCodeFactory recoveryCodeFactory,
      IdGenerator idGenerator); @Override @Transactional Stream<RecoveryCode> generateRecoveryCodes(); @Override @Transactional void useRecoveryCode(String recoveryCode); @Override Stream<RecoveryCode> getRecoveryCodes();  }