@Test void testCreateGrammar() throws IOException { this.grammarCreator.createGrammar("testName", "keyword1", "keyword2", "keyword3", "keyword4"); Path grammarDir = this.grammarCreator.getGrammarDirectory(); Path grammarFile = grammarDir.resolve("testName.gram"); Assertions.assertTrue(Files.exists(grammarFile), "Grammar file should have been created,"); String fileContent = new String(Files.readAllBytes(grammarFile), StandardCharsets.UTF_8); assertThat("Grammer file should start with the specified string.", fileContent, startsWith("#JSGF V1.0;")); assertThat("Grammer file should contain line with grammar name.", fileContent, containsString("grammar testName;\n")); assertThat("Grammer file should contain line with keyword 1.", fileContent, containsString("> = ( keyword1 );\n")); assertThat("Grammer file should contain line with keyword 2.", fileContent, containsString("> = ( keyword2 );\n")); assertThat("Grammer file should contain line with keyword 3.", fileContent, containsString("> = ( keyword3 );\n")); assertThat("Grammer file should contain line with keyword 4.", fileContent, containsString("> = ( keyword4 );\n")); }
public void createGrammar(String name, String keywordStartSingle, String keywordStartMulti, String keywordEndMulti, String keywordStopOutput) { Path grammarFile = this.grammarDir.resolve(name + ".gram"); try (BufferedWriter bw = Files.newBufferedWriter(grammarFile, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { bw.write(generateGrammarString(name, keywordStartSingle, keywordStartMulti, keywordEndMulti, keywordStopOutput)); } catch (IOException e) { throw new IllegalStateException("Can't write grammar file", e); } }
SphinxGrammarCreator { public void createGrammar(String name, String keywordStartSingle, String keywordStartMulti, String keywordEndMulti, String keywordStopOutput) { Path grammarFile = this.grammarDir.resolve(name + ".gram"); try (BufferedWriter bw = Files.newBufferedWriter(grammarFile, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { bw.write(generateGrammarString(name, keywordStartSingle, keywordStartMulti, keywordEndMulti, keywordStopOutput)); } catch (IOException e) { throw new IllegalStateException("Can't write grammar file", e); } } }
SphinxGrammarCreator { public void createGrammar(String name, String keywordStartSingle, String keywordStartMulti, String keywordEndMulti, String keywordStopOutput) { Path grammarFile = this.grammarDir.resolve(name + ".gram"); try (BufferedWriter bw = Files.newBufferedWriter(grammarFile, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { bw.write(generateGrammarString(name, keywordStartSingle, keywordStartMulti, keywordEndMulti, keywordStopOutput)); } catch (IOException e) { throw new IllegalStateException("Can't write grammar file", e); } }  }
SphinxGrammarCreator { public void createGrammar(String name, String keywordStartSingle, String keywordStartMulti, String keywordEndMulti, String keywordStopOutput) { Path grammarFile = this.grammarDir.resolve(name + ".gram"); try (BufferedWriter bw = Files.newBufferedWriter(grammarFile, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { bw.write(generateGrammarString(name, keywordStartSingle, keywordStartMulti, keywordEndMulti, keywordStopOutput)); } catch (IOException e) { throw new IllegalStateException("Can't write grammar file", e); } }  void createGrammar(String name, String keywordStartSingle, String keywordStartMulti, String keywordEndMulti,
			String keywordStopOutput); Path getGrammarDirectory(); }
SphinxGrammarCreator { public void createGrammar(String name, String keywordStartSingle, String keywordStartMulti, String keywordEndMulti, String keywordStopOutput) { Path grammarFile = this.grammarDir.resolve(name + ".gram"); try (BufferedWriter bw = Files.newBufferedWriter(grammarFile, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { bw.write(generateGrammarString(name, keywordStartSingle, keywordStartMulti, keywordEndMulti, keywordStopOutput)); } catch (IOException e) { throw new IllegalStateException("Can't write grammar file", e); } }  void createGrammar(String name, String keywordStartSingle, String keywordStartMulti, String keywordEndMulti,
			String keywordStopOutput); Path getGrammarDirectory();  }