MessageProgramParser implements ProgramParser { @Override public ProgramType parse(InputStream in, File file, Collection<File> includeDirs) throws IOException, ParseException { try { return mSerializer.deserialize(in, ProgramType.kDescriptor); } catch (SerializerException tse) { throw new ParseException(tse, "Failed to deserialize definition file %s", file.getName()) .setFile(file.getName()); } } MessageProgramParser(Serializer serializer); @Override ProgramType parse(InputStream in, File file, Collection<File> includeDirs);  }
@Test public void testParse() throws IOException { MessageProgramParser parser = new MessageProgramParser(new JsonSerializer()); ByteArrayInputStream in = new ByteArrayInputStream( ("{\n" + " \"namespaces\": {\n" + " \"java\": \"net.morimekta.providence\"\n" + " }\n" + "}").getBytes(StandardCharsets.UTF_8)); ProgramType program = parser.parse(in, new File("test.json"), ImmutableSet.of()); assertThat(program.getNamespaces(), is(ImmutableMap.of( "java", "net.morimekta.providence" ))); }
@Test public void testFail() throws IOException { MessageProgramParser parser = new MessageProgramParser(new JsonSerializer()); ByteArrayInputStream in = new ByteArrayInputStream( ("{\n" + " \"namespaces\": {\n" + " \"java\": \"net.morimekta.providence\"\n" + " },\n" + "}").getBytes(StandardCharsets.UTF_8)); try { parser.parse(in, new File("test.json"), ImmutableSet.of()); fail("no exception"); } catch (ParseException e) { assertThat(e.getMessage(), is("Failed to deserialize definition file test.json")); } }