Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the list of files in the Calculator Package - . src Calculator Calculator.java test Calculator CalculatorTest.java Calculator.Calculator class is fully implemented and contains

Here is the list of files in the Calculator Package -
.
src
Calculator
Calculator.java
test
Calculator
CalculatorTest.java
Calculator.Calculator class is fully implemented and contains a list of methods for each basic arithmetic operation. The only method that is different from what youd expect is divide(), which throws an exception if someone tries to divide by zero.
This is interesting because when you write tests you will have to make sure your test tests the fact that exceptions are being thrown when expected and not being thrown when not expected.
Calculator.CalculatorTest class inside test/Calculator/CalculatorTest.java is empty. Lets talk about how to start writing this class.
In order to be able to write tests, you need to import a bunch of methods called assertions from a library called Junit. Here are some example assert methods -
assertEquals: takes two arguements, and checks if they are equal. If unequal, the test fails.
assertThrows: takes two arguements, the first being a class, and the second being a lambda expression.
You can get the class of an exception by using Exception.class, for example ArithmeticException.class or java.lang.ArithmeticException.class if youve not imported it.
The lambda expression should include the method call that should throw an exception. You can think of it as a small convinient try block, for example -

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

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

=+1. Describe the product range in the press sector!

Answered: 1 week ago

Question

Explain the nature of human resource management.

Answered: 1 week ago

Question

Write a note on Quality circles.

Answered: 1 week ago

Question

Describe how to measure the quality of work life.

Answered: 1 week ago

Question

=+ Are they breakable for any reason?

Answered: 1 week ago