Skip to content

Commit

Permalink
move asserts from teardown into check method
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonEntholzer committed Dec 3, 2024
1 parent f6ed392 commit 2232df3
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,6 @@ class UserSshPublicKeyExpiryNotificationServiceShould {

@AfterEach
void tearDown() {
assertThat(sentNotifications.getFirst()).isInstanceOf(SingleUserNotification.class);
assertThat(((SingleUserNotification) sentNotifications.getFirst()).getRecipient()).isEqualTo(user);
assertThat((sentNotifications.getFirst()).getText()).isEqualTo(SSH_KEY_ADDED_TEXT);

userSshPublicKeyRepository.deleteAll();
}

Expand All @@ -424,6 +420,7 @@ void notifyUserAboutNewlyCreatedSshKeyWithExpirationDate() throws GeneralSecurit
userSshPublicKeyService.createSshKeyForUser(user, AuthorizedKeyEntry.parseAuthorizedKeyEntry(keyDTO.publicKey()), keyDTO);

sentNotifications = notificationRepository.findAll();
checkFirstNotification();
}

@Test
Expand All @@ -433,6 +430,7 @@ void notifyUserAboutNewlyCreatedSshKeyWithNoDate() throws GeneralSecurityExcepti
userSshPublicKeyService.createSshKeyForUser(user, AuthorizedKeyEntry.parseAuthorizedKeyEntry(keyDTO.publicKey()), keyDTO);

sentNotifications = notificationRepository.findAll();
checkFirstNotification();
}

@Test
Expand All @@ -446,6 +444,7 @@ void notifyUserAboutUpcomingSshKeyExpiry() throws GeneralSecurityException, IOEx
assertThat(sentNotifications).hasSize(2);
assertThat(((SingleUserNotification) sentNotifications.getFirst()).getRecipient()).isEqualTo(user);
assertThat((sentNotifications.get(1)).getText()).isEqualTo(SSH_KEY_EXPIRES_SOON_TEXT);
checkFirstNotification();
}

@Test
Expand All @@ -459,6 +458,7 @@ void notifyUserAboutExpiredSshKey() throws GeneralSecurityException, IOException
assertThat(sentNotifications).hasSize(2);
assertThat(((SingleUserNotification) sentNotifications.getFirst()).getRecipient()).isEqualTo(user);
assertThat((sentNotifications.get(1)).getText()).isEqualTo(SSH_KEY_HAS_EXPIRED_TEXT);
checkFirstNotification();
}

@Test
Expand All @@ -470,6 +470,7 @@ void notNotifyUserAboutUpcomingSshKeyExpiryWhenKeyDoesNotExpireSoon() throws Gen

sentNotifications = notificationRepository.findAll();
assertThat(sentNotifications).hasSize(1);
checkFirstNotification();
}

@Test
Expand All @@ -481,6 +482,13 @@ void notNotifyUserAboutExpiredSshKeyWhenKeyIsNotExpired() throws GeneralSecurity

sentNotifications = notificationRepository.findAll();
assertThat(sentNotifications).hasSize(1);
checkFirstNotification();
}

void checkFirstNotification() {
assertThat(sentNotifications.getFirst()).isInstanceOf(SingleUserNotification.class);
assertThat(((SingleUserNotification) sentNotifications.getFirst()).getRecipient()).isEqualTo(user);
assertThat((sentNotifications.getFirst()).getText()).isEqualTo(SSH_KEY_ADDED_TEXT);
}
}

Expand Down

0 comments on commit 2232df3

Please sign in to comment.