EnumParser { public static List<EnumRow> fromString( final String content ) { final List<EnumRow> enums = new ArrayList<EnumRow>(); if ( content == null || content.isEmpty() ) { return enums; } else { final String[] lines = content.split( "\\n" ); for ( int i = 0; i < lines.length; i++ ) { final String line = lines[ i ].trim(); final EnumRow er = parseEnum( line ); if ( er != null ) { enums.add( er ); } } } return enums; } private  EnumParser(); static List<EnumRow> fromString( final String content ); static String toString( final List<EnumRow> content );  }
@Test public void testFromStringParsing1() { final String content = "'Fact.field' : ['a', 'b']"; final List<EnumRow> enums = EnumParser.fromString( content ); assertFalse( enums.isEmpty() ); assertEquals( 1, enums.size() ); assertEquals( "Fact", enums.get( 0 ).getFactName() ); assertEquals( "field", enums.get( 0 ).getFieldName() ); assertEquals( "['a', 'b']", enums.get( 0 ).getContext() ); }
@Test public void testFromStringParsing2() { final String content = "Fact.field' : ['a', 'b']"; final List<EnumRow> enums = EnumParser.fromString( content ); assertFalse( enums.isEmpty() ); assertEquals( "Fact.field' : ['a', 'b']", enums.get( 0 ).getRaw() ); }
@Test public void testFromStringParsing3() { final String content = "'Fact.field : ['a', 'b']"; final List<EnumRow> enums = EnumParser.fromString( content ); assertFalse( enums.isEmpty() ); assertEquals( "'Fact.field : ['a', 'b']", enums.get( 0 ).getRaw() ); }
@Test public void testFromStringParsing4() { final String content = "'Fact.field':['a', 'b']"; final List<EnumRow> enums = EnumParser.fromString( content ); assertFalse( enums.isEmpty() ); assertEquals( 1, enums.size() ); assertEquals( "Fact", enums.get( 0 ).getFactName() ); assertEquals( "field", enums.get( 0 ).getFieldName() ); assertEquals( "['a', 'b']", enums.get( 0 ).getContext() ); }
@Test public void testFromStringParsing5() { final String content = "'Fact.field': ['a', 'b']"; final List<EnumRow> enums = EnumParser.fromString( content ); assertFalse( enums.isEmpty() ); assertEquals( 1, enums.size() ); assertEquals( "Fact", enums.get( 0 ).getFactName() ); assertEquals( "field", enums.get( 0 ).getFieldName() ); assertEquals( "['a', 'b']", enums.get( 0 ).getContext() ); }
@Test public void testFromStringParsing6() { final String content = "'Fact.field' :['a', 'b']"; final List<EnumRow> enums = EnumParser.fromString( content ); assertFalse( enums.isEmpty() ); assertEquals( 1, enums.size() ); assertEquals( "Fact", enums.get( 0 ).getFactName() ); assertEquals( "field", enums.get( 0 ).getFieldName() ); assertEquals( "['a', 'b']", enums.get( 0 ).getContext() ); }
@Test public void testFromStringMissingFact1() { final String content = "field' : ['a', 'b']"; final List<EnumRow> enums = EnumParser.fromString( content ); assertFalse( enums.isEmpty() ); assertEquals( "field' : ['a', 'b']", enums.get( 0 ).getRaw() ); }
@Test public void testFromStringMissingFact2() { final String content = ".field' : ['a', 'b']"; final List<EnumRow> enums = EnumParser.fromString( content ); assertFalse( enums.isEmpty() ); assertEquals( ".field' : ['a', 'b']", enums.get( 0 ).getRaw() ); }
@Test public void testFromStringMissingField1() { final String content = "Fact' : ['a', 'b']"; final List<EnumRow> enums = EnumParser.fromString( content ); assertFalse( enums.isEmpty() ); assertEquals( "Fact' : ['a', 'b']", enums.get( 0 ).getRaw() ); }
@Test public void testFromStringMissingField2() { final String content = "Fact.' : ['a', 'b']"; final List<EnumRow> enums = EnumParser.fromString( content ); assertFalse( enums.isEmpty() ); assertEquals( "Fact.' : ['a', 'b']", enums.get( 0 ).getRaw() ); }
@Test public void testFromStringMissingContext() { final String content = "Fact.field' :"; final List<EnumRow> enums = EnumParser.fromString( content ); assertFalse( enums.isEmpty() ); assertEquals( "Fact.field' :", enums.get( 0 ).getRaw() ); }
@Test public void testFromStringInvalidSyntax() { final String content = "This isn't even close to a correct definition"; final List<EnumRow> enums = EnumParser.fromString( content ); assertFalse( enums.isEmpty() ); assertEquals( "This isn't even close to a correct definition", enums.get( 0 ).getRaw() ); }
@Test public void testFromStringComments() { final String content = "'Fact.field' : ['a', 'b']\n" + "\n" + "#A comment\n" + " final List<EnumRow> enums = EnumParser.fromString( content ); assertFalse( enums.isEmpty() ); assertEquals( 1, enums.size() ); assertEquals( "Fact", enums.get( 0 ).getFactName() ); assertEquals( "field", enums.get( 0 ).getFieldName() ); assertEquals( "['a', 'b']", enums.get( 0 ).getContext() ); }