@Test(expected = ConfigurationModeNotFoundException.class) public void env_no_mode() throws IOException { // Renderer when(httpRendererService.getRenderer(ConfigurationSet.class, MODE)) .thenThrow(new RendererNotFoundException(ConfigurationSet.class, MODE)); // Call MockHttpServletResponse response = new MockHttpServletResponse(); get.env(APP_NAME, VERSION, ENV, MODE, VARIANT, response); }
@Test public void env() throws IOException { // Renderer @SuppressWarnings("unchecked") HttpRenderer<ConfigurationSet> renderer = mock(HttpRenderer.class); when(httpRendererService.getRenderer(ConfigurationSet.class, MODE)).thenReturn(renderer); // Call MockHttpServletResponse response = new MockHttpServletResponse(); get.env(APP_NAME, VERSION, ENV, MODE, VARIANT, response); // Checks the render call verify(renderer, times(1)).renderer(any(ConfigurationSet.class), eq(VARIANT), same(response)); }
@Test public void onException() { // Mock: request HttpServletRequest request = mock(HttpServletRequest.class); // Mock: error handler when(errorHandler.handleError( any(HttpServletRequest.class), any(Locale.class), any(Exception.class))) .thenReturn(new ErrorMessage("xxx", "Error message")); // Call ResponseEntity<String> entity = get.onException(request, Locale.ENGLISH, new ApplicationNotFoundException(APP)); assertNotNull(entity); assertEquals( "An error has occurred.\nMessage: Error message\nReference: xxx", entity.getBody()); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); }
@Test public void key() { when(service.getKey(APP_NAME, VERSION, ENV, KEY)).thenReturn(VALUE); String value = get.key(APP_NAME, VERSION, ENV, KEY); assertEquals(VALUE, value); }
@Test public void version() { when(service.getVersion()).thenReturn("VX"); String value = get.version(); assertEquals("VX", value); }