Guest User

Untitled

a guest
May 23rd, 2017
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. Class Foo {
  2.  
  3.     private int a;
  4.     private int b;
  5.     private int c;
  6.     private DBSaver dbSaver;
  7.  
  8.     public Foo(DBSaver dbSaver) {
  9.    
  10.         this.dbSaver = dbSaver;
  11.     }
  12.  
  13.     public void processData() {
  14.        
  15.         processData();
  16.         saveToDB();
  17.     }
  18.  
  19.     private void workNumbers() {
  20.  
  21.         a = 1;
  22.         b = 2;
  23.         c = a + b;
  24.     }
  25.  
  26.     private void saveToDB() {
  27.        
  28.         List<Integer> list = new ArrayList<>();
  29.         list.add(a); list.add(b); list.add(c);
  30.         dbSaver.save(list);
  31.     }
  32. }
  33.  
  34. Class FooTest {
  35.    
  36.     @Mock
  37.     DBSaver dbSaver;
  38.     @Mock
  39.     Foo foo;
  40.    
  41.     @Test
  42.     private void test() {
  43.  
  44.         when(dbSaver.save(any(ArrayList<>.class))).then(returnsFirstArg());
  45.         foo = new Foo(dbSaver);
  46.         Mockito.doThrow(new Exception() {
  47.                 //Now I would like to get a, b and c so I can ensure that they have the proper values.
  48.             }
  49.             ).when(foo).processData();
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment