Skip to content

Commit

Permalink
change naming of ValidationServiceTests so that all test names start …
Browse files Browse the repository at this point in the history
…with should
  • Loading branch information
nevio18324 committed Dec 19, 2024
1 parent cf9d857 commit a550d5c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void setUp() {

@DisplayName("Should be successful on validateOnCreate() when action is valid")
@Test
void validateOnCreateShouldBeSuccessfulWhenActionIsValid() {
void shouldBeSuccessfulOnValidateOnCreateWhenActionIsValid() {
validator.validateOnCreate(action1);

verify(validator, times(1)).throwExceptionWhenModelIsNull(action1);
Expand All @@ -119,7 +119,7 @@ void validateOnCreateShouldBeSuccessfulWhenActionIsValid() {

@DisplayName("Should throw exception on validateOnCreate() when model is null")
@Test
void validateOnCreateShouldThrowExceptionWhenModelIsNull() {
void shouldThrowExceptionOnValidateOnCreateWhenModelIsNull() {
// arrange
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
() -> validator.validateOnCreate(null));
Expand All @@ -132,7 +132,7 @@ void validateOnCreateShouldThrowExceptionWhenModelIsNull() {

@DisplayName("Should be successful on validateOnCreate() when id is not null")
@Test
void validateOnCreateShouldThrowExceptionWhenIdIsNotNull() {
void shouldThrowExceptionOnValidateOnCreateWhenIdIsNotNull() {
// arrange
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
() -> validator.validateOnCreate(action2));
Expand All @@ -145,7 +145,7 @@ void validateOnCreateShouldThrowExceptionWhenIdIsNotNull() {

@ParameterizedTest(name = "should throw exception on validateOnCreate() when model has invalid text {0}")
@MethodSource("actionValidationArguments")
void validateOnCreateShouldThrowExceptionWhenActionIsInvalid(String actionText, List<ErrorDto> errors) {
void shouldThrowExceptionOnValidateOnCreateWhenActionIsInvalid(String actionText, List<ErrorDto> errors) {
// arrange
Action action = Action.Builder.builder().withId(null).withAction(actionText).isChecked(false).withPriority(1)
.withKeyResult(keyResult).build();
Expand All @@ -159,7 +159,7 @@ void validateOnCreateShouldThrowExceptionWhenActionIsInvalid(String actionText,

@DisplayName("Should throw exception on validateOnCreate() when attributes are missing")
@Test
void validateOnCreateShouldThrowExceptionWhenAttrsAreMissing() {
void shouldThrowExceptionOnValidateOnCreateWhenAttrsAreMissing() {
// arrange
Action actionInvalid = Action.Builder.builder().isChecked(true).build();

Expand All @@ -175,7 +175,7 @@ void validateOnCreateShouldThrowExceptionWhenAttrsAreMissing() {

@DisplayName("Should be successful on validateOnUpdate() when action is valid")
@Test
void validateOnUpdateShouldBeSuccessfulWhenActionIsValid() {
void shouldBeSuccessfulOnValidateOnUpdateWhenActionIsValid() {
// arrange
when(actionPersistenceService.findById(anyLong())).thenReturn(action2);

Expand All @@ -193,7 +193,7 @@ void validateOnUpdateShouldBeSuccessfulWhenActionIsValid() {

@DisplayName("Should throw exception on validateOnUpdate() when model is null")
@Test
void validateOnUpdateShouldThrowExceptionWhenModelIsNull() {
void shouldThrowExceptionOnValidateOnUpdateWhenModelIsNull() {
// arrange
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
() -> validator.validateOnUpdate(1L, null));
Expand All @@ -206,7 +206,7 @@ void validateOnUpdateShouldThrowExceptionWhenModelIsNull() {

@DisplayName("Should throw exception on validateOnUpdate() when id is null")
@Test
void validateOnUpdateShouldThrowExceptionWhenIdIsNull() {
void shouldThrowExceptionOnValidateOnUpdateWhenIdIsNull() {
// act + assert
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
() -> validator.validateOnUpdate(null, action1));
Expand All @@ -221,7 +221,7 @@ void validateOnUpdateShouldThrowExceptionWhenIdIsNull() {

@DisplayName("Should throw exception on validateOnUpdate() when id has changed")
@Test
void validateOnUpdateShouldThrowExceptionWhenIdHasChanged() {
void shouldThrowExceptionOnValidateOnUpdateWhenIdHasChanged() {
// act + assert
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
() -> validator.validateOnUpdate(1L, action2));
Expand All @@ -237,7 +237,7 @@ void validateOnUpdateShouldThrowExceptionWhenIdHasChanged() {

@DisplayName("Should throw exception on validateOnUpdate() when no entity can be found")
@Test
void validateOnUpdateShouldThrowExceptionWhenEntityDoesNotExist() {
void shouldThrowExceptionOnValidateOnUpdateWhenEntityDoesNotExist() {
// arrange
String reason = "MODEL_WITH_ID_NOT_FOUND";
when(actionPersistenceService.findById(anyLong()))
Expand All @@ -258,7 +258,7 @@ void validateOnUpdateShouldThrowExceptionWhenEntityDoesNotExist() {
@DisplayName("Should throw exception on validateOnUpdate() when KeyResult is not set")
@ParameterizedTest
@MethodSource("actionPairArgument")
void validateOnUpdateShouldThrowExceptionWhenKeyResultNotSet(ActionPair actionPair) {
void shouldThrowExceptionOnValidateOnUpdateWhenKeyResultNotSet(ActionPair actionPair) {
// arrange
Action action = actionPair.action();
Action saveAction = actionPair.saveAction();
Expand All @@ -281,7 +281,7 @@ void validateOnUpdateShouldThrowExceptionWhenKeyResultNotSet(ActionPair actionPa

@DisplayName("should throw exception on validateOnUpdate() when key result id has changed")
@Test
void validateOnUpdateShouldThrowExceptionWhenKeyResultIdHasChanged() {
void shouldThrowExceptionOnValidateOnUpdateWhenKeyResultIdHasChanged() {
// arrange
Action action = Action.Builder.builder().withId(action2.getId()).withAction("Action").isChecked(false)
.withPriority(1)
Expand All @@ -303,7 +303,7 @@ void validateOnUpdateShouldThrowExceptionWhenKeyResultIdHasChanged() {

@ParameterizedTest(name = "should throw exception on validateOnUpdate() when model has invalid text {0}")
@MethodSource("actionValidationArguments")
void validateOnUpdateShouldThrowExceptionWhenTitleIsInvalid(String actionText, List<ErrorDto> errors) {
void shouldThrowExceptionOnValidateOnUpdateWhenTitleIsInvalid(String actionText, List<ErrorDto> errors) {
// arrange
Action action = Action.Builder.builder().withId(3L).withAction(actionText).isChecked(false).withPriority(1)
.withKeyResult(keyResult).build();
Expand All @@ -317,7 +317,7 @@ void validateOnUpdateShouldThrowExceptionWhenTitleIsInvalid(String actionText, L

@DisplayName("should throw exception on validateOnUpdate() when key result is missing in model")
@Test
void validateOnUpdateShouldThrowExceptionWhenKeyResultIsMissing() {
void shouldThrowExceptionOnValidateOnUpdateWhenKeyResultIsMissing() {
// arrange
Action actionInvalid = Action.Builder.builder().withId(11L).isChecked(true).build();
when(actionPersistenceService.findById(anyLong())).thenReturn(actionInvalid);
Expand All @@ -333,7 +333,7 @@ void validateOnUpdateShouldThrowExceptionWhenKeyResultIsMissing() {

@DisplayName("should throw exception on validateOnUpdate() when attributes are missing")
@Test
void validateOnUpdateShouldThrowExceptionWhenAttrsAreMissing() {
void shouldThrowExceptionOnValidateOnUpdateWhenAttrsAreMissing() {
// arrange
Action actionInvalid = Action.Builder.builder().withId(11L).isChecked(true).withKeyResult(keyResult).build();
when(actionPersistenceService.findById(anyLong())).thenReturn(actionInvalid);
Expand All @@ -349,7 +349,7 @@ void validateOnUpdateShouldThrowExceptionWhenAttrsAreMissing() {

@DisplayName("should be successful on validateOnGetByKeyResultId() when id is not null")
@Test
void validateOnGetByKeyResultIdShouldBeSuccessfulWhenIdIsNotNull() {
void shouldBeSuccessfulInValidateOnGetByKeyResultIdWhenIdIsNotNull() {
// arrange
Long id = 1L;
doNothing().when(keyResultValidationService).validateOnGet(id);
Expand All @@ -361,7 +361,7 @@ void validateOnGetByKeyResultIdShouldBeSuccessfulWhenIdIsNotNull() {

@DisplayName("should throw exception on validateOnGetByKeyResultId() when id is null")
@Test
void validateOnGetByKeyResultIdShouldThrowExceptionWhenIdIsNull() {
void shouldThrowExceptionOnValidateOnGetByKeyResultIdWhenIdIsNull() {
// arrange
Long id = null;
doThrow(OkrResponseStatusException.class).when(keyResultValidationService).validateOnGet(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,26 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
class AlignmentValidationServiceTest {
private final Alignment keyResultAlignment = new KeyResultAlignment();
@MockitoBean
AlignmentPersistenceService alignmentPersistenceService = Mockito.mock(AlignmentPersistenceService.class);
private final Alignment keyResultAlignment = new KeyResultAlignment();

@Spy
@InjectMocks
private AlignmentValidationService validator;

@DisplayName("Should throw exception on validateOnCreate()")
@Test
void validateOnCreateShouldThrowException() {
void shouldThrowExceptionOnValidateOnCreate() {
assertThrows(UnsupportedOperationException.class, () -> validator.validateOnCreate(keyResultAlignment));
}

@DisplayName("Should throw exception on validateOnUpdate() when id is null")
@Test
void validateOnUpdateShouldThrowExceptionWhenIdIsNull() {
void shouldThrowExceptionOnValidateOnUpdateWhenIdIsNull() {
when(alignmentPersistenceService.getModelName()).thenReturn("Alignment");

OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
Expand All @@ -56,7 +53,7 @@ void validateOnUpdateShouldThrowExceptionWhenIdIsNull() {

@DisplayName("Should throw exception on validateOnUpdate() when id of alignment is null")
@Test
void validateOnUpdateShouldThrowExceptionWhenIdOfAlignmentIsNull() {
void shouldThrowExceptionOnValidateOnValidateOnUpdateWhenIdOfAlignmentIsNull() {
when(alignmentPersistenceService.getModelName()).thenReturn("Alignment");
Alignment alignment = KeyResultAlignment.Builder.builder().withId(null).build();

Expand All @@ -72,7 +69,7 @@ void validateOnUpdateShouldThrowExceptionWhenIdOfAlignmentIsNull() {

@DisplayName("Should throw exception on validateOnUpdate() when id has changed")
@Test
void validateOnUpdateShouldThrowExceptionWhenIdHasChanged() {
void shouldThrowExceptionOnValidateOnUpdateWhenIdHasChanged() {
Alignment alignment = KeyResultAlignment.Builder.builder().withId(3L).build();

OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
Expand All @@ -86,7 +83,7 @@ void validateOnUpdateShouldThrowExceptionWhenIdHasChanged() {

@DisplayName("Should throw exception on validateOnUpdate() when model is invalid")
@Test
void validateOnUpdateShouldValidateDto() {
void shouldThrowExceptionOnValidateOnUpdateWhenModelIsInvalid() {
when(alignmentPersistenceService.getModelName()).thenReturn("Alignment");
Alignment alignment = KeyResultAlignment.Builder.builder().withId(2L).withAlignedObjective(null).withVersion(1)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ void setUp() {

@DisplayName("Should be successful on validateOnGet() when id is valid")
@Test
void validateOnGetShouldBeSuccessfulWhenValidCheckInId() {
void shouldBeSuccessfulOnValidateOnGetWhenValidCheckInId() {
validator.validateOnGet(1L);
verify(validator, times(1)).throwExceptionWhenIdIsNull(1L);
}

@DisplayName("Should throw exception on validateOnGet() when id is null")
@Test
void validateOnGetShouldThrowExceptionIfCheckInIdIsNull() {
void shouldThrowExceptionOnValidateOnGetIfCheckInIdIsNull() {
// act + assert
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
() -> validator.validateOnGet(null));
Expand All @@ -101,7 +101,7 @@ void validateOnGetShouldThrowExceptionIfCheckInIdIsNull() {

@DisplayName("Should be successful on validateOnCreate() when check in is valid")
@Test
void validateOnCreateShouldBeSuccessfulWhenCheckInIsValid() {
void shouldBeSuccessfulOnValidateOnCreateWhenCheckInIsValid() {
when(checkInPersistenceService.findById(checkInMetric.getId())).thenReturn(checkInMetric);

validator.validateOnCreate(checkInMetric);
Expand All @@ -113,7 +113,7 @@ void validateOnCreateShouldBeSuccessfulWhenCheckInIsValid() {

@DisplayName("Should throw exception on validateOnCreate() when model is null")
@Test
void validateOnCreateShouldThrowExceptionWhenModelIsNull() {
void shouldThrowExceptionOnValidateOnCreateWhenModelIsNull() {
// act + assert
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
() -> validator.validateOnCreate(null));
Expand All @@ -124,7 +124,7 @@ void validateOnCreateShouldThrowExceptionWhenModelIsNull() {

@DisplayName("Should throw exception on validateOnCreate() when id is not null")
@Test
void validateOnCreateShouldThrowExceptionWhenIdIsNotNull() {
void shouldThrowExceptionOnValidateOnCreateWhenIdIsNotNull() {
// act + assert
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
() -> validator.validateOnCreate(fullCheckIn));
Expand All @@ -135,7 +135,7 @@ void validateOnCreateShouldThrowExceptionWhenIdIsNotNull() {

@ParameterizedTest(name = "should throw exception on validateOnCreate() when confidence has invalid value {0}")
@MethodSource("confidenceValidationArguments")
void validateOnCreateShouldThrowExceptionWhenConfidenceIsInvalid(Integer confidence,
void shouldThrowExceptionOnValidateOnCreateWhenConfidenceIsInvalid(Integer confidence,
List<ErrorDto> expectedErrors) {

// arrange
Expand All @@ -158,7 +158,7 @@ void validateOnCreateShouldThrowExceptionWhenConfidenceIsInvalid(Integer confide

@DisplayName("Should throw exception on validateOnCreate() when attributes are missing")
@Test
void validateOnCreateShouldThrowExceptionWhenAttrsAreMissing() {
void shouldThrowExceptionOnValidateOnCreateWhenAttrsAreMissing() {
// arrange
CheckIn checkInInvalid = CheckInMetric.Builder.builder() //
.withId(null) //
Expand Down Expand Up @@ -192,7 +192,7 @@ void validateOnUpdateShouldBeSuccessfulWhenCheckInIsValid() {

@DisplayName("Should throw exception on validateOnUpdate() when model is null")
@Test
void validateOnUpdateShouldThrowExceptionWhenModelIsNull() {
void shouldThrowExceptionOnValidateOnUpdateWhenModelIsNull() {
// act + assert
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
() -> validator.validateOnUpdate(1L, null));
Expand All @@ -203,7 +203,7 @@ void validateOnUpdateShouldThrowExceptionWhenModelIsNull() {

@DisplayName("Should throw exception on validateOnUpdate() when id is null")
@Test
void validateOnUpdateShouldThrowExceptionWhenIdIsNull() {
void shouldThrowExceptionOnValidateOnUpdateWhenIdIsNull() {
// act + assert
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
() -> validator.validateOnUpdate(null, checkInOrdinal));
Expand All @@ -217,7 +217,7 @@ void validateOnUpdateShouldThrowExceptionWhenIdIsNull() {

@DisplayName("Should throw exception on validateOnUpdate() when id has changed")
@Test
void validateOnUpdateShouldThrowExceptionWhenIdIsHasChanged() {
void shouldThrowExceptionOnValidateOnUpdateWhenIdIsHasChanged() {
// act + assert
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
() -> validator.validateOnUpdate(2L, checkInOrdinal));
Expand All @@ -232,7 +232,7 @@ void validateOnUpdateShouldThrowExceptionWhenIdIsHasChanged() {

@ParameterizedTest(name = "should throw exception on validateOnUpdate() when confidence has invalid value {0}")
@MethodSource("confidenceValidationArguments")
void validateOnUpdateShouldThrowExceptionWhenConfidenceIsInvalid(Integer confidence,
void shouldThrowExceptionOnValidateOnUpdateWhenConfidenceIsInvalid(Integer confidence,
List<ErrorDto> expectedErrors) {

// arrange
Expand All @@ -251,7 +251,7 @@ void validateOnUpdateShouldThrowExceptionWhenConfidenceIsInvalid(Integer confide

@DisplayName("Should throw exception on validateOnUpdate() when check ins are empty")
@Test
void validateOnUpdateShouldThrowExceptionWhenCheckInsOfKeyResultIsEmpty() {
void shouldThrowExceptionOnValidateOnUpdateWhenCheckInsOfKeyResultIsEmpty() {
// arrange
Long id = 2L;
CheckIn checkIn = CheckInMetric.Builder.builder().withValue(40.9).withId(id).withChangeInfo("ChangeInfo")
Expand All @@ -277,7 +277,7 @@ void validateOnUpdateShouldThrowExceptionWhenCheckInsOfKeyResultIsEmpty() {

@DisplayName("Should throw exception on validateOnUpdate() when attributes are missing")
@Test
void validateOnUpdateShouldThrowExceptionWhenAttrsAreMissing() {
void shouldThrowExceptionOnValidateOnUpdateWhenAttrsAreMissing() {
// arrange
Long id = 11L;
CheckIn checkInInvalid = CheckInMetric.Builder.builder() //
Expand All @@ -301,15 +301,15 @@ void validateOnUpdateShouldThrowExceptionWhenAttrsAreMissing() {

@DisplayName("Should be successful on validateOnDelete() when id is valid")
@Test
void validateOnDeleteShouldBeSuccessfulWhenValidKeyResultId() {
void shouldBeSuccessfulOnValidateOnDeleteWhenValidKeyResultId() {
validator.validateOnDelete(1L);
verify(validator, times(1)).throwExceptionWhenIdIsNull(1L);
verify(validator, times(1)).doesEntityExist(1L);
}

@DisplayName("Should throw exception on validateOnDelete() when id is null")
@Test
void validateOnDeleteShouldThrowExceptionIfKeyResultIdIsNull() {
void shouldThrowExceptionOnValidateOnDeleteWhenKeyResultIdIsNull() {
// act + assert
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
() -> validator.validateOnDelete(null));
Expand Down
Loading

0 comments on commit a550d5c

Please sign in to comment.