Question: I expect you to TDD this assignment - no line of code written until a failing test is written, You will have a ConsoleThread class

I expect you to TDD this assignment - no line of code written until a failing test is written,

You will have a ConsoleThread class with 2 methods:

public void start(int times) - sysout "Starting..." + waitManySeconds(times)

private void waitManySeconds(int times) - wait 1 second and sysout "Waited x second" after each wait - where x is the number of seconds waited.

SystemWrapper and ThreadWrapper should be class fields for ConsoleThread - not method parameters. So instead of this main method:

ConsoleThread consoleThread = new ConsoleThread();

consoleThread.start(new SystemWrapper(), new ThreadWrapper());

Instead you want this in your main method:

ConsoleThread consoleThread = new ConsoleThread(new SystemWrapper(), new ThreadWrapper());

consoleThread.start(5);

Hints:

Start with a single test case to verify that systemWrapper.println("Starting...") happened.

Create your mocks in your setUp() method - then create the ConsoleThread with the mocked wrappers.

Continue to a test that checks that you can wait 1 second and print once.

Remember the boundaries.

If you want to verify that nothing happened to a mock:

Mockito.verifyZeroInteractions(threadWrapper);

If you want to verify that nothing happened after the first "Starting..." sysout:

Mockito.verifyNoMoreInteractions(systemWrapper);

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!