Question: Need assistance in changing HelloWorld.java and the one incorrect test so that tests all pass. package hw; public class HelloWorld { public String getMessage() {

Need assistance in changing HelloWorld.java and the one incorrect test so that tests all pass.

package hw;
public class HelloWorld {
public String getMessage() {
return "hello world";
}
public int getYear() {
return 2020;
}
}
package hw;
import java.util.Arrays;
public class Main {
public static void main(final String[] args) {
System.out.println("args = " + Arrays.asList(args));
final var instance = new HelloWorld();
System.out.println(instance.getMessage());
System.out.println(instance.getYear());
System.out.println("bye for now");
}
}
package hw;
import static org.junit.Assert.*;
import java.util.Arrays;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TestHelloWorld {
private HelloWorld fixture;
@Before
public void setUp() throws Exception {
fixture = new HelloWorld();
}
@After
public void tearDown() throws Exception {
fixture = null;
}
@Test
public void initialization() { // this test is OK as-is, it should pass with no problem
assertNotNull(fixture);
}
@Test
public void getMessage() { // this test is OK as-is, it should pass with no problem
assertNotNull(fixture);
assertEquals("hello world", fixture.getMessage());
}
@Test
public void getYear() { // this test is OK, fix HelloWorld.java to make it pass!
assertNotNull(fixture);
assertEquals(2021, fixture.getYear());
}
@Test
public void getMessageInList() { // this test is broken - fix it!
var list = Arrays.asList(fixture);
assertEquals("hello world", list.get(1).getMessage());
}
@Test
public void getYearInList() { // this test is broken - fix it!
var list = Arrays.asList(fixture);
assertEquals(2021, list.get(1).getYear());
}
}

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!