use of org.summerb.microservices.properties.impl.dao.StringIdAliasDao in project summerb by skarpushin.
the class StringIdAliasServiceEagerImplFactory method createDaoMock.
private static StringIdAliasDao createDaoMock() {
StringIdAliasDao ret = Mockito.mock(StringIdAliasDao.class);
when(ret.createAliasFor(NAME)).thenReturn(NAME_ALIAS);
when(ret.findAliasFor(NAME)).thenReturn(NAME_ALIAS);
when(ret.loadAllAliases(any(PagerParams.class))).thenAnswer(new Answer<PaginatedList<Entry<String, Long>>>() {
@Override
public PaginatedList<Entry<String, Long>> answer(InvocationOnMock invocation) throws Throwable {
PagerParams pagerParams = (PagerParams) invocation.getArguments()[0];
// Synthetic pause, simulate
Thread.sleep(250);
PaginatedList<Entry<String, Long>> result = new PaginatedList<Entry<String, Long>>();
result.setPagerParams(pagerParams);
result.setTotalResults(150);
ArrayList<Entry<String, Long>> items = new ArrayList<Entry<String, Long>>();
result.setItems(items);
long offset = pagerParams.getOffset();
long max = -1;
if (offset == 0) {
max = 100;
} else if (offset == 100) {
max = 50;
} else {
fail();
}
for (long i = offset; i < max; i++) {
items.add(new AliasEntry("str" + i, i));
}
return result;
}
});
return ret;
}
use of org.summerb.microservices.properties.impl.dao.StringIdAliasDao in project summerb by skarpushin.
the class StringIdAliasServiceEagerImplTest method testLoadAllAliases_whitebox_expectExceptionOnException.
@Test(expected = RuntimeException.class)
public void testLoadAllAliases_whitebox_expectExceptionOnException() {
StringIdAliasServiceEagerImpl fixture = new StringIdAliasServiceEagerImpl();
StringIdAliasDao stringIdAliasDao = Mockito.mock(StringIdAliasDao.class);
when(stringIdAliasDao.loadAllAliases(any(PagerParams.class))).thenThrow(new IllegalStateException("test exception"));
fixture.loadAllAliases();
fail();
}
use of org.summerb.microservices.properties.impl.dao.StringIdAliasDao in project summerb by skarpushin.
the class StringIdAliasServiceEagerImplTest method testGetAliases_whitebox_expectExceptionOnException.
@Test(expected = RuntimeException.class)
public void testGetAliases_whitebox_expectExceptionOnException() {
StringIdAliasServiceEagerImpl fixture = new StringIdAliasServiceEagerImpl();
StringIdAliasDao stringIdAliasDao = Mockito.mock(StringIdAliasDao.class);
when(stringIdAliasDao.loadAllAliases(any(PagerParams.class))).thenThrow(new IllegalStateException("test exception"));
fixture.getAliases();
fail();
}
Aggregations