Complete the code to create a stub that returns a fixed value.
StubClass stub = new StubClass() {
@Override
public int getValue() {
return [1];
}
};The stub method getValue() should return an integer. Returning 10 is correct.
Complete the code to stub a method that returns a fixed string.
StubClass stub = new StubClass() {
@Override
public String getName() {
return [1];
}
};The stub method getName() returns a String. Returning "TestUser" is correct.
Fix the error in the stub method to return the correct boolean value.
StubClass stub = new StubClass() {
@Override
public boolean isAvailable() {
return [1];
}
};The method isAvailable() returns a boolean. The correct return is the boolean literal true, not a string or number.
Fill both blanks to stub a method that returns a list with one fixed element.
StubClass stub = new StubClass() {
@Override
public List<String> getItems() {
return [1];
}
};
List<String> expected = new ArrayList<>();
expected.[2]("item1");remove or clear instead of add.The stub returns a new empty list (new ArrayList<>()), then we add "item1" to the expected list using add.
Fill all three blanks to stub a method that returns a map with one key-value pair.
StubClass stub = new StubClass() {
@Override
public Map<String, Integer> getScores() {
Map<String, Integer> map = [1];
map.[2]([3], 100);
return map;
}
};clear instead of put.The stub creates a new map with new HashMap<>(), adds a key-value pair using put with key "player1" and value 100, then returns the map.