Question
JAVA question. The test cases are written for Junit5. Is there a way to convert them to Junit 4? Java Code: public class UsingExceptions {
JAVA question. The test cases are written for Junit5. Is there a way to convert them to Junit 4?
Java Code:
public class UsingExceptions { int array[] = {1,2,3,4,5,}; String a = null; String b = "Great way to use exceptions ";
public double divide(double a, double b) { return a/b; } public int stringJoint(String s) { return Integer.parseInt(s); } public int getArrayElement(int index) { return array[index]; } public char getCharNullString(int index) { return a.charAt(index); } public char getCharString(int index) { return b.charAt(index); } }
Test Cases:
class ExceptionTest
UsingException ee = new UsingException();
@Test void testDivide() { Assertions.assertThrows(ArithmeticException.class, () -> ee.divide(5, 0)); }
@Test void testStringJoint() { Assertions.assertThrows(NumberFormatException.class, () -> ee.stringJoint("abcd")); }
@Test void testGetArrayElement() { Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, () -> ee.getArrayElement(10)); }
@Test void testGetCharNullString() { Assertions.assertThrows(NullPointerException.class, () -> ee.getCharNullString(1)); }
@Test void testGetCharString() { Assertions.assertThrows(StringIndexOutOfBoundsException.class, () -> ee.getCharString(50)); }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started