Skip to content

Instantly share code, notes, and snippets.

@cgruber
Created May 15, 2014 20:13
Show Gist options
  • Save cgruber/cb3b053f4a2a0f9d9c6f to your computer and use it in GitHub Desktop.
Save cgruber/cb3b053f4a2a0f9d9c6f to your computer and use it in GitHub Desktop.
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