### Question:
RequiredResourcesPropertyConverter extends SingleTypedConverter<RequiredResourcesProperty> { @Override public boolean convert(ConverterRequest request, ConverterResult result, Object target) { RequiredResourcesProperty requiredResourcesProperty = (RequiredResourcesProperty) target; ModelASTOption option = new ModelASTOption( this ); option.setName( "lock" ); List<ModelASTMethodArg> lockArgs = new ArrayList<>(); if( StringUtils.isNotBlank(requiredResourcesProperty.getLabelName())){ lockArgs.add( buildKeyPairArg("label", requiredResourcesProperty.getLabelName())); } if( StringUtils.isNotBlank(requiredResourcesProperty.getResourceNames())){ lockArgs.add( buildKeyPairArg("resource", requiredResourcesProperty.getResourceNames())); } option.setArgs( lockArgs ); ModelASTUtils.addOption(result.getModelASTPipelineDef(), option ); 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 ); RequiredResourcesProperty requiredResourcesProperty = new RequiredResourcesProperty( "beer", null, null, "labelName", null ); p.addProperty( requiredResourcesProperty ); p.addProperty( requiredResourcesProperty ); RequiredResourcesPropertyConverter converter = j.jenkins.getExtensionList( RequiredResourcesPropertyConverter.class ).get( 0 ); assertTrue( converter.canConvert( requiredResourcesProperty ) ); ConverterResult result = new ConverterResult(); converter.convert( new ConverterRequest(), result, requiredResourcesProperty ); ModelASTOptions options = result.getModelASTPipelineDef().getOptions(); assertEquals( 1, options.getOptions().size() ); String groovy = options.toGroovy(); assertThat( groovy, containsString( "lock" ) ); assertThat( groovy, containsString( "resource: 'beer'" ) ); assertThat( groovy, containsString( "label: 'labelName'" ) ); }
@Test public void simpletest_empty_values() throws Exception { String projectName = Long.toString( System.currentTimeMillis() ); FreeStyleProject p = j.createFreeStyleProject( projectName ); RequiredResourcesProperty requiredResourcesProperty = new RequiredResourcesProperty( "", null, null, "", null ); p.addProperty( requiredResourcesProperty ); p.addProperty( requiredResourcesProperty ); RequiredResourcesPropertyConverter converter = j.jenkins.getExtensionList( RequiredResourcesPropertyConverter.class ).get( 0 ); assertTrue( converter.canConvert( requiredResourcesProperty ) ); ConverterResult result = new ConverterResult(); converter.convert( new ConverterRequest(), result, requiredResourcesProperty ); ModelASTOptions options = result.getModelASTPipelineDef().getOptions(); assertEquals( 1, options.getOptions().size() ); String groovy = options.toGroovy(); assertThat( groovy, containsString( "lock" ) ); }