@Test public void testRecognizeComment() { Collection<AbstractBlock> blocks = new ArrayList<> (); String[] validLines = { "# ok", "#", " # woo ", " ###############" }; for( String line : validLines ) { blocks.clear(); FileDefinitionParser parser = new FileDefinitionParser( null, false ); int code = parser.recognizeComment( line, blocks ); Assert.assertEquals( "Expected a YES code for '" + line + "'", FileDefinitionParser.P_CODE_YES, code ); Assert.assertEquals( "No parsing error was expected for '" + line + "'", 0, parser.getFileRelations().getParsingErrors().size()); Assert.assertEquals( "Expected ONE block to be registered for '" + line + "'", 1, blocks.size()); Assert.assertEquals( "Expected ONE comment block for '" + line + "'", AbstractBlock.COMMENT, blocks.iterator().next().getInstructionType()); } for( String line : validLines ) { blocks.clear(); FileDefinitionParser parser = new FileDefinitionParser( null, true ); int code = parser.recognizeComment( line, blocks ); Assert.assertEquals( "Expected a YES code for '" + line + "'", FileDefinitionParser.P_CODE_YES, code ); Assert.assertEquals( "No parsing error was expected for '" + line + "'", 0, parser.getFileRelations().getParsingErrors().size()); Assert.assertEquals( "Expected ZERO block to be registered for '" + line + "'", 0, blocks.size()); } String[] invalidLines = { "", " ", "something", "something # with a comment after" }; for( String line : invalidLines ) { blocks.clear(); FileDefinitionParser parser = new FileDefinitionParser( null, true ); int code = parser.recognizeComment( line, blocks ); Assert.assertEquals( "Expected a NO code for '" + line + "'", FileDefinitionParser.P_CODE_NO, code ); Assert.assertEquals( "No parsing error was expected for '" + line + "'", 0, parser.getFileRelations().getParsingErrors().size()); Assert.assertEquals( "Expected ZERO block to be registered for '" + line + "'", 0, blocks.size()); } }
int recognizeComment( String line, Collection<AbstractBlock> blocks ) { int result = P_CODE_NO; if( line.trim().startsWith( ParsingConstants.COMMENT_DELIMITER )) { result = P_CODE_YES; if( ! this.ignoreComments ) blocks.add( new BlockComment( this.definitionFile, line )); } return result; }
FileDefinitionParser { int recognizeComment( String line, Collection<AbstractBlock> blocks ) { int result = P_CODE_NO; if( line.trim().startsWith( ParsingConstants.COMMENT_DELIMITER )) { result = P_CODE_YES; if( ! this.ignoreComments ) blocks.add( new BlockComment( this.definitionFile, line )); } return result; } }
FileDefinitionParser { int recognizeComment( String line, Collection<AbstractBlock> blocks ) { int result = P_CODE_NO; if( line.trim().startsWith( ParsingConstants.COMMENT_DELIMITER )) { result = P_CODE_YES; if( ! this.ignoreComments ) blocks.add( new BlockComment( this.definitionFile, line )); } return result; } FileDefinitionParser( File relationsFile, boolean ignoreComments ); }
FileDefinitionParser { int recognizeComment( String line, Collection<AbstractBlock> blocks ) { int result = P_CODE_NO; if( line.trim().startsWith( ParsingConstants.COMMENT_DELIMITER )) { result = P_CODE_YES; if( ! this.ignoreComments ) blocks.add( new BlockComment( this.definitionFile, line )); } return result; } FileDefinitionParser( File relationsFile, boolean ignoreComments ); FileDefinition read(); }
FileDefinitionParser { int recognizeComment( String line, Collection<AbstractBlock> blocks ) { int result = P_CODE_NO; if( line.trim().startsWith( ParsingConstants.COMMENT_DELIMITER )) { result = P_CODE_YES; if( ! this.ignoreComments ) blocks.add( new BlockComment( this.definitionFile, line )); } return result; } FileDefinitionParser( File relationsFile, boolean ignoreComments ); FileDefinition read();  }