Guest User

Untitled

a guest
May 14th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 0.75 KB | None | 0 0
  1. // ======================================
  2. // tests: unit tests for the domain model
  3. // ======================================
  4.  
  5.  
  6. class CopyTest {
  7.  
  8.   void testCopyIsFreeIfUserIsNull() {
  9.     def copy = new Copy();
  10.     copy.user = null
  11.     assertTrue(copy.isAvailable())
  12.     copy.user = new User()
  13.     assertFalse(copy.isAvailable())
  14.   }
  15. }
  16.  
  17. class BookTest {
  18.  
  19.   void testBookIsAvailableIfAnyCopyIsAvailable() {
  20.     def book = new Book()
  21.     book.copies = []
  22.     assertFalse(book.isAvailable())
  23.  
  24.  
  25.     // Variante 1: echtes Copy
  26.     def copy = new Copy(book)
  27.  
  28.     // Variante 2: gemocktes Copy
  29.     def copy = mock(Copy.class)
  30.     when(copy.isAvailable()).thenReturn(true)
  31.    
  32.  
  33.     book.copies = [copy]
  34.     assertTrue(book.isAvailable())
  35.   }
  36. }
Add Comment
Please, Sign In to add comment