### Question:
ContentViewerHelper implements IContentViewerHelper { @Override public PublicContentAuthorizationInfo getAuthorizationInfo(String contentId, RequestContext reqCtx) throws ApsSystemException { PublicContentAuthorizationInfo authInfo = null; try { Widget widget = (Widget) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET); contentId = this.extractContentId(contentId, widget.getConfig(), reqCtx); if (null == contentId) { logger.info("Null contentId"); return null; } authInfo = this.getContentAuthorizationHelper().getAuthorizationInfo(contentId, true); if (null == authInfo) { logger.info("Null authorization info by content '" + contentId + "'"); } } catch (Throwable t) { logger.error("Error extracting content authorization info by content {}", contentId, t); throw new ApsSystemException("Error extracting content authorization info by content '" + contentId + "'", t); } return authInfo; }  @Override String getRenderedContent(String contentId, String modelId, RequestContext reqCtx); @Override String getRenderedContent(String contentId, String modelId, boolean publishExtraTitle, RequestContext reqCtx); @Override ContentRenderizationInfo getRenderizationInfo(String contentId, String modelId, boolean publishExtraTitle, RequestContext reqCtx); @Override PublicContentAuthorizationInfo getAuthorizationInfo(String contentId, RequestContext reqCtx); void setContentModelManager(IContentModelManager contentModelManager); void setContentManager(IContentManager contentManager); void setContentDispenser(IContentDispenser contentDispenser); void setContentAuthorizationHelper(IContentAuthorizationHelper contentAuthorizationHelper);  }### Answer:
@Test public void getAuthorizationInfo() throws Exception { PublicContentAuthorizationInfo pcaiMock = Mockito.mock(PublicContentAuthorizationInfo.class); when(this.contentAuthorizationHelper.getAuthorizationInfo("EVN100", true)).thenReturn(pcaiMock); Widget currentWidget = new Widget(); ApsProperties properties = new ApsProperties(); properties.setProperty("contentId", "EVN100"); currentWidget.setConfig(properties); when(this.reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET)).thenReturn(currentWidget); PublicContentAuthorizationInfo pcai = contentViewerHelper.getAuthorizationInfo(null, reqCtx); Assert.assertNotNull(pcai); Mockito.verify(reqCtx, Mockito.times(0)).getRequest(); }
@Test public void getNullAuthorizationInfo() throws Exception { HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); when(mockRequest.getParameter(SystemConstants.K_CONTENT_ID_PARAM)).thenReturn(null); when(this.reqCtx.getRequest()).thenReturn(mockRequest); Widget currentWidget = new Widget(); ApsProperties properties = new ApsProperties(); properties.setProperty("wrongParam", "xyz"); currentWidget.setConfig(properties); when(this.reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET)).thenReturn(currentWidget); PublicContentAuthorizationInfo pcai = contentViewerHelper.getAuthorizationInfo(null, reqCtx); Assert.assertNull(pcai); Mockito.verify(reqCtx, Mockito.times(1)).getRequest(); Mockito.verify(contentAuthorizationHelper, Mockito.times(0)).getAuthorizationInfo(Mockito.anyString(), Mockito.anyBoolean()); }
@Test(expected = ApsSystemException.class) public void getAuthorizationInfoWithError() throws Exception { HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); when(mockRequest.getParameter(SystemConstants.K_CONTENT_ID_PARAM)).thenReturn("ART123"); when(this.reqCtx.getRequest()).thenReturn(mockRequest); Widget currentWidget = new Widget(); currentWidget.setConfig(new ApsProperties()); when(this.reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET)).thenReturn(currentWidget); Mockito.doThrow(RuntimeException.class).when(this.contentAuthorizationHelper).getAuthorizationInfo("ART123", true); try { contentViewerHelper.getAuthorizationInfo(null, reqCtx); Assert.fail(); } catch (Exception e) { Mockito.verify(reqCtx, Mockito.times(1)).getRequest(); throw e; } }