Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. package by.epam.dzianis;
  2.  
  3.  
  4.  
  5. import java.util.List;
  6.  
  7. import org.junit.After;
  8. import org.junit.Assert;
  9. import org.junit.Before;
  10. import org.junit.Test;
  11.  
  12. import by.epam.dzianis.dao.*;
  13. import by.epam.dzianis.data.MyImage;
  14. import static org.mockito.Mockito.*;
  15.  
  16.  
  17.  
  18. public class TestREST {
  19.     List mockedList = mock(List.class);
  20.     MyImage myImage = mock(MyImage.class);
  21.     IDao dao = new Dao(mockedList, myImage);
  22.    
  23.    
  24.     /**
  25.      *
  26.      */
  27.     @Test
  28.     public void testDaoCreate(){
  29.        
  30.         when(myImage.getId()).thenReturn(0);
  31.         when(mockedList.size()).thenReturn(1);
  32.         when(mockedList.get(0)).thenReturn(myImage);
  33.        
  34.         dao.create(myImage);
  35.        
  36.         verify(mockedList).add(myImage);
  37.         verify(mockedList).get(0);
  38.         verify(myImage).setId(0);
  39.     }
  40.    
  41.     /**
  42.      *
  43.      */
  44.     @Test
  45.     public void testDaoRead(){
  46.         when(mockedList.get(0)).thenReturn(myImage);
  47.         Assert.assertEquals(dao.read(0), myImage);
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement