Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to verify that the method process() was called exactly once.
JUnit
verify(mockObject, [1]).process(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
never() will check that the method was never called.Using
atLeast(1) allows one or more calls, not exactly one.✗ Incorrect
Using
times(1) verifies that the method was called exactly once.2fill in blank
mediumComplete the code to verify that the method save() was never called.
JUnit
verify(mockObject, [1]).save(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
times(0) is similar but never() is clearer.Using
atLeast(1) would allow calls, which is incorrect here.✗ Incorrect
Using
never() verifies that the method was not called at all.3fill in blank
hardFix the error in the verification to check that update() was called at least twice.
JUnit
verify(mockObject, [1]).update(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
times(2) checks for exactly two calls, not at least two.Using
never() means no calls, which is wrong here.✗ Incorrect
Using
atLeast(2) verifies that the method was called two or more times.4fill in blank
hardFill both blanks to verify that delete() was called exactly three times and create() was never called.
JUnit
verify(mockObject, [1]).delete(); verify(mockObject, [2]).create();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up
never() and times(0).Using
atLeast(1) instead of times(3) for exact calls.✗ Incorrect
Use
times(3) to check exactly three calls and never() to check zero calls.5fill in blank
hardFill all three blanks to verify that start() was called at least once, stop() was called exactly twice, and reset() was never called.
JUnit
verify(mockObject, [1]).start(); verify(mockObject, [2]).stop(); verify(mockObject, [3]).reset();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
times(1) instead of atLeast(1) for the start() method.Confusing
never() with times(0).✗ Incorrect
Use
atLeast(1) for one or more calls, times(2) for exactly two calls, and never() for zero calls.