Here is a component that acceses an external API to get random English words:
@Component
public class WordRandomizer {
private RestTemplate restTemplate = new RestTemplate();
public String getRandomWord() {
// Accesses external API to get one random word
return restTemplate.getForObject("https://random-word-api.vercel.app/api?words=1", String[].class)[0];
}
public List<String> get3RandomWords() {
// Accesses external API to get 3 random words
return restTemplate.getForObject("https://random-word-api.vercel.app/api?words=3", List.class);
}
}
What values do the methods of wordRandomizer return in the test below?
@SpringBootTest
public class WordRandomizerTest {
@MockBean
public WordRandomizer wordRandomizer;
@Test
void shouldReturnDefaultValues() {
var randomWordsList1 = wordRandomizer.get3RandomWords();
Mockito.when(wordRandomizer.get3RandomWords()).thenReturn(List.of("mock1", "mock2", "mock3"));
var randomWordsList2 = wordRandomizer.get3RandomWords();
String randomWord = wordRandomizer.getRandomWord();
System.out.println();
}
}
Match each variable name with its value.