DefParser { void parse() throws IOException, DefParserException { root = new InnerCNode(name); normalizedDefinition = new NormalizedDefinition(); String s; List<String> originalInput = new ArrayList<>(); while ((s = reader.readLine()) != null) { originalInput.add(s); } reader.close(); parseLines(root, originalInput, normalizedDefinition); root.setMd5(normalizedDefinition.generateMd5Sum()); } DefParser(String name, Reader defReader); InnerCNode getTree(); NormalizedDefinition getNormalizedDefinition(); static void dumpTree(CNode root, String indent); static final String DEFAULT_PACKAGE_PREFIX; static final Pattern versionPattern; static final Pattern namespacePattern; static final Pattern packagePattern; }
@Test public void version_is_not_mandatory() { try { createParser("a string\n").parse(); } catch (Exception e) { fail("Should not get an exception here"); } }
@Test(expected = DefParser.DefParserException.class) public void testInvalidCommaInEnum() throws DefParser.DefParserException, IOException { String invalidEnum = "anEnum enum {A, B, } default=A\n"; String validEnum = "anotherEnum enum {A, B} default=A\n"; StringBuilder sb = createDefTemplate(); sb.append(invalidEnum); sb.append(validEnum); DefParser parser = createParser(sb.toString()); parser.parse(); }
@Test public void duplicate_parameter_is_illegal() { Class<?> exceptionClass = DefParser.DefParserException.class; StringBuilder sb = createDefTemplate(); String duplicateLine = "b int\n"; sb.append(duplicateLine); sb.append(duplicateLine); try { createParser(sb.toString()).parse(); fail("Didn't find expected exception of type " + exceptionClass); } catch (Exception e) { assertExceptionAndMessage(e, exceptionClass, "Error when parsing line 4: " + duplicateLine + "b is already defined"); } }