@SuppressWarnings("unchecked") @Test(expected = NonUniqueResultException.class) public void findUniqueOrNoneThrowsExceptionWhenNonUniqueResults() { when(currencyDao.findUniqueOrNone(any(Currency.class), any(SearchParameters.class))) .thenThrow(NonUniqueResultException.class); currencyRepository.findUniqueOrNone(new Currency()); }
@Test public void findUniqueOrNoneReturnsNull() { when(currencyDao.findUniqueOrNone(any(Currency.class), any(SearchParameters.class))) .thenReturn(null); Currency result = currencyRepository.findUniqueOrNone(new Currency()); assertThat(result).isNull(); verify(currencyDao, times(1)) .findUniqueOrNone(any(Currency.class), any(SearchParameters.class)); }
@Test public void findUniqueOrNoneReturnsSingleValue() { Currency unique = new Currency(); when(currencyDao.findUniqueOrNone(any(Currency.class), any(SearchParameters.class))) .thenReturn(unique); Currency result = currencyRepository.findUniqueOrNone(new Currency()); assertThat(result).isNotNull().isSameAs(unique); verify(currencyDao, times(1)) .findUniqueOrNone(any(Currency.class), any(SearchParameters.class)); }