Bin grad echt ratlos...
Hier mal etwas Code...
Ihr müsst nicht viel lesen, nur soviel:
Die Bedingung, die die RuntimeException werfen soll, wird in einem JUnit Test offensichtlich erfüllt,denn ich bekomme über das sout meine Meldung ausgegeben ("RuntimeException")
[HIGHLIGHT="Java"]public static String expand(String input) throws RuntimeException {
String test="";
for (int i=0;i<input.length();i++) {
try {
final char chr = input.charAt(i);
/* Marker found! */
if (chr == 'Z') {
i++;
char zweiterchr = input.charAt(i);
if ((int)(zweiterchr) <48 || (int)(zweiterchr)>57) {
System.out.println("RuntimeException!");
throw new RuntimeException();
}
int counter = (int)(input.charAt(i)-'0'); // this one has to be of type counted
i++;
for (int j=0;j<counter;j++) { // repeat *counted* times
test += input.charAt(i); // this one has to be the compressed char
}
}
else // no marker found...return input
test += chr;
}
catch (Exception e) {
break; // end of string reached already !
}
}
return test;
}[/HIGHLIGHT]
Mein JUnit Test:
[HIGHLIGHT="Java"]@Test(expected=RuntimeException.class) public void expand5() {
RunlengthCompressor.expand("ZbB");
}[/HIGHLIGHT]
Dies hier ist der Test,der die Bedingung erfüllt, es wird auch "RuntimeException!" über sout ausgegeben...
Trotzdem erhalte ich immer den Fehler, dass die Exception, die erwartet wird, nicht kommt.
Warum nicht?
Hier mal etwas Code...
Ihr müsst nicht viel lesen, nur soviel:
Die Bedingung, die die RuntimeException werfen soll, wird in einem JUnit Test offensichtlich erfüllt,denn ich bekomme über das sout meine Meldung ausgegeben ("RuntimeException")
[HIGHLIGHT="Java"]public static String expand(String input) throws RuntimeException {
String test="";
for (int i=0;i<input.length();i++) {
try {
final char chr = input.charAt(i);
/* Marker found! */
if (chr == 'Z') {
i++;
char zweiterchr = input.charAt(i);
if ((int)(zweiterchr) <48 || (int)(zweiterchr)>57) {
System.out.println("RuntimeException!");
throw new RuntimeException();
}
int counter = (int)(input.charAt(i)-'0'); // this one has to be of type counted
i++;
for (int j=0;j<counter;j++) { // repeat *counted* times
test += input.charAt(i); // this one has to be the compressed char
}
}
else // no marker found...return input
test += chr;
}
catch (Exception e) {
break; // end of string reached already !
}
}
return test;
}[/HIGHLIGHT]
Mein JUnit Test:
[HIGHLIGHT="Java"]@Test(expected=RuntimeException.class) public void expand5() {
RunlengthCompressor.expand("ZbB");
}[/HIGHLIGHT]
Dies hier ist der Test,der die Bedingung erfüllt, es wird auch "RuntimeException!" über sout ausgegeben...
Trotzdem erhalte ich immer den Fehler, dass die Exception, die erwartet wird, nicht kommt.
Warum nicht?