HighlighterPageExtension extends SimplePageExtension { @Override public boolean isAvailable(@NotNull HttpServletRequest request) { final Long buildId; try { buildId = Long.valueOf(request.getParameter("buildId")); } catch (NumberFormatException e) { LOG.warning(String.format("'%s' is not a valid build id, highlighter extension won't be available", request.getParameter("buildId"))); return false; } final SBuild sBuild = sBuildServer.findBuildInstanceById(buildId); highlightDataModel = new HighlightDataModel(dataStoreServices.get(activeDataStoreName).loadData(sBuild)); return !highlightDataModel.getHighlightData().isEmpty(); } HighlighterPageExtension(@NotNull PagePlaces pagePlaces, @NotNull SBuildServer sBuildServer,
                                    EventDispatcher<BuildServerListener> eventDispatcher); @Override void fillModel(@NotNull Map<String, Object> model, @NotNull HttpServletRequest request); @Override boolean isAvailable(@NotNull HttpServletRequest request); void setActiveDataStoreName(String activeDataStoreName);  }
@Test public void testIsAvailable() throws Exception { when(dataStoreService.loadData(eq(sBuild))).thenReturn(highlightData); final boolean available = highlighterPageExtension.isAvailable(httpServletRequest); verify(sBuildServer).findBuildInstanceById(1234); verify(dataStoreService).loadData(eq(sBuild)); assertThat(available, is(true)); }
@Test public void testIsAvailable_not_available() throws Exception { when(dataStoreService.loadData(any(SBuild.class))).thenReturn(new ArrayList(0)); final boolean available = highlighterPageExtension.isAvailable(httpServletRequest); verify(sBuildServer).findBuildInstanceById(1234); verify(dataStoreService).loadData(eq(sBuild)); assertThat(available, is(false)); }
@Test public void testIsAvailable_not_available_nfe() throws Exception { when(httpServletRequest.getParameter(eq("buildId"))).thenReturn("abc"); final boolean available = highlighterPageExtension.isAvailable(httpServletRequest); verify(sBuildServer, never()).findBuildInstanceById(anyLong()); verify(dataStoreService, never()).loadData(any(SBuild.class)); assertThat(available, is(false)); }