0
0
JUnittesting~10 mins

Dummy objects 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 create a dummy object for the Logger interface.

JUnit
Logger dummyLogger = [1];
Drag options to blanks, or click blank then click option'
ALogger()
Bnew Logger()
Cdummy(Logger.class)
Dmock(Logger.class)
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to instantiate an interface directly with new.
Using a non-existent method like dummy().
2fill in blank
medium

Complete the code to create a dummy List object using Mockito.

JUnit
List<String> dummyList = [1];
Drag options to blanks, or click blank then click option'
Amock(List.class)
BList()
Cdummy(List.class)
Dnew ArrayList<>()
Attempts:
3 left
💡 Hint
Common Mistakes
Using new ArrayList() which is a real object, not a dummy.
Trying to call dummy() which does not exist.
3fill in blank
hard

Fix the error in the dummy object creation for the Service interface.

JUnit
Service dummyService = [1];
Drag options to blanks, or click blank then click option'
Amock(Service.class)
Bnew Service()
Cdummy(Service.class)
DService()
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to instantiate interface with new.
Using a non-existent dummy() method.
4fill in blank
hard

Fill both blanks to create a dummy object and verify it was used once.

JUnit
Repository dummyRepo = [1];
verify(dummyRepo).[2]();
Drag options to blanks, or click blank then click option'
Amock(Repository.class)
Bsave
Cdelete
Dnew Repository()
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to instantiate interface with new.
Verifying a method that was not called.
5fill in blank
hard

Fill all three blanks to create a dummy object, stub a method, and assert the stubbed value.

JUnit
Calculator dummyCalc = [1];
when(dummyCalc.[2](5, 3)).thenReturn([3]);
assertEquals(8, dummyCalc.add(5, 3));
Drag options to blanks, or click blank then click option'
Amock(Calculator.class)
Badd
C8
Dcalculate
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names in stubbing.
Not stubbing the method before asserting.