@SuppressWarnings("unchecked") @Test(expected = NonUniqueResultException.class) public void findUniqueThrowsExeptionWhenNonUniqueResult() { when(currencyDao.findUnique(any(Currency.class), any(SearchParameters.class))) .thenThrow(NonUniqueResultException.class); currencyRepository.findUnique(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)); }