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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!