Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Can I test (junit) default case of switch-case statement ?

807589Nov 4 2008 — edited Nov 4 2008
Hi,

I have a class which has switch-case statements and I am trying to junit test with 100% coverage. My switch-case workes based on enum values.

say my enum values are 1, 2.

switch(getEnumValues) {

case 1:
return "some value";
case 2:
return "some value";
default:
throw new UnsupportedOperationException("No such enum value supported.");
}

I have test case to test the case 1 and 2 but I am not able to test default case. Can anyone please let me know how can I right a junit test case for default case.

Edited by: TUIJAVADEV on Nov 4, 2008 4:15 PM

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 2 2008
Added on Nov 4 2008
10 comments
6,221 views