I'm trying to test a 3rd party library that works with a callback.
Db db;
db.find("param", new DbCallback() {
public void onComplete(Result r) {
//my business logic with r
r.get("name"); //etc
}
});
This is inside class Foo which is my test subject. It looks like this:
class Foo {
@Autowired
Db db;
void bar() {
db.find("param", new DbCallback() {
public void onComplete(Result r) {
// my business logic with r
r.get("name"); //etc
}
});
}
}
My test so far looks like this:
class FooTest {
@InjectMocks
Foo foo; // test subject
@Mock
Db db; //thing I want to mock
// initMocks etc.
@Test
void bar() {
when(db.find( ??? )).then???
foo.bar();
// asserts etc.
}
}
But I'm not entirely sure how to use when here.
If it was a "regular" method I would just use
when(db.find(anyString()).thenReturn(fakeData)