use of com.thoughtworks.go.server.database.DatabaseStrategy in project gocd by gocd.
the class MaterialRepositoryTest method setUp.
@Before
public void setUp() {
databaseStrategy = mock(DatabaseStrategy.class);
sessionFactory = mock(SessionFactory.class);
goCache = mock(GoCache.class);
ourCustomCache = new HashMap<>();
transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
mockHibernateTemplate = mock(HibernateTemplate.class);
materialConfigConverter = mock(MaterialConfigConverter.class);
materialExpansionService = mock(MaterialExpansionService.class);
materialRepository = new MaterialRepository(sessionFactory, goCache, 4242, transactionSynchronizationManager, materialConfigConverter, materialExpansionService, databaseStrategy);
materialRepository.setHibernateTemplate(mockHibernateTemplate);
when(goCache.get(anyString())).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
return ourCustomCache.get(arguments[0]);
}
});
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
return ourCustomCache.put((String) arguments[0], arguments[1]);
}
}).when(goCache).put(anyString(), anyObject());
when(goCache.remove(anyString())).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
return ourCustomCache.remove(arguments[0]);
}
});
}
Aggregations