-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDuplicateCharactersCounterTest.java
61 lines (53 loc) · 2.38 KB
/
DuplicateCharactersCounterTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package io.github.dbc;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EmptySource;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
class DuplicateCharactersCounterTest {
private DuplicateCharactersCounter counter;
@BeforeEach
void setUp() {
counter = new DuplicateCharactersCounter();
}
@ParameterizedTest(name = "countDuplicateCharacters(\"{arguments}\")")
@ValueSource(strings = {"abcdefghijklmnopqrstuvwxyz", "dbc", "A", "1234567890", " "})
@DisplayName("should return map of correct size")
void shouldReturnMapOfCorrectSize(String input) {
// Act
var characterIntegerMap = counter.countDuplicateCharacters(input);
// Assert
assertEquals(input.length(), characterIntegerMap.size(), "the map should have the same size as the input string");
}
@Test
@DisplayName("should return count as 1 for all non duplicate characters")
void shouldReturnCount1ForNonDuplicateCharacters() {
// Arrange
String input = "abcdefghijklmnopqrstuvwxyz";
// Act
var characterIntegerMap = counter.countDuplicateCharacters(input);
// get the value for key 'a'
var count = characterIntegerMap.get('a');
// Assert
assertEquals(1, count, "the count value for all non duplicate characters should be 1");
}
@ParameterizedTest(name = "countDuplicateCharacters({arguments})")
@NullSource
@DisplayName("should throw an IllegalArgumentException for null input")
void shouldThrowAnIllegalArgumentExceptionForNullInput(String input) {
assertThrows(IllegalArgumentException.class, () -> counter.countDuplicateCharacters(input));
}
@ParameterizedTest(name = "countDuplicateCharacters(\"{arguments}\")")
@EmptySource
@DisplayName("should return empty map for empty input")
void shouldReturnEmptyMapForEmptyInput(String input) {
// Act
var characterIntegerMap = counter.countDuplicateCharacters(input);
// Assert
assertEquals(0, characterIntegerMap.size(), "the map should be empty");
}
}