Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

The amount of work I am asked to do is reasonable.

Answered: 1 week ago

Question

The company encourages a balance between work and personal life.

Answered: 1 week ago