@Test @WithMockUser(value = USERNAME, roles = ROLE_SU) void testGenerateRecoveryCodes() { 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(recoveryCodeFactory.create()).thenReturn(recoveryCode); Stream<RecoveryCode> recoveryCodeStream = recoveryServiceImpl.generateRecoveryCodes(); assertEquals(recoveryCodeStream.count(), 10); }
@Override @Transactional public Stream<RecoveryCode> generateRecoveryCodes() { String userId = getUser().getId(); deleteOldRecoveryCodes(userId); List<RecoveryCode> newRecoveryCodes = generateRecoveryCodes(userId); runAsSystem((Runnable) () -> dataService.add(RECOVERY_CODE, newRecoveryCodes.stream())); return newRecoveryCodes.stream(); }
RecoveryServiceImpl implements RecoveryService { @Override @Transactional public Stream<RecoveryCode> generateRecoveryCodes() { String userId = getUser().getId(); deleteOldRecoveryCodes(userId); List<RecoveryCode> newRecoveryCodes = generateRecoveryCodes(userId); runAsSystem((Runnable) () -> dataService.add(RECOVERY_CODE, newRecoveryCodes.stream())); return newRecoveryCodes.stream(); } }
RecoveryServiceImpl implements RecoveryService { @Override @Transactional public Stream<RecoveryCode> generateRecoveryCodes() { String userId = getUser().getId(); deleteOldRecoveryCodes(userId); List<RecoveryCode> newRecoveryCodes = generateRecoveryCodes(userId); runAsSystem((Runnable) () -> dataService.add(RECOVERY_CODE, newRecoveryCodes.stream())); return newRecoveryCodes.stream(); } RecoveryServiceImpl(
      DataService dataService,
      UserService userService,
      RecoveryCodeFactory recoveryCodeFactory,
      IdGenerator idGenerator); }
RecoveryServiceImpl implements RecoveryService { @Override @Transactional public Stream<RecoveryCode> generateRecoveryCodes() { String userId = getUser().getId(); deleteOldRecoveryCodes(userId); List<RecoveryCode> newRecoveryCodes = generateRecoveryCodes(userId); runAsSystem((Runnable) () -> dataService.add(RECOVERY_CODE, newRecoveryCodes.stream())); return newRecoveryCodes.stream(); } 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 @Transactional public Stream<RecoveryCode> generateRecoveryCodes() { String userId = getUser().getId(); deleteOldRecoveryCodes(userId); List<RecoveryCode> newRecoveryCodes = generateRecoveryCodes(userId); runAsSystem((Runnable) () -> dataService.add(RECOVERY_CODE, newRecoveryCodes.stream())); return newRecoveryCodes.stream(); } RecoveryServiceImpl(
      DataService dataService,
      UserService userService,
      RecoveryCodeFactory recoveryCodeFactory,
      IdGenerator idGenerator); @Override @Transactional Stream<RecoveryCode> generateRecoveryCodes(); @Override @Transactional void useRecoveryCode(String recoveryCode); @Override Stream<RecoveryCode> getRecoveryCodes();  }