### Question:
ReverseBuildTriggerConverter extends SingleTypedConverter<ReverseBuildTrigger> { @Override public boolean convert(ConverterRequest request, ConverterResult result, Object target) { ReverseBuildTrigger reverseBuildTrigger = (ReverseBuildTrigger) target; String upstreamProjects = reverseBuildTrigger.getUpstreamProjects(); Result threshold = reverseBuildTrigger.getThreshold(); ModelASTTrigger modelASTTrigger = new ModelASTTrigger( this ); modelASTTrigger.setName( "upstream" ); List<ModelASTMethodArg> args = new ArrayList<>( ); { ModelASTKeyValueOrMethodCallPair projects = new ModelASTKeyValueOrMethodCallPair( this ); ModelASTKey key = new ModelASTKey( this ); key.setKey( "upstreamProjects" ); projects.setKey( key ); projects.setValue( ModelASTValue.fromConstant( upstreamProjects, this ) ); args.add( projects ); } if(threshold!=null) { ModelASTKeyValueOrMethodCallPair thresholdArg = new ModelASTKeyValueOrMethodCallPair(this); ModelASTKey key = new ModelASTKey(this); key.setKey( "threshold" ); thresholdArg.setKey( key ); thresholdArg.setValue( ModelASTValue.fromGString( threshold.getClass().getName() + "." + threshold.toString(), this ) ); args.add( thresholdArg ); } modelASTTrigger.setArgs( args ); ModelASTUtils.addTrigger( result.getModelASTPipelineDef(), modelASTTrigger ); return true; }  @Override boolean convert(ConverterRequest request, ConverterResult result, Object target);  }### Answer:
@Test public void simpletest() throws Exception { String projectName = Long.toString( System.currentTimeMillis() ); FreeStyleProject p = j.createFreeStyleProject( projectName ); ReverseBuildTrigger trigger = new ReverseBuildTrigger( "foo,bar" ); trigger.setThreshold( null ); p.addTrigger( trigger ); ReverseBuildTriggerConverter converter = j.jenkins .getExtensionList( ReverseBuildTriggerConverter.class ).get( 0 ); assertTrue(converter.canConvert( trigger ) ); ConverterResult result = new ConverterResult(); converter.convert( new ConverterRequest().job( p ), result, trigger ); List<ModelASTTrigger> triggers = result.getModelASTPipelineDef().getTriggers().getTriggers(); assertEquals( 1, triggers.size() ); String groovy = result.getModelASTPipelineDef().getTriggers().toGroovy(); System.out.println( groovy ); assertThat( groovy, containsString( "foo,bar" ) ); assertThat( groovy, containsString( "upstreamProjects" ) ); }
@Test public void simpletestwiththreshold() throws Exception { String projectName = Long.toString( System.currentTimeMillis() ); FreeStyleProject p = j.createFreeStyleProject( projectName ); ReverseBuildTrigger trigger = new ReverseBuildTrigger( "foo,bar" ); trigger.setThreshold( Result.FAILURE ); p.addTrigger( trigger ); ReverseBuildTriggerConverter converter = j.jenkins .getExtensionList( ReverseBuildTriggerConverter.class ).get( 0 ); assertTrue(converter.canConvert( trigger ) ); ConverterResult result = new ConverterResult(); converter.convert( new ConverterRequest().job( p ), result, trigger ); List<ModelASTTrigger> triggers = result.getModelASTPipelineDef().getTriggers().getTriggers(); assertEquals( 1, triggers.size() ); String groovy = result.getModelASTPipelineDef().getTriggers().toGroovy(); System.out.println( groovy ); assertThat( groovy, containsString( "foo,bar" ) ); assertThat( groovy, containsString( "upstreamProjects" ) ); assertThat( groovy, containsString( "threshold" ) ); assertThat( groovy, containsString( "hudson.model.Result.FAILURE" ) ); }