Question 2 (3 points): Assuming you are assigned to conduct the component test for the method below, please design and create the minimum component test cases (Unit Test case) needed to achieve 100% statement coverage and 100% decision coverage. (Use question 2 template).
The countCharacters method that counts the number of uppercase letters, lowercase letters,numeric characters, and special characters in a given input string. It returns a HashMap containing this information.
1
2
3 @
import java.util.HashMap;
public class Character Counter {
public static HashMap<String, Integer> countCharacters(String input) {
int upperCaseCount = 0;int lowerCaseCount = 0;
5
6
int numericCount = 0;
7
int specialCharCount = 0;
8
9
10
11
12
13
14
15
16
17
for (char c input.toCharArray()) {
if (Character.isUpperCase(c)) {
upper CaseCount++;
} else if (Character.isLowerCase(c)) {
lower CaseCount++;
} else if (Character.isDigit(c)) {
numericCount++;
} else {
specialCharCount++;
18
}
19
}
20
21
22
23
24
25
26
27
HashMap<String, Integer> character Counts = new HashMap<>();characterCounts.put("UpperCase", upperCaseCount);
characterCounts.put("LowerCase", lowerCaseCount);characterCounts.put("Numeric", numericCount);
characterCounts.put("SpecialCharacter", specialCharCount);
return characterCounts;
28
29
}
}
Zoom
+ 100%
Close