I started creating JUnit tests for the different algorithms, but soon I realized that most of the time, I write the same code, so I decided to centralize those parts.
Instead of doing multiple calls to the DB, I prefer to create a mock, and read values from CSV. I mock each provider that is responsible to do the call to DB and return values.
Let's say I have the following providers: A, B, C, D, E, F.
I created for each one an abstract class on which I have some methods, one to read values from csv, another one to filter the result and use it in the when-thenReturn statement: AMock, BMock, CMock, DMock, EMock, FMock.
I know that I can't create a test that extends all these classes, so at the moment, I use this workaround:
EMock extends FMock
DMock extends EMock
CMock extends DMock
BMock extends CMock
AMock extends BMock
MyTest1 extends AMock
MyTest2 extends AMock
MyTest3 extends CMock
etc.
But I don't like it very well, because I don't need it all every time,
for example if MyTest2 needs only AMock and EMock, extending the AMock I have them all.
It's there a more elegant approach?