InputJsonReader { @Nullable public AbstractInput read(@Nullable final String json) { if (TextUtils.isEmpty(json)) { return null; } try { return read(new StringReader(json)); } catch (IOException ioe) { Log.w(TAG, ioe.getMessage()); } return null; } InputJsonReader(@NonNull final OnInputJsonReaderListener onInputJsonReaderListener); @NonNull String getDateFormat(); void setDateFormat(@NonNull final String dateFormat); @Nullable AbstractInput read(@Nullable final String json); @NonNull AbstractInput read(@NonNull final Reader in);  }
@Test public void testReadEmptyInput() throws Exception { final String json = TestHelper.getFixture("input_empty.json"); final StringReader reader = new StringReader(json); final DummyInput input = (DummyInput) inputJsonReader.read(reader); verify(onInputJsonReaderListener, never()).readAdditionalInputData(any(JsonReader.class), any(String.class), any(DummyInput.class)); verify(onInputJsonReaderListener, never()).readAdditionalTaxonData(any(JsonReader.class), any(String.class), any(DummyTaxon.class)); assertNotNull(input); assertEquals(2, input.getInputId()); assertEquals(InputType.FAUNA, input.getType()); final Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.YEAR, 2015); calendar.set(Calendar.MONTH, Calendar.NOVEMBER); calendar.set(Calendar.DAY_OF_MONTH, 19); assertEquals(calendar.getTime(), input.getDate()); assertNull(input.getQualification()); assertEquals(0, input.getObservers() .size()); assertEquals(0, input.getTaxa() .size()); assertEquals(-1, input.getCurrentSelectedTaxonId()); }
@Test public void testRead() throws Exception { final String json = TestHelper.getFixture("input.json"); final StringReader reader = new StringReader(json); final DummyInput input = (DummyInput) inputJsonReader.read(reader); verify(onInputJsonReaderListener, never()).readAdditionalInputData(any(JsonReader.class), any(String.class), any(DummyInput.class)); verify(onInputJsonReaderListener, never()).readAdditionalTaxonData(any(JsonReader.class), any(String.class), any(DummyTaxon.class)); assertNotNull(input); assertEquals(2, input.getInputId()); assertEquals(InputType.FAUNA, input.getType()); final Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.YEAR, 2015); calendar.set(Calendar.MONTH, Calendar.NOVEMBER); calendar.set(Calendar.DAY_OF_MONTH, 19); assertEquals(calendar.getTime(), input.getDate()); final Qualification qualification = input.getQualification(); assertNotNull(qualification); assertEquals(2, qualification.getOrganism()); assertEquals(140, qualification.getProtocol()); assertEquals(4, qualification.getLot()); assertEquals(1, input.getObservers() .size()); final Observer observer1 = input.getObservers() .get(1L); assertNotNull(observer1); assertEquals(1, observer1.getObserverId()); assertEquals(1, input.getTaxa() .size()); final DummyTaxon taxon1 = (DummyTaxon) input.getTaxa() .get(3L); assertNotNull(taxon1); assertEquals(3L, taxon1.getId()); assertEquals(4L, taxon1.getTaxonId()); assertEquals("name", taxon1.getNameEntered()); assertEquals(5L, taxon1.getCriterionId()); assertEquals("comment", taxon1.getComment()); assertEquals(3L, input.getCurrentSelectedTaxonId()); assertNotNull(input.getCurrentSelectedTaxon()); assertEquals(3L, input.getCurrentSelectedTaxon() .getId()); assertEquals(4L, input.getCurrentSelectedTaxon() .getTaxonId()); assertEquals("name", input.getCurrentSelectedTaxon() .getNameEntered()); assertEquals(5L, input.getCurrentSelectedTaxon() .getCriterionId()); assertEquals("comment", input.getCurrentSelectedTaxon() .getComment()); }