-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathBookRepositoryImplOkHttpTest.java
More file actions
51 lines (39 loc) · 1.3 KB
/
Copy pathBookRepositoryImplOkHttpTest.java
File metadata and controls
51 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.howtoprogram.repository.okhttp;
import org.junit.Before;
import org.junit.Test;
import com.howtoprogram.domain.Book;
import junit.framework.Assert;
public class BookRepositoryImplOkHttpTest {
private BookRepositoryImplOkHttp bookRepository;
@Before
public void initialize() {
bookRepository = new BookRepositoryImplOkHttp();
}
@Test
public void testGetAllBooks() throws Exception {
Book[] books = bookRepository.getAllBooks();
Assert.assertTrue(books.length > 0);
}
@Test
public void testDeleteBook() throws Exception {
Book[] books1 = bookRepository.getAllBooks();
bookRepository.deleteBook(books1[0].getId());
Book[] books2 = bookRepository.getAllBooks();
Assert.assertEquals(books1.length - 1, books2.length);
}
@Test
public void testAddBook() throws Exception {
Book book = new Book(null, "Hell", "aaa");
Book createdBook = bookRepository.createBook(book);
Assert.assertTrue(createdBook != null && createdBook.getId() > 0);
}
@Test
public void testUpdateBook() throws Exception {
Book[] books = bookRepository.getAllBooks();
Book book = books[0];
book.setAuthor("Reactive Programming");
Book updatedBook = bookRepository.updateBook(book);
Assert.assertTrue(updatedBook != null);
Assert.assertEquals("Reactive Programming", updatedBook.getAuthor());
}
}