Skip to content

Commit

Permalink
Revise CustomObjectValue test expected result
Browse files Browse the repository at this point in the history
The defaultValue was the same as the value returned by the
CustomObject class, so it was not clear which result was being
returned.

Changed the return value from the CustomObject class to be clearly
different from the default value.
  • Loading branch information
MarkEWaite committed Jan 26, 2024
1 parent b165cc7 commit c7ca01f
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ void setUp() {

// A custom class to control the toString() behavior
private static class CustomObject {
final String returnValue;

CustomObject(String returnValue) {
this.returnValue = returnValue;
}

@Override
public String toString() {
return "default";
return returnValue;
}
}

Expand Down Expand Up @@ -93,17 +99,18 @@ void resolveShouldReplaceParameterWithDefaultValueIfParamValueIsNull() {
}

@Test
void resolveShouldReplaceParameterWithDefaultValueIfParamValueToStringIsNull() {
void resolveShouldReplaceParameterWithCustomObjectValueIfParamValueToStringIsNull() {
String paramName = "paramName";
String defaultValue = "default";
String parameter = "params." + paramName + "|" + defaultValue;
String customObjectReturnValue = defaultValue + "CustomObject";

ParameterValue valueMock = mock(ParameterValue.class);
when(valueMock.getValue()).thenReturn(new CustomObject());
when(valueMock.getValue()).thenReturn(new CustomObject(customObjectReturnValue));

when(paramsMock.getParameter(paramName)).thenReturn(valueMock);
when(runMock.getAction(ParametersAction.class)).thenReturn(paramsMock);

assertEquals(defaultValue, resolver.resolve(runMock, parameter));
assertEquals(customObjectReturnValue, resolver.resolve(runMock, parameter));
}
}

0 comments on commit c7ca01f

Please sign in to comment.