0
0
JUnittesting~10 mins

verify() for interaction verification in JUnit - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to verify that the method save() was called exactly once on the mock object.

JUnit
verify(mockObject).[1]();
Drag options to blanks, or click blank then click option'
Aexecute
Bstart
Crun
Dsave
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that was never called on the mock.
Forgetting to call the method inside verify().
2fill in blank
medium

Complete the code to verify that the method delete() was never called on the mock object.

JUnit
verify(mockObject, [1]()).delete();
Drag options to blanks, or click blank then click option'
Anever
BatMost
Ctimes
DatLeastOnce
Attempts:
3 left
💡 Hint
Common Mistakes
Using times(0) instead of never() (both work but never() is clearer).
Using atLeastOnce() which means the method was called at least once.
3fill in blank
hard

Fix the error in the code to verify that update() was called exactly twice on the mock object.

JUnit
verify(mockObject, [1](2)).update();
Drag options to blanks, or click blank then click option'
AatLeast
Bnever
Ctimes
DatMost
Attempts:
3 left
💡 Hint
Common Mistakes
Using never() which means zero calls.
Using atLeast(2) which means two or more calls.
4fill in blank
hard

Fill both blanks to verify that the method process() was called at least once but no more than three times on the mock object.

JUnit
verify(mockObject, [1](1)).process();
verify(mockObject, [2](3)).process();
Drag options to blanks, or click blank then click option'
AatLeast
Btimes
CatMost
Dnever
Attempts:
3 left
💡 Hint
Common Mistakes
Using times() for range checks instead of atLeast and atMost.
Using never() which means zero calls.
5fill in blank
hard

Fill all three blanks to demonstrate verifications that the method calculate() was called exactly once, never called, and at least twice.

JUnit
verify(mockObject, [1](1)).calculate();
verify(mockObject, [2]()).calculate();
verify(mockObject, [3](2)).calculate();
Drag options to blanks, or click blank then click option'
Atimes
Bnever
CatLeast
DatMost
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up atMost and atLeast.
Using times() without a number.