Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the following method, and I need to review a tests methods; however, when running coverage gives me a warning one of the two

I have the following method, and I need to review a tests methods; however, when running coverage gives me a warning one of the two branches missed

here

&& gender == that.gender

&& Objects.equals(name, that.name);

Here is code

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (!(obj instanceof Person))

return false;

Person that = (Person) obj;

return Objects.equals(birthday, that.birthday)

&& gender == that.gender

&& Objects.equals(name, that.name);

}

@Before

public void setUp() throws Exception

{

System.setOut(new PrintStream(outContent));

fred = new Person(

"Fred",

IsoChronology.INSTANCE.date(1980, 6, 2..d@example.com");

jane = new Person(

"Jane",

IsoChronology.INSTANCE.date(1990, 7, 15),

Person.Sex.FEMALE

);

}

@Test

public void testEqualsFredFred2() {

Person fred2 = new Person(

"Fred",

IsoChronology.INSTANCE.date(1980, 6, 20),

Person.Sex.MALE

);

assertEquals(fred,fred2);

}

@Test

public void testEqualsFredFred() {

assertEquals(fred,fred);

}

@Test

public void testEqualsFredNull() {

assertNotEquals(fred,null);

}

@Test

public void testEqualsFredHello() {

assertNotEquals(fred,"Hello");

}

@Test

public void testEqualsFredJane() {

assertNotEquals(fred,jane);

}

@Test

public void testEqualsBirthdaysNotEquals() {

Person fred2 = new Person(

"Fred",

IsoChronology.INSTANCE.date(1990, 7, 15),

Person.Sex.FEMALE

);

assertNotEquals(fred,fred2);

}

@Test

public void testEqualsGendersNotEquals() {

Person fred2 = new Person(

"Fred",

IsoChronology.INSTANCE.date(1980, 6, 20),

Person.Sex.FEMALE

);

assertNotEquals(fred,fred2);

}

Step by Step Solution

3.39 Rating (155 Votes )

There are 3 Steps involved in it

Step: 1

The warning youre receiving about one of the branches being missed in the coverage is likely re... 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

Elements Of Chemical Reaction Engineering

Authors: H. Fogler

6th Edition

013548622X, 978-0135486221

More Books

Students also viewed these Programming questions