Advertisement
Guest User

Untitled

a guest
Mar 25th, 2018
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. package g30124.hendli.catalin.l4.e5;
  2. import g30124.hendli.catalin.l4.e4.Author;
  3.  
  4. import static org.junit.Assert.*;
  5. import org.junit.*;
  6.  
  7.  
  8. public class TestBook {
  9. private Book b;
  10. private Author a;
  11.  
  12. @Before
  13. public void initTest() {
  14. System.out.println("Initialize test.");
  15. }
  16.  
  17. @Test
  18. public void TestGetAuthor() {
  19. a = new Author("Jamie Andrew", "dotsdots@yahoo.com",'m');
  20. b = new Book("Book no. 1",a,120);
  21. assertEquals("Book no. 1",b.getName());
  22. assertEquals("Jamie Andrew (m) dotsdots@yahoo.com",b.getAuthor().toString());
  23. //here i used the toString() method from Author class for testing
  24. //i could also use getName(), getEmail(), getGender();
  25. }
  26.  
  27. @Test
  28. public void TestSettersAndGetters() {
  29. b = new Book("Book no.2",a,23.99,20);
  30. b.setPrice(20.99);
  31. assertTrue(b.getPrice() == 20.99);
  32. b.setQtyInStock(23);
  33. assertEquals(23,b.getQtyInStock());
  34. }
  35.  
  36. @Test
  37. public void TestToString() {
  38. a = new Author("Jamie Andrew", "dotsdots@yahoo.com",'m');
  39. b = new Book("Book no.5",a,200,40);
  40. assertEquals("Book no.5 by Jamie Andrew (m) at dotsdots@yahoo.com",b.toString());
  41. }
  42.  
  43. @After
  44. public void finTest() {
  45. System.out.println("Finished test.");
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement