I am doing Test Driven Development.So i created a case that needs to send an array of strings to the function.That function will check if the array has any uppercase letter strings.If there is then it needs to print all the strings as "name , name, name and name are awesome ".So before the last one it should be putting an "and".
It is sometimes giving me dead code error because there are other cases that might be interfering with the execution of this case.
Test Case
@Test
void testAcceptsAJumbleOfUpperCaseAndLowerCase() {
theAmazingPeter obj = new theAmazingPeter();
String[] arr = {"Peter","GUNEET"};
String result = obj.AmazingPerson(arr);
assertEquals("Peter, and GUNEET are 7.amazing",result);
}
}
Statement
1.else {
2. for(int i = 0;i < names.length;i++) {
3. if(names.length >= 1 && 4.names[i].equals(names[i].toUpperCase())) {
5. if(i > 0 ) {
6. sb.append(", ");
7. if(i == names.length - 1) {
8. sb.append("and ");
9. }
10. }
11. sb.append(names[i]);
12. }
13. System.out.println(sb.toString() + " are 14.amazing");
15.
16. }String result = sb.toString() + " are amazing";
17. return result;
18.
19. }
Aucun commentaire:
Enregistrer un commentaire