### Question:
BuildResultAction extends AbstractBuildAction { public String execute() throws ContinuumException, IOException, BuildManagerException { try { checkViewProjectGroupAuthorization( getProjectGroupName() ); } catch ( AuthorizationRequiredException e ) { return REQUIRES_AUTHORIZATION; } project = getContinuum().getProject( getProjectId() ); ConfigurationService configuration = getContinuum().getConfiguration(); buildResult = getContinuum().getBuildResult( getBuildId() ); boolean runningOnAgent = false; if ( configuration.isDistributedBuildEnabled() ) { try { int buildDefinitionId = buildResult.getBuildDefinition().getId(); runningOnAgent = buildResult.getState() == ContinuumProjectState.BUILDING && distributedBuildManager.getCurrentRun( getProjectId(), buildDefinitionId ).getBuildResultId() == getBuildId(); } catch ( ContinuumException e ) { log.debug( "running distributed build not found: {}", e.getMessage() ); } } if ( runningOnAgent ) { Map<String, Object> map = distributedBuildManager.getBuildResult( project.getId() ); if ( map == null ) { projectGroupId = project.getProjectGroup().getId(); return ERROR; } if ( map.size() > 0 ) { buildResult = ContinuumBuildConstant.getBuildResult( map, null ); buildOutput = ContinuumBuildConstant.getBuildOutput( map ); if ( ServletActionContext.getRequest() != null ) { state = StateGenerator.generate( buildResult.getState(), ServletActionContext.getRequest().getContextPath() ); } } changeSet = null; hasSurefireResults = false; this.setCanDelete( false ); } else { buildResult = getContinuum().getBuildResult( getBuildId() ); File[] testReports = null; try { File surefireReportsDirectory = configuration.getTestReportsDirectory( buildId, getProjectId() ); testReports = surefireReportsDirectory.listFiles(); } catch ( ConfigurationException ce ) { log.warn( "failed to access test reports", ce ); } hasSurefireResults = testReports != null && testReports.length > 0; changeSet = getContinuum().getChangesSinceLastSuccess( getProjectId(), getBuildId() ); try { buildOutput = getBuildOutputText(); } catch ( ConfigurationException ce ) { log.warn( "failed to access build output", ce ); } if ( ServletActionContext.getRequest() != null ) { state = StateGenerator.generate( buildResult.getState(), ServletActionContext.getRequest().getContextPath() ); } this.setCanDelete( this.canRemoveBuildResult( buildResult ) ); } return SUCCESS; }  String execute(); String remove(); String buildLogAsText(); InputStream getBuildOutputInputStream(); int getBuildId(); void setBuildId( int buildId ); Project getProject(); BuildResult getBuildResult(); List<ChangeSet> getChangesSinceLastSuccess(); boolean isHasSurefireResults(); void setHasSurefireResults( boolean hasSurefireResults ); String getBuildOutput(); String getState(); String getProjectGroupName(); int getProjectGroupId(); void setDistributedBuildManager( DistributedBuildManager distributedBuildManager ); boolean isBuildInProgress(); boolean isBuildSuccessful(); boolean isShowBuildNumber(); boolean isShowBuildError();  }### Answer:
@Test public void testSuccessfulWhenTestDirThrows() throws Exception { when( configurationService.getTestReportsDirectory( anyInt(), anyInt() ) ).thenThrow( new ConfigurationException( "failed creating dir" ) ); when( configurationService.getBuildOutputFile( anyInt(), anyInt() ) ).thenReturn( new File( "non-existent" ) ); assertEquals( Action.SUCCESS, action.execute() ); }
@Test public void testSuccessfulWhenBuildOutputDirThrows() throws Exception { when( configurationService.getTestReportsDirectory( anyInt(), anyInt() ) ).thenReturn( new File( "non-existent" ) ); when( configurationService.getBuildOutputFile( anyInt(), anyInt() ) ).thenThrow( new ConfigurationException( "failed creating dir" ) ); assertEquals( Action.SUCCESS, action.execute() ); }