ZwitscherController { @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public HttpEntity<Collection<String>> tweets(@RequestParam(value = "q", required = false) String q) { Collection<String> tweets = repository.search(ofNullable(q).orElse(query), pageSize); return new ResponseEntity<>(tweets, HttpStatus.OK); } @Autowired  ZwitscherController(ZwitscherRepository repository); @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) HttpEntity<Collection<String>> tweets(@RequestParam(value = "q", required = false) String q); @Value("${tweet.query:cloudnativenerd}") void setQuery(String query); @Value("${tweet.pageSize:42}") void setPageSize(int pageSize);  }
@Test public void tweets() throws Exception { ZwitscherRepository repository = mock(ZwitscherRepository.class); ZwitscherController controller = new ZwitscherController(repository); controller.setQuery("cloudnativenerd"); controller.setPageSize(42); when(repository.search("cloudnativenerd", 42)).thenReturn(Collections.singleton("Hello Test.")); HttpEntity<Collection<String>> tweets = controller.tweets(null); assertFalse(tweets.getBody().isEmpty()); }