@Override public MetricsRepository load() { List<Metric> metrics = new ArrayList<>(); try { loadFromPaginatedWs(metrics); } catch (Exception e) { throw new IllegalStateException("Unable to load metrics", e); } return new MetricsRepository(metrics); }
@Before public void setUp() throws IOException { wsClient = mock(ScannerWsClient.class); WsTestUtil.mockReader(wsClient, WS_URL + "1", new StringReader(IOUtils.toString(this.getClass().getResourceAsStream("DefaultMetricsRepositoryLoaderTest/page1.json")))); WsTestUtil.mockReader(wsClient, WS_URL + "2", new StringReader(IOUtils.toString(this.getClass().getResourceAsStream("DefaultMetricsRepositoryLoaderTest/page2.json")))); metricsRepositoryLoader = new DefaultMetricsRepositoryLoader(wsClient); }
@Test public void testCloseError() throws IOException { Reader reader = mock(Reader.class); when(reader.read(any(char[].class), anyInt(), anyInt())).thenReturn(-1); doThrow(new IOException()).when(reader).close(); WsTestUtil.mockReader(wsClient, reader); exception.expect(IllegalStateException.class); metricsRepositoryLoader.load(); } }
@Test public void testIOError() throws IOException { Reader reader = mock(Reader.class); when(reader.read(any(char[].class), anyInt(), anyInt())).thenThrow(new IOException()); WsTestUtil.mockReader(wsClient, reader); exception.expect(IllegalStateException.class); metricsRepositoryLoader.load(); }
@Override public MetricsRepository load() { List<Metric> metrics = new ArrayList<>(); try { loadFromPaginatedWs(metrics); } catch (Exception e) { throw new IllegalStateException("Unable to load metrics", e); } return new MetricsRepository(metrics); }
@Test public void test() { MetricsRepository metricsRepository = metricsRepositoryLoader.load(); assertThat(metricsRepository.metrics()).hasSize(3); WsTestUtil.verifyCall(wsClient, WS_URL + "1"); WsTestUtil.verifyCall(wsClient, WS_URL + "2"); verifyNoMoreInteractions(wsClient); }