class 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);
    }

}

class ZwitscherControllerTest {

    @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());
    }

}