-1

This code when executed returns an ArrayoutOfBoundsException:0 Source Code :

public static String foo(final EnumClass enumObject){
    switch(enumObject){
        case CASE1 : return "case1";
        case CASE2 : return "case2";
        default : return "invalid";
    }
}

Enum Def :

EnumClass{
    CASE1,CASE2;
}

Test Code :

public void testFoo(){
    assertEquals("case1",foo(EnumClass.CASE1));
}
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
jazz
  • 27
  • 1
  • 10
  • 3
    Please post the stack trace of your exception! – isnot2bad Nov 25 '13 at 13:59
  • http://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors – isnot2bad Nov 25 '13 at 14:00
  • 2
    You are not getting that exception, with this code. Modify the code above until you actually get the exception you describe. Most likely you will know why you get that exception after that exercise. – Jens Schauder Nov 25 '13 at 14:00

1 Answers1

0

The following passes without error therefore something else in your code is causing the error:

public class TestClass {

public static String foo(final EnumClass enumObject) {
    switch (enumObject) {
    case CASE1:
        return "case1";
    case CASE2:
        return "case2";
    default:
        return "invalid";
    }
}

enum EnumClass {
    CASE1, CASE2;
}

@Test
public void testFoo() {
    Assert.assertEquals("case1", foo(EnumClass.CASE1));
}
}
John B
  • 32,493
  • 6
  • 77
  • 98