MotechJsonReader { public Object readFromFile(String classpathFile, Type ofType) { InputStream inputStream = getClass().getResourceAsStream(classpathFile); if (inputStream == null) { throw new MotechException("File not found in classpath: " + classpathFile); } try { String jsonText = IOUtils.toString(inputStream); return from(jsonText, ofType, standardTypeAdapters, false); } catch (IOException e) { throw new JsonIOException(e); } } MotechJsonReader();  MotechJsonReader(FieldNamingStrategy fieldNamingStrategy); Object readFromStream(InputStream stream, Type ofType); Object readFromStreamOnlyExposeAnnotations(InputStream stream, Type ofType); Object readFromFile(String classpathFile, Type ofType); Object readFromString(String text, Type ofType); Object readFromStringOnlyExposeAnnotations(String text, Type ofType); Object readFromString(String text, Type ofType, Map<Type, Object> typeAdapters);  }
@Test(expected = MotechException.class) public void shouldFailGracefullyWhenJsonFileIsNotFound(){ reader.readFromFile("this-file-does-not-exist.json", String.class); }
@Test public void shouldParseMotechProperties() { MotechProperties motechProperties = (MotechProperties) reader.readFromFile("/motech-properties.json", MotechProperties.class); assertThat(motechProperties.size(), IsEqual.equalTo(14)); assertThat(motechProperties.get("case_name"), IsEqual.equalTo("Pankaja")); assertThat(motechProperties.get("family_number"), IsEqual.equalTo("")); assertThat(motechProperties.get("external_id"), IsNull.nullValue()); }
@Test public void shouldSkipMotechPropertyThatHasJsonObjectAsValue() { MotechProperties motechProperties = (MotechProperties) reader.readFromFile("/complex-motech-properties.json", MotechProperties.class); assertThat(motechProperties.size(), IsEqual.equalTo(5)); assertThat(motechProperties, not(Matchers.hasKey("edd"))); assertThat(motechProperties, not(Matchers.hasKey("next_due"))); assertThat(motechProperties, not(Matchers.hasKey("next_form"))); assertThat(motechProperties, not(Matchers.hasKey("partner_name"))); assertThat(motechProperties, not(Matchers.hasKey("village"))); }