@Test public void singleNullValue() { when(cursor.getCount()).thenReturn(1); when(cursor.moveToFirst()).thenReturn(true); Fetcher fetcher = Fetcher.of(cursor); Optional<String> result = fetcher.toValue(Converter.STRING); assertFalse("We should not have a value", result.isPresent()); }
@Test public void emptyCursorToValue() { when(cursor.getCount()).thenReturn(0); Fetcher fetcher = Fetcher.of(cursor); Optional<String> result = fetcher.toValue(Converter.STRING); assertFalse(result.isPresent()); verify(cursor).close(); }
@Test public void singleValueToValue() { when(cursor.getCount()).thenReturn(1); when(cursor.moveToFirst()).thenReturn(true); when(cursor.getInt(0)).thenReturn(42); Fetcher fetcher = Fetcher.of(cursor); Optional<Integer> result = fetcher.toValue(Converter.INT); assertTrue("We should have a value", result.isPresent()); assertThat(result.get()).isEqualTo(42); }
@Test public void nullCursor() { Fetcher fetcher = Fetcher.of(null); assertThat(fetcher.toList(Converter.STRING)).isNotNull().isEmpty(); assertThat(fetcher.toSet(Converter.STRING)).isNotNull().isEmpty(); assertThat(fetcher.toCollection(Converter.STRING, Collections.<String>emptyList())) .isNotNull() .isEmpty(); final Optional<String> result = fetcher.toValue(Converter.STRING); assertThat(result).isNotNull(); assertFalse(result.isPresent()); }