@Test public void must_return_status_503_when_site_is_not_available() throws Exception { when(siteProvider.isSiteAvailable()).thenReturn(false); final Status result = underTest.process(request); final File actualFile = new File("target/test-artifacts/response.txt"); final File expectedFile = new File("src/test/resources/expected-results/response.txt"); actualFile.getParentFile().mkdirs(); Files.write(responseHolder.get(), actualFile); assertThat(result, is(Status.BREAK)); FileComparisonUtils.assertSameContents(expectedFile, actualFile); } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @BeforeMethod public void setupFixture() throws Exception { MockResponseBuilder.setCurrentTime(currentTime); resourceFile = mock(ResourceFile.class); when(resourceFile.asBytes()).thenReturn("FILE CONTENT".getBytes()); when(resourceFile.getMimeType()).thenReturn("text/plain"); when(resourceFile.getLatestModificationTime()).thenReturn(resourceLatestModifiedTime); headers = new HashMap<>(); request = mock(Request.class); when(request.getHeader(anyString())).thenAnswer(new Answer<String>() { @Override @Nonnull public String answer (final @Nonnull InvocationOnMock invocation) throws NotFoundException { final String name = (String)invocation.getArguments()[0]; return NotFoundException.throwWhenNull(headers.get(name), "Not found " + name); } }); underTest = new MockResponseHolder(); }