BlockInstanceOf extends AbstractBlockHolder { @Override public String toString() { BlockProperty p = findPropertyBlockByName( ParsingConstants.PROPERTY_INSTANCE_NAME ); StringBuilder sb = new StringBuilder(); String componentName = getName(); if( ! Utils.isEmptyOrWhitespaces( componentName )) sb.append( componentName ); else sb.append( "Unspecified component" ); if( p != null && ! Utils.isEmptyOrWhitespaces( p.getValue())) { sb.append( " as " ); sb.append( p.getValue()); } return sb.toString(); } BlockInstanceOf( FileDefinition declaringFile ); @Override String[] getSupportedPropertyNames(); @Override int getInstructionType(); @Override String toString();  }
@Test public void testToString() { FileDefinition def = new FileDefinition( new File( "toto.txt" )); BlockInstanceOf block = new BlockInstanceOf( def ); Assert.assertNotNull( block.toString()); block.setName( "my-component" ); Assert.assertTrue( block.toString().contains( "my-component" )); block.getInnerBlocks().add( new BlockProperty( def, ParsingConstants.PROPERTY_INSTANCE_NAME, "foo" )); Assert.assertTrue( block.toString().contains( "my-component" )); Assert.assertTrue( block.toString().contains( "foo" )); Assert.assertTrue( block.toString().contains( " as " )); block.getInnerBlocks().clear(); block.getInnerBlocks().add( new BlockProperty( def, ParsingConstants.PROPERTY_INSTANCE_NAME, " " )); Assert.assertTrue( block.toString().contains( "my-component" )); Assert.assertFalse( block.toString().contains( " as " )); }