Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ======================================
- // tests: unit tests for the domain model
- // ======================================
- class CopyTest {
- void testCopyIsFreeIfUserIsNull() {
- def copy = new Copy();
- copy.user = null
- assertTrue(copy.isAvailable())
- copy.user = new User()
- assertFalse(copy.isAvailable())
- }
- }
- class BookTest {
- void testBookIsAvailableIfAnyCopyIsAvailable() {
- def book = new Book()
- book.copies = []
- assertFalse(book.isAvailable())
- // Variante 1: echtes Copy
- def copy = new Copy(book)
- // Variante 2: gemocktes Copy
- def copy = mock(Copy.class)
- when(copy.isAvailable()).thenReturn(true)
- book.copies = [copy]
- assertTrue(book.isAvailable())
- }
- }
Add Comment
Please, Sign In to add comment