Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Class Foo {
- private int a;
- private int b;
- private int c;
- private DBSaver dbSaver;
- public Foo(DBSaver dbSaver) {
- this.dbSaver = dbSaver;
- }
- public void processData() {
- processData();
- saveToDB();
- }
- private void workNumbers() {
- a = 1;
- b = 2;
- c = a + b;
- }
- private void saveToDB() {
- List<Integer> list = new ArrayList<>();
- list.add(a); list.add(b); list.add(c);
- dbSaver.save(list);
- }
- }
- Class FooTest {
- @Mock
- DBSaver dbSaver;
- @Mock
- Foo foo;
- @Test
- private void test() {
- when(dbSaver.save(any(ArrayList<>.class))).then(returnsFirstArg());
- foo = new Foo(dbSaver);
- Mockito.doThrow(new Exception() {
- //Now I would like to get a, b and c so I can ensure that they have the proper values.
- }
- ).when(foo).processData();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment