Skip to content
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

Clean up: use BlankStringSource in tests #1064

Merged
merged 1 commit into from
Oct 8, 2023
Merged
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
7 changes: 3 additions & 4 deletions src/test/java/org/kiwiproject/base/KiwiEnumsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.junit.jupiter.params.provider.ValueSource;
import org.kiwiproject.util.BlankStringArgumentsProvider;
import org.kiwiproject.util.BlankStringSource;

@DisplayName("KiwiEnums")
class KiwiEnumsTest {
Expand All @@ -28,7 +27,7 @@ void shouldThrowIllegalArgumentWhenEnumClasIsNull() {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldReturnEmptyOptionalWhenGivenBlankInput(String input) {
assertThat(KiwiEnums.getIfPresent(Season.class, input)).isEmpty();
}
Expand Down Expand Up @@ -65,7 +64,7 @@ void shouldThrowIllegalArgumentWhenEnumClasIsNull() {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldReturnEmptyOptionalWhenGivenBlankInput(String input) {
assertThat(KiwiEnums.getIfPresent(Season.class, input)).isEmpty();
}
Expand Down
15 changes: 7 additions & 8 deletions src/test/java/org/kiwiproject/base/KiwiPreconditionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.junit.jupiter.params.provider.ValueSource;
import org.kiwiproject.util.BlankStringArgumentsProvider;
import org.kiwiproject.util.BlankStringSource;

import java.math.BigInteger;
import java.time.Instant;
Expand Down Expand Up @@ -278,7 +277,7 @@ class CheckArgumentIsBlank {
class WithNoMessage {

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldNotThrow_WhenArgumentIsBlank(String string) {
assertThatCode(() -> KiwiPreconditions.checkArgumentIsBlank(string))
.doesNotThrowAnyException();
Expand All @@ -295,7 +294,7 @@ void shouldThrowIllegalArgument_WhenArgumentIsNotBlank() {
class WithMessage {

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldNotThrow_WhenArgumentIsBlank(String string) {
assertThatCode(() -> KiwiPreconditions.checkArgumentIsBlank(string, "the argument cannot be blank"))
.doesNotThrowAnyException();
Expand All @@ -315,7 +314,7 @@ void shouldThrowIllegalArgument_WhenArgumentIsNotBlank() {
class WithTemplateMessage {

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldNotThrow_WhenArgumentIsBlank(String string) {
assertThatCode(() ->
KiwiPreconditions.checkArgumentIsBlank(string, "{} cannot be blank", "foo"))
Expand Down Expand Up @@ -574,14 +573,14 @@ void testRequireNotNullElseGet(SoftAssertions softly) {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void testRequireNotBlank_NoMessage(String value, SoftAssertions softly) {
softly.assertThatThrownBy(() -> requireNotBlank(value))
.isExactlyInstanceOf(IllegalArgumentException.class);
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void testRequireNotBlank_StaticMessage(String value, SoftAssertions softly) {
var errorMessage = "foo cannot be null";

Expand All @@ -592,7 +591,7 @@ void testRequireNotBlank_StaticMessage(String value, SoftAssertions softly) {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void testRequireNotBlank_MessageWithTemplate(String value, SoftAssertions softly) {
var errorMessageTemplate = "{} cannot be null (code: {})";
Object[] args = { "foo", 42 };
Expand Down
21 changes: 10 additions & 11 deletions src/test/java/org/kiwiproject/base/KiwiStringsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.kiwiproject.util.BlankStringArgumentsProvider;
import org.kiwiproject.util.BlankStringSource;

import java.util.List;
import java.util.NoSuchElementException;
Expand Down Expand Up @@ -117,21 +116,21 @@ void shouldSplitOnStringSeparator() {
class NullSafeWithTrimAndOmitEmpty {

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldReturnEmptyIterable_WithBlankArgument(String string) {
var iterable = nullSafeSplitWithTrimAndOmitEmpty(string);
assertThat(iterable).isEmpty();
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldReturnEmptyIterable_WithBlankArgument_AndCharSeparator(String string) {
var iterable = nullSafeSplitWithTrimAndOmitEmpty(string, COMMA);
assertThat(iterable).isEmpty();
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldReturnEmptyIterable_WithBlankArgument_AndStringSeparator(String string) {
var iterable = nullSafeSplitWithTrimAndOmitEmpty(string, String.valueOf(COMMA));
assertThat(iterable).isEmpty();
Expand Down Expand Up @@ -231,32 +230,32 @@ void shouldSplitWithMaxGroups_WithStringSeparator() {
class NullSafeToList {

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldReturnEmptyList_WithBlankArgument(String string) {
assertThat(nullSafeSplitToList(string)).isEmpty();
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldReturnEmptyList_WithBlankArgument_AndCharSeparator(String string) {
assertThat(nullSafeSplitToList(string, COMMA)).isEmpty();
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldReturnEmptyList_WithBlankArgument_AndStringSeparator(String string) {
assertThat(nullSafeSplitToList(string, String.valueOf(COMMA))).isEmpty();
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldReturnEmptyList_WithBlankArgument_AndCharSeparator_AndMaxGroups(String string) {
assertThat(nullSafeSplitToList(string, NEWLINE, 5)).isEmpty();
}


@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldReturnEmptyList_WithBlankArgument_AndStringSeparator_AndMaxGroups(String string) {
assertThat(nullSafeSplitToList(string, String.valueOf(COMMA), 10)).isEmpty();
}
Expand Down Expand Up @@ -434,7 +433,7 @@ void whenSomeoneIsBeingAJerkAndTriesToMixAndMatchGuavaAndSlf4jPlaceholders() {
class BlankToNull {

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldBeNull_WithBlankStrings(String argument) {
var result = blankToNull(argument);
assertThat(result).isNull();
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/org/kiwiproject/collect/KiwiMapsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.kiwiproject.util.BlankStringArgumentsProvider;
import org.kiwiproject.util.BlankStringSource;

import java.nio.file.Path;
import java.time.LocalDate;
Expand Down Expand Up @@ -250,7 +249,7 @@ void whenKeyIsNull() {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void whenKeyIsBlank(String value) {
assertThat(KiwiMaps.keyExistsWithNullValue(Map.of(), value)).isFalse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.kiwiproject.jaxrs.exception.ErrorMessage;
import org.kiwiproject.jaxrs.exception.JaxrsBadRequestException;
import org.kiwiproject.jaxrs.exception.JaxrsValidationException;
import org.kiwiproject.util.BlankStringArgumentsProvider;
import org.kiwiproject.util.BlankStringSource;
import org.kiwiproject.validation.group.ExistingObject;
import org.kiwiproject.validation.group.KiwiValidationGroups;
import org.kiwiproject.validation.group.NewObject;
Expand Down Expand Up @@ -152,7 +151,7 @@ void shouldNotThrow_WhenStringIsNotBlank() {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldThrow_WhenStringIsBlank(String input) {
var thrown = catchThrowable(() ->
KiwiJaxrsValidations.assertNotBlank("mobileNumber", input));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.kiwiproject.collect.KiwiMaps;
import org.kiwiproject.internal.Fixtures;
import org.kiwiproject.json.JsonHelper;
import org.kiwiproject.util.BlankStringArgumentsProvider;
import org.kiwiproject.util.BlankStringSource;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -42,7 +41,7 @@ class ErrorMessageTest {
class ShouldConstruct {

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void withBlankString(String blankString) {
var errorMessage = new ErrorMessage(blankString);

Expand Down Expand Up @@ -211,7 +210,7 @@ void whenMapContainsInvalidStatusCode(SoftAssertions softly) {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void whenMapContainsBlankMessage(String blankMessage) {
// Map.of does not permit null values; use KiwiMaps instead
Map<String, Object> props = KiwiMaps.newHashMap(
Expand Down
7 changes: 3 additions & 4 deletions src/test/java/org/kiwiproject/net/SimpleHostAndPortTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.kiwiproject.util.BlankStringArgumentsProvider;
import org.kiwiproject.util.BlankStringSource;

@DisplayName("SimpleHostAndPort")
class SimpleHostAndPortTest {

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void testFromWithDefaults_WithBlankStrings(String input) {
var hostAndPort = SimpleHostAndPort.from(input, "192.168.1.101", 8900);

Expand Down Expand Up @@ -44,7 +43,7 @@ void testFromWithDefaults_WhenHostOnlyString() {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void testFromWithNoDefaults_WithBlankStrings(String input) {
assertThatThrownBy(() -> SimpleHostAndPort.from(input))
.isExactlyInstanceOf(IllegalArgumentException.class)
Expand Down
17 changes: 8 additions & 9 deletions src/test/java/org/kiwiproject/security/KiwiSecurityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.EnumSource;
import org.kiwiproject.util.BlankStringArgumentsProvider;
import org.kiwiproject.util.BlankStringSource;

import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManagerFactory;
Expand Down Expand Up @@ -150,7 +149,7 @@ void andKeyStorePasswordIsNull() {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void andKeyStoreTypeIsBlank(String blankKeyStoreType) {
assertThatIllegalArgumentException()
.isThrownBy(() ->
Expand All @@ -162,7 +161,7 @@ void andKeyStoreTypeIsBlank(String blankKeyStoreType) {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void andKeyManagerAlgorithmIsBlank(String blankKeyManagerAlgorithm) {
assertThatIllegalArgumentException()
.isThrownBy(() ->
Expand All @@ -176,7 +175,7 @@ void andKeyManagerAlgorithmIsBlank(String blankKeyManagerAlgorithm) {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void whenBlankTrustStorePath(String blankTrustStorePath) {
assertThatIllegalArgumentException()
.isThrownBy(() ->
Expand All @@ -201,7 +200,7 @@ void whenNullTrustStorePassword() {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void whenBlankTrustStoreType(String blankTrustStoreType) {
assertThatIllegalArgumentException()
.isThrownBy(() ->
Expand All @@ -213,7 +212,7 @@ void whenBlankTrustStoreType(String blankTrustStoreType) {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void whenBlankTrustManagerAlgorithm(String blankTrustManagerAlgorithm) {
assertThatIllegalArgumentException()
.isThrownBy(() ->
Expand All @@ -225,7 +224,7 @@ void whenBlankTrustManagerAlgorithm(String blankTrustManagerAlgorithm) {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void whenBlankProtocol(String blankProtocol) {
assertThatIllegalArgumentException()
.isThrownBy(() ->
Expand Down Expand Up @@ -493,4 +492,4 @@ void whenInvalidAlgorithm() {
}
}
}
}
}
9 changes: 4 additions & 5 deletions src/test/java/org/kiwiproject/spring/data/KiwiSortTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.kiwiproject.json.JsonHelper;
import org.kiwiproject.json.JsonHelper.OutputFormat;
import org.kiwiproject.spring.data.KiwiSort.Direction;
import org.kiwiproject.util.BlankStringArgumentsProvider;
import org.kiwiproject.util.BlankStringSource;

import java.util.stream.Stream;

Expand Down Expand Up @@ -89,7 +88,7 @@ void shouldCreateNewAscendingInstance(SoftAssertions softly) {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldNotPermitBlankPropertyForAscendingSort(String value) {
assertThatIllegalArgumentException()
.isThrownBy(() -> KiwiSort.ofAscending(value));
Expand All @@ -108,7 +107,7 @@ void shouldCreateNewDescendingInstance(SoftAssertions softly) {
}

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldNotPermitBlankPropertyForDescendingSort(String value) {
assertThatIllegalArgumentException()
.isThrownBy(() -> KiwiSort.ofDescending(value));
Expand Down Expand Up @@ -138,7 +137,7 @@ void shouldCallToString() {
class DirectionFromString {

@ParameterizedTest
@ArgumentsSource(BlankStringArgumentsProvider.class)
@BlankStringSource
void shouldRequireNonBlankValue(String value) {
assertThatIllegalArgumentException()
.isThrownBy(() -> Direction.fromString(value))
Expand Down
Loading