Skip to content

3-3-0 enable-string-trimming tests #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -188,6 +189,34 @@ void trimmedAnnotationPostProcessorAnnotatedInputParams(@Autowired TrimmedServic
assertEquals(inputArgs.trim(), actual);
}

@Test
@DisplayName("TrimmedAnnotationBeanPostProcessor trims String input params marked with @Trimmed and ignore not annotated")
void trimmedAnnotationPostProcessorAnnotatedAndNotAnnotatedInputParams(@Autowired TrimmedService service) {
String inputArgs = " Simba Bimba ";
String inputArgs2 = " Timon Lemon ";
String actual = service.getTheTrimmedStringWithTwoArgs(inputArgs, inputArgs2);

assertEquals(inputArgs.trim().concat(inputArgs2), actual);
}

@Test
@DisplayName("TrimmedAnnotationBeanPostProcessor trims several String input params marked with @Trimmed and ignore not annotated")
void trimmedAnnotationPostProcessorSeveralAnnotatedAndNotAnnotatedInputParams(@Autowired TrimmedService service) {
String inputArgs = " Simba Bimba ";
String inputArgs2 = " Timon Lemon ";
String inputArgs3 = " Pumba Lumba ";
String actual = service.getTheTrimmedStringWithThreeArgs(inputArgs, inputArgs2, inputArgs3);

assertEquals(inputArgs.trim().concat(inputArgs2).concat(inputArgs3.trim()), actual);
}

@Test
@DisplayName("TrimmedAnnotationBeanPostProcessor not trims non-String input params marked with @Trimmed")
void trimmedAnnotationPostProcessorAnnotatedNonStringInputParams(@Autowired TrimmedService service) {
Integer inputArg = 1;
assertDoesNotThrow(() -> service.getTheTrimmedInteger(inputArg), "Annotated parameter must ignore non-String types");
}

@Test
@DisplayName("TrimmedAnnotationBeanPostProcessor not trims String input params that not marked by @Trimmed")
void trimmedAnnotationPostProcessorNotAnnotatedInputParams(@Autowired TrimmedService service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ public String getTheTrimmedString(@Trimmed String string) {
return string;
}

public String getTheTrimmedInteger(@Trimmed Integer num) {
return num.toString();
}

public String getTheTrimmedStringWithTwoArgs(@Trimmed String stringOne, String stringTwo) {
return stringOne.concat(stringTwo);
}

public String getTheTrimmedStringWithThreeArgs(@Trimmed String stringOne, String stringTwo, @Trimmed String stringThree) {
return stringOne.concat(stringTwo).concat(stringThree);
}

public String getNotTrimmedString(String string) {
return string;
}
Expand Down