Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Foo {
@AutoFactory
Foo(@Provider bar, String aString) {...}
}
@Generated(...AutoFactoryProcessor.class)
final class FooFactory {
...
public Foo create(String s) { ... }
}
class MyService {
@Inject MyService(FooFactory factoryOfFoos) { ... }
@Inject ActionLogger log;
Whoop extractWhoop() {
Foo = factoryOfFoos().create(getSomeBlahString());
... // do stuff with Foo to get a Whoop for 10 lines or so
Whoop result = ... // the final Whoop creation.
return result;
}
}
class MyServiceTest {
@Test testDoStuffLogsProperly() {
Foo testFoo = new Foo(new Bar(blah), "this is a test.");
FooFactory factory = mock(FooFactory);
when(factory.create(any(String.class))).return(testFoo); // faked for the test
Whoop expectedWhoop = new Whoop(... whatever);
ASSERT.that(objectUnderTest.extractWhoop()).isEqualTo(expectedWhoop);
ASSERT.that(objectUnderTest.extractWhoop().whatever()).contains("this is a test.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment