ContextFreeGrammar extends Grammar { @SuppressWarnings({"UnusedReturnValue", "IOResourceOpenedButNotSafelyClosed"}) public boolean readBNFFile(String file_name) throws MalformedGrammarException { StringBuffer contents = new StringBuffer(); try { int bufferSize = 1024; String line; ClassLoader loader = ClassLoader.getSystemClassLoader(); InputStream is = loader.getResourceAsStream(file_name); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr, bufferSize); assert (br != null) : "Cannot load resource from classloader: "+file_name; while( (line = br.readLine()) != null ) { contents.append(line); contents.append(System.getProperty("line.separator")); } br.close(); } catch(FileNotFoundException e) { System.err.println("Grammar File not found: "+file_name); return false; } catch(NullPointerException e) { System.err.println("Grammar File not found in classloader: "+file_name); return false; } catch(IOException e) { System.err.println("IOException when looking for grammar file: "+file_name); return false; } contents.append("\n"); return readBNFString(contents.toString()); } ContextFreeGrammar();   ContextFreeGrammar(ContextFreeGrammar g); abstract boolean genotype2Phenotype(); abstract boolean phenotype2Genotype(); abstract int getUsedCodons(); abstract int getUsedWraps(); @SuppressWarnings({"UnusedReturnValue", "IOResourceOpenedButNotSafelyClosed"}) boolean readBNFFile(String file_name); Rule findRule(Symbol s); Rule findRule(String s); ArrayList getTerminalRules(); ArrayList getNonTerminalRules();  }
@Test public void testReadBNFFile() { System.out.println("* ContextFreeGrammarTest: readBNFFile"); String fileName = ""; ContextFreeGrammar instance = new ContextFreeGrammarMock(); boolean result = false; try { result = instance.readBNFFile(fileName); fail("Expected a Malformed Grammar Exception"); } catch (MalformedGrammarException ex) { } catch (AssertionError e) { assertTrue(true); } catch (NullPointerException e) { assertTrue(true); } assertEquals(false, result); instance = new ContextFreeGrammarMock(); fileName = null; result = true; try { result = instance.readBNFFile(fileName); fail("Expected a Malformed Grammar Exception"); } catch (MalformedGrammarException ex) { } catch (AssertionError e) { assertTrue(true); } catch (NullPointerException e) { assertTrue(true); } assertEquals(false, result); }