### Question:
DefaultBuildDefinitionService implements BuildDefinitionService, Initializable { public void addTemplateInProject( int buildDefinitionTemplateId, Project project ) throws BuildDefinitionServiceException { try { BuildDefinitionTemplate template = getBuildDefinitionTemplate( buildDefinitionTemplateId ); if ( template.getBuildDefinitions().isEmpty() ) { return; } project = projectDao.getProjectWithBuildDetails( project.getId() ); for ( BuildDefinition bd : (List<BuildDefinition>) template.getBuildDefinitions() ) { bd = cloneBuildDefinition( bd ); bd.setTemplate( false ); bd = buildDefinitionDao.addBuildDefinition( bd ); project.addBuildDefinition( bd ); } projectDao.updateProject( project ); } catch ( ContinuumStoreException e ) { throw new BuildDefinitionServiceException( e.getMessage(), e ); } }  void initialize(); BuildDefinition getBuildDefinition( int buildDefinitionId ); BuildDefinition addBuildDefinition( BuildDefinition buildDefinition ); void removeBuildDefinition( BuildDefinition buildDefinition ); void updateBuildDefinition( BuildDefinition buildDefinition ); List<BuildDefinition> getAllBuildDefinitions(); List<BuildDefinition> getAllTemplates(); BuildDefinition cloneBuildDefinition( BuildDefinition buildDefinition ); boolean isBuildDefinitionInUse( BuildDefinition buildDefinition ); BuildDefinitionTemplate getContinuumDefaultWithType( String type ); BuildDefinitionTemplate getDefaultAntBuildDefinitionTemplate(); BuildDefinitionTemplate getDefaultMavenOneBuildDefinitionTemplate(); BuildDefinitionTemplate getDefaultMavenTwoBuildDefinitionTemplate(); BuildDefinitionTemplate getDefaultShellBuildDefinitionTemplate(); List<BuildDefinitionTemplate> getAllBuildDefinitionTemplate(); BuildDefinitionTemplate getBuildDefinitionTemplate( int id ); void removeBuildDefinitionTemplate( BuildDefinitionTemplate buildDefinitionTemplate ); BuildDefinitionTemplate updateBuildDefinitionTemplate( BuildDefinitionTemplate buildDefinitionTemplate ); BuildDefinitionTemplate addBuildDefinitionTemplate( BuildDefinitionTemplate buildDefinitionTemplate ); BuildDefinitionTemplate addBuildDefinitionInTemplate( BuildDefinitionTemplate buildDefinitionTemplate,
                                                                 BuildDefinition buildDefinition, boolean template ); BuildDefinitionTemplate removeBuildDefinitionFromTemplate( BuildDefinitionTemplate buildDefinitionTemplate,
                                                                      BuildDefinition buildDefinition ); void addTemplateInProject( int buildDefinitionTemplateId, Project project ); ProjectGroup addBuildDefinitionTemplateToProjectGroup( int projectGroupId, BuildDefinitionTemplate template ); List<BuildDefinitionTemplate> getBuildDefinitionTemplatesWithType( String type ); List<BuildDefinitionTemplate> getContinuumBuildDefinitionTemplates();  }### Answer:
@Test public void testAddTemplateInProject() throws Exception { try { List<BuildDefinitionTemplate> templates = getBuildDefinitionService().getAllBuildDefinitionTemplate(); assertEquals( 5, templates.size() ); assertEquals( 5, getBuildDefinitionService().getAllBuildDefinitions().size() ); getBuildDefinitionService().addTemplateInProject( buildDefinitionTemplate.getId(), project ); project = getProjectDao().getProjectWithAllDetails( project.getId() ); templates = getBuildDefinitionService().getAllBuildDefinitionTemplate(); assertEquals( 1, project.getBuildDefinitions().size() ); assertEquals( 5, templates.size() ); List<BuildDefinition> all = getBuildDefinitionService().getAllBuildDefinitions(); assertEquals( 6, all.size() ); getBuildDefinitionService().addTemplateInProject( buildDefinitionTemplate.getId(), project ); project = getProjectDao().getProjectWithAllDetails( project.getId() ); templates = getBuildDefinitionService().getAllBuildDefinitionTemplate(); assertEquals( 2, project.getBuildDefinitions().size() ); assertEquals( 5, templates.size() ); all = getBuildDefinitionService().getAllBuildDefinitions(); assertEquals( 7, all.size() ); } catch ( Exception e ) { logger.error( e.getMessage(), e ); throw e; } }