### Question:
DefaultBuildDefinitionService implements BuildDefinitionService, Initializable { public BuildDefinitionTemplate addBuildDefinitionTemplate( BuildDefinitionTemplate buildDefinitionTemplate ) throws BuildDefinitionServiceException { try { if ( !hasDuplicateTemplateName( buildDefinitionTemplate ) ) { return buildDefinitionTemplateDao.addBuildDefinitionTemplate( buildDefinitionTemplate ); } } catch ( ContinuumStoreException e ) { throw new BuildDefinitionServiceException( e.getMessage(), e ); } return null; }  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 testAddBuildDefinitionTemplate() throws Exception { BuildDefinitionTemplate template = new BuildDefinitionTemplate(); template.setName( "testTemplate" ); template = getBuildDefinitionService().addBuildDefinitionTemplate( template ); template = getBuildDefinitionService().getBuildDefinitionTemplate( template.getId() ); assertNotNull( template ); assertEquals( "testTemplate", template.getName() ); List<BuildDefinition> all = getBuildDefinitionService().getAllBuildDefinitions(); assertEquals( 5, all.size() ); BuildDefinition bd = getBuildDefinitionService().getDefaultMavenTwoBuildDefinitionTemplate().getBuildDefinitions().get( 0 ); template = getBuildDefinitionService().addBuildDefinitionInTemplate( template, bd, false ); assertEquals( true, getBuildDefinitionService().isBuildDefinitionInUse( bd ) ); assertEquals( 1, template.getBuildDefinitions().size() ); all = getBuildDefinitionService().getAllBuildDefinitions(); assertEquals( 5, all.size() ); template = getBuildDefinitionService().getBuildDefinitionTemplate( template.getId() ); template = getBuildDefinitionService().updateBuildDefinitionTemplate( template ); template = getBuildDefinitionService().removeBuildDefinitionFromTemplate( template, bd ); assertEquals( 0, template.getBuildDefinitions().size() ); all = getBuildDefinitionService().getAllBuildDefinitions(); assertEquals( 5, all.size() ); }
@Test public void testAddDuplicateBuildDefinitionTemplate() throws Exception { BuildDefinitionTemplate template = new BuildDefinitionTemplate(); template.setName( "test" ); template = getBuildDefinitionService().addBuildDefinitionTemplate( template ); assertNull( template ); }