-3

I need to run a JUnit test on the below code:

Carl
  • 19
  • 5

1 Answers1

1

I'll work through one of your methods, the "happy-path" approach. It's up to you to test alternate examples, i.e. if ready is false and so on, but the basic structure is arrange, execute, verify, though since you're using mockito and multiple mocks and no test subject, I've added an initiate step just so you can see the additional mock you need to support your step, plus the test subject.

@Test
public void testdoGet() {
    //Initiate
    ReadyCheck readyCheck = new ReadyCheck();
    Writer writer = mock(Writer.class); //not sure which writer it is off the top of my head

    //Arange
    when(response.getWriter()).thenReturn(writer); //we pass the writer on the get
    when(response.getStatus()).thenReturn(HttpServletResponse.SC_OK); //we pass a status

    //Execute       
    readyCheck.doGet(request, response);

    //Verify
    verify(response, times(1)).setStatus(HttpServletResponse.SC_OK);
    verify(writer, times(1)).write("Ready!");
}
Compass
  • 5,867
  • 4
  • 30
  • 42