### Question:
DefaultBuildController implements BuildController { protected boolean shouldBuild( BuildContext context ) throws TaskExecutionException { BuildDefinition buildDefinition = context.getBuildDefinition(); if ( buildDefinition.isAlwaysBuild() ) { log.info( "AlwaysBuild configured, building" ); return true; } if ( context.getOldBuildResult() == null ) { log.info( "The project has never been built with the current build definition, building" ); return true; } Project project = context.getProject(); if ( project.getOldState() == ContinuumProjectState.ERROR || context.getOldBuildResult().getState() == ContinuumProjectState.ERROR ) { log.info( "Latest state was 'ERROR', building" ); return true; } if ( context.getBuildTrigger().getTrigger() == ContinuumProjectState.TRIGGER_FORCED ) { log.info( "The project build is forced, building" ); return true; } boolean shouldBuild = false; boolean allChangesUnknown = true; if ( project.getOldState() != ContinuumProjectState.NEW && project.getOldState() != ContinuumProjectState.CHECKEDOUT && context.getBuildTrigger().getTrigger() != ContinuumProjectState.TRIGGER_FORCED && project.getState() != ContinuumProjectState.NEW && project.getState() != ContinuumProjectState.CHECKEDOUT ) { if ( context.getScmResult() != null ) { allChangesUnknown = checkAllChangesUnknown( context.getScmResult().getChanges() ); } if ( allChangesUnknown ) { if ( context.getScmResult() != null && !context.getScmResult().getChanges().isEmpty() ) { log.info( "The project was not built because all changes are unknown (maybe local modifications or ignored files not defined in your SCM tool." ); } else { log.info( "The project was not built because no changes were detected in sources since the last build." ); } } if ( context.getModifiedDependencies() != null && !context.getModifiedDependencies().isEmpty() ) { log.info( "Found dependencies changes, building" ); shouldBuild = true; } } if ( !shouldBuild && ( ( !allChangesUnknown && context.getScmResult() != null && !context.getScmResult().getChanges().isEmpty() ) || project.getExecutorId().equals( ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR ) ) ) { try { ContinuumBuildExecutor executor = buildExecutorManager.getBuildExecutor( project.getExecutorId() ); Map<String, Object> actionContext = context.getActionContext(); List<Project> projectsWithCommonScmRoot = AbstractContinuumAction.getListOfProjectsInGroupWithCommonScmRoot( actionContext ); String projectScmRootUrl = AbstractContinuumAction.getProjectScmRootUrl( actionContext, project.getScmUrl() ); if ( executor == null ) { log.warn( "No continuum build executor found for project " + project.getId() + " with executor '" + project.getExecutorId() + "'" ); } else if ( context.getScmResult() != null ) { shouldBuild = executor.shouldBuild( context.getScmResult().getChanges(), project, workingDirectoryService.getWorkingDirectory( project, projectScmRootUrl, projectsWithCommonScmRoot ), context.getBuildDefinition() ); } } catch ( Exception e ) { updateBuildResult( context, ContinuumUtils.throwableToString( e ) ); throw new TaskExecutionException( "Can't determine if the project should build or not", e ); } } if ( shouldBuild ) { log.info( "Changes found in the current project, building" ); } else { project.setState( project.getOldState() ); project.setOldState( 0 ); try { projectDao.updateProject( project ); } catch ( ContinuumStoreException e ) { throw new TaskExecutionException( "Error storing project", e ); } log.info( "No changes in the current project, not building" ); } return shouldBuild; }  void build( int projectId, int buildDefinitionId, BuildTrigger buildTrigger, ScmResult scmResult );  }### Answer:
@Test public void testWithNewBuildDefinition() throws Exception { BuildContext context = getScheduledBuildContext(); assertNull( context.getOldBuildResult() ); assertTrue( controller.shouldBuild( context ) ); }