Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to stub the method call using Mockito.
JUnit
when(mockedList.[1]()).thenReturn("hello");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to stub void methods like clear() or add() which do not return values.
Using size() which returns an int, not a String.
✗ Incorrect
The get(0) method is stubbed to return "hello" when called on the mocked list.
2fill in blank
mediumComplete the code to stub the size() method to return 5.
JUnit
when(mockedList.[1]()).thenReturn(5);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting parentheses in method call.
Using incorrect method names like size or length().
✗ Incorrect
The size() method is stubbed correctly with parentheses to return 5.
3fill in blank
hardFix the error in the stubbing code below.
JUnit
when(mockedList.get([1])).thenReturn("world");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of an integer index.
Using null or negative index values.
✗ Incorrect
The index argument must be an integer, so 0 is correct. Using a string or null causes errors.
4fill in blank
hardFill both blanks to stub mockedMap.get() to return 10 when key "score" is used.
JUnit
when(mockedMap.[1]([2])).thenReturn(10);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
put or remove which are void or different methods.Not passing the key as a string.
✗ Incorrect
The get method is stubbed with the key "score" to return 10.
5fill in blank
hardFill all three blanks to stub mockedService.calculate() to return 42 when called with 5.
JUnit
when(mockedService.[1]([2])).thenReturn([3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names like
compute.Passing arguments or return values as strings instead of numbers.
✗ Incorrect
The calculate method is stubbed with argument 5 to return 42.