Skip to content

Commit b7b26fc

Browse files
committed
use the @nullsource and @EmptySource annotations for tests
1 parent 55cb5de commit b7b26fc

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

.idea/workspace.xml

Lines changed: 21 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/java/io/github/dbc/DuplicateCharactersCounterTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.junit.jupiter.api.DisplayName;
55
import org.junit.jupiter.api.Test;
66
import org.junit.jupiter.params.ParameterizedTest;
7+
import org.junit.jupiter.params.provider.EmptySource;
8+
import org.junit.jupiter.params.provider.NullSource;
79
import org.junit.jupiter.params.provider.ValueSource;
810

911
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -41,17 +43,17 @@ void shouldReturnCount1ForNonDuplicateCharacters() {
4143
assertEquals(1, count, "the count value for all non duplicate characters should be 1");
4244
}
4345

44-
@Test
46+
@ParameterizedTest
47+
@NullSource
4548
@DisplayName("should throw an IllegalArgumentException for null input")
46-
void shouldThrowAnIllegalArgumentExceptionForNullInput() {
47-
assertThrows(IllegalArgumentException.class, () -> counter.countDuplicateCharacters(null));
49+
void shouldThrowAnIllegalArgumentExceptionForNullInput(String input) {
50+
assertThrows(IllegalArgumentException.class, () -> counter.countDuplicateCharacters(input));
4851
}
4952

50-
@Test
53+
@ParameterizedTest
54+
@EmptySource
5155
@DisplayName("should return empty map for empty input")
52-
void shouldReturnEmptyMapForEmptyInput() {
53-
// Arrange
54-
String input = "";
56+
void shouldReturnEmptyMapForEmptyInput(String input) {
5557
// Act
5658
var characterIntegerMap = counter.countDuplicateCharacters(input);
5759
// Assert

0 commit comments

Comments
 (0)