Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need Java Assistance In Having The Test Below Run. Thank you package hw; public class HelloWorld { public String getMessage() { return hello world; }

Need Java Assistance In Having The Test Below Run. Thank you

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

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

Students also viewed these Databases questions