0
0
JUnittesting~10 mins

Argument matchers (any, eq) 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 a method call with any String argument.

JUnit
verify(mockObject).someMethod([1]());
Drag options to blanks, or click blank then click option'
AanyString
Beq
CanyInt
DisNull
Attempts:
3 left
💡 Hint
Common Mistakes
Using eq without specifying the exact argument.
Using anyInt() which matches integers, not strings.
2fill in blank
medium

Complete the code to verify a method call with an exact argument "test".

JUnit
verify(mockObject).someMethod([1]("test"));
Drag options to blanks, or click blank then click option'
Aany
BanyString
Ceq
DisNull
Attempts:
3 left
💡 Hint
Common Mistakes
Using anyString() which matches any string, not the exact one.
Using any() without specifying the type.
3fill in blank
hard

Fix the error in the verification by choosing the correct matcher for any Integer argument.

JUnit
verify(mockObject).someMethod([1]());
Drag options to blanks, or click blank then click option'
Aeq
BanyInt
CanyString
DanyDouble
Attempts:
3 left
💡 Hint
Common Mistakes
Using anyString() which matches strings, not integers.
Using eq() without specifying the exact integer.
4fill in blank
hard

Fill both blanks to verify a method called with exact String "hello" and any Integer argument.

JUnit
verify(mockObject).someMethod([1]("hello"), [2]());
Drag options to blanks, or click blank then click option'
Aeq
BanyInt
CanyString
DisNull
Attempts:
3 left
💡 Hint
Common Mistakes
Using anyString() for the first argument instead of eq().
Using eq() for the second argument without specifying a value.
5fill in blank
hard

Fill all three blanks to verify a method called with any String, exact Integer 5, and any Boolean argument.

JUnit
verify(mockObject).someMethod([1](), [2](5), [3]());
Drag options to blanks, or click blank then click option'
AanyString
Beq
CanyBoolean
DanyInt
Attempts:
3 left
💡 Hint
Common Mistakes
Using anyInt() instead of eq(5) for the exact integer.
Using eq() without argument for the Boolean.