Skip to content

Commit d89613d

Browse files
author
Thomas Wiik
committed
Implemented author class. Refactoring. Changed tests to adhere to exercise two.
1 parent c88c9b3 commit d89613d

File tree

7 files changed

+63
-29
lines changed

7 files changed

+63
-29
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.booleanuk.core;
22

33
public class Article extends RentableReadingMaterial{
4+
private final Author author;
45

5-
public Article(String title){
6+
public Article(String title, Author author){
67
super(title);
8+
this.author = author;
79
}
810
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.booleanuk.core;
2+
3+
public class Author {
4+
private final String name;
5+
private final String phoneNumber;
6+
private final String email;
7+
8+
public Author(String name, String phoneNumber, String email){
9+
this.name = name;
10+
this.phoneNumber = phoneNumber;
11+
this.email = email;
12+
}
13+
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package com.booleanuk.core;
22

33
public class Book extends RentableReadingMaterial{
4-
public Book(String title) {
4+
private final Author author;
5+
6+
public Book(String title, Author author) {
57
super(title);
8+
this.author = author;
69
}
10+
11+
public Author getAuthor(){ return this.author; }
712
}

src/test/java/com/booleanuk/core/ArticleTest.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,34 @@
66
class ArticleTest {
77
@Test
88
public void shouldCheckOutIfAvailable() {
9-
Article article = new Article("JUnit Rocks");
10-
Assertions.assertEquals("item has been checked out", article.checkOut());
9+
Author author = new Author("Dave", "12345678", "[email protected]");
10+
Article article = new Article("JUnit Rocks", author);
11+
Assertions.assertEquals("Item has been checked out.", article.checkOut());
1112
}
1213

1314
@Test
1415
public void shouldDeclineIfNotAvailableToCheckout() {
15-
Article article = new Article("JUnit Rocks");
16+
Author author = new Author("Dave", "12345678", "[email protected]");
17+
Article article = new Article("JUnit Rocks", author);
1618
article.checkOut();
1719

18-
Assertions.assertEquals("item is currently on loan", article.checkOut());
20+
Assertions.assertEquals("Item is currently on loan.", article.checkOut());
1921
}
2022

2123
@Test
2224
public void shouldCheckInIfOnLoan() {
23-
Article article = new Article("JUnit Rocks");
25+
Author author = new Author("Dave", "12345678", "[email protected]");
26+
Article article = new Article("JUnit Rocks", author);
2427
article.checkOut();
2528

26-
Assertions.assertEquals("item has been checked in", article.checkIn());
29+
Assertions.assertEquals("Item has been checked in.", article.checkIn());
2730
}
2831

2932
@Test
3033
public void shouldDeclineCheckInIfNotOnLoan() {
31-
Article article = new Article("JUnit Rocks");
34+
Author author = new Author("Dave", "12345678", "[email protected]");
35+
Article article = new Article("JUnit Rocks", author);
3236

33-
Assertions.assertEquals("item is not currently on loan", article.checkIn());
37+
Assertions.assertEquals("Item is not currently on loan.", article.checkIn());
3438
}
3539
}

src/test/java/com/booleanuk/core/BookTest.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,34 @@
66
public class BookTest {
77
@Test
88
public void shouldCheckOutIfAvailable() {
9-
Book book = new Book("JUnit Rocks");
10-
Assertions.assertEquals("item has been checked out", book.checkOut());
9+
Author author = new Author("Dave", "12345678", "[email protected]");
10+
Book book = new Book("JUnit Rocks", author);
11+
Assertions.assertEquals("Item has been checked out.", book.checkOut());
1112
}
1213

1314
@Test
1415
public void shouldDeclineIfNotAvailableToCheckout() {
15-
Book book = new Book("JUnit Rocks");
16+
Author author = new Author("Dave", "12345678", "[email protected]");
17+
Book book = new Book("JUnit Rocks", author);
1618
book.checkOut();
1719

18-
Assertions.assertEquals("item is currently on loan", book.checkOut());
20+
Assertions.assertEquals("Item is currently on loan.", book.checkOut());
1921
}
2022

2123
@Test
2224
public void shouldCheckInIfOnLoan() {
23-
Book book = new Book("JUnit Rocks");
25+
Author author = new Author("Dave", "12345678", "[email protected]");
26+
Book book = new Book("JUnit Rocks", author);
2427
book.checkOut();
2528

26-
Assertions.assertEquals("item has been checked in", book.checkIn());
29+
Assertions.assertEquals("Item has been checked in.", book.checkIn());
2730
}
2831

2932
@Test
3033
public void shouldDeclineCheckInIfNotOnLoan() {
31-
Book book = new Book("JUnit Rocks");
34+
Author author = new Author("Dave", "12345678", "[email protected]");
35+
Book book = new Book("JUnit Rocks", author);
3236

33-
Assertions.assertEquals("item is not currently on loan", book.checkIn());
37+
Assertions.assertEquals("Item is not currently on loan.", book.checkIn());
3438
}
3539
}

src/test/java/com/booleanuk/core/LibraryTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ public class LibraryTest {
88
@Test
99
public void checkOutRentableReadingMaterialTest(){
1010
Library library = new Library();
11-
RentableReadingMaterial book = new Book("My Java life");
11+
Author author = new Author("Dave", "12345678", "[email protected]");
12+
RentableReadingMaterial book = new Book("Teaching cats Java for dummies", author);
1213
library.addToStock(book);
1314

14-
String result = library.checkOutRentableReadingMaterial("My Java life");
15+
String result = library.checkOutRentableReadingMaterial("Teaching cats Java for dummies");
1516
Assertions.assertEquals("Item has been checked out.", result);
1617

17-
result = library.checkOutRentableReadingMaterial("My Java life");
18+
result = library.checkOutRentableReadingMaterial("Teaching cats Java for dummies");
1819
Assertions.assertEquals("Item is currently on loan.", result);
1920

2021
result = library.checkOutRentableReadingMaterial("The secret life of cats");
@@ -23,14 +24,15 @@ public void checkOutRentableReadingMaterialTest(){
2324

2425
@Test void checkInRentableReadingMaterialTest(){
2526
Library library = new Library();
26-
RentableReadingMaterial book = new Book("My Java life");
27+
Author author = new Author("Dave", "12345678", "[email protected]");
28+
RentableReadingMaterial book = new Book("Teaching cats Java for dummies", author);
2729
library.addToStock(book);
2830

29-
library.checkOutRentableReadingMaterial("My Java life");
30-
String result = library.checkInRentableReadingMaterial("My Java life");
31+
library.checkOutRentableReadingMaterial("Teaching cats Java for dummies");
32+
String result = library.checkInRentableReadingMaterial("Teaching cats Java for dummies");
3133
Assertions.assertEquals("Item has been checked in.", result);
3234

33-
result = library.checkInRentableReadingMaterial("My Java life");
35+
result = library.checkInRentableReadingMaterial("Teaching cats Java for dummies");
3436
Assertions.assertEquals("Item is not currently on loan.", result);
3537

3638
result = library.checkInRentableReadingMaterial("The life of a cat");

src/test/java/com/booleanuk/core/RentableReadingMaterialTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,33 @@
66
public class RentableReadingMaterialTest {
77
@Test
88
public void shouldCheckOutIfAvailable() {
9-
Book book = new Book("JUnit Rocks");
9+
Author author = new Author("Dave", "12345678", "[email protected]");
10+
Book book = new Book("JUnit Rocks", author);
1011
Assertions.assertEquals("Item has been checked out.", book.checkOut());
1112
}
1213

1314
@Test
1415
public void shouldDeclineIfNotAvailableToCheckout() {
15-
Book book = new Book("JUnit Rocks");
16+
Author author = new Author("Dave", "12345678", "[email protected]");
17+
Book book = new Book("JUnit Rocks", author);
1618
book.checkOut();
1719

1820
Assertions.assertEquals("Item is currently on loan.", book.checkOut());
1921
}
2022

2123
@Test
2224
public void shouldCheckInIfOnLoan() {
23-
Book book = new Book("JUnit Rocks");
25+
Author author = new Author("Dave", "12345678", "[email protected]");
26+
Book book = new Book("JUnit Rocks", author);
2427
book.checkOut();
2528

2629
Assertions.assertEquals("Item has been checked in.", book.checkIn());
2730
}
2831

2932
@Test
3033
public void shouldDeclineCheckInIfNotOnLoan() {
31-
Book book = new Book("JUnit Rocks");
34+
Author author = new Author("Dave", "12345678", "[email protected]");
35+
Book book = new Book("JUnit Rocks", author);
3236

3337
Assertions.assertEquals("Item is not currently on loan.", book.checkIn());
3438
}

0 commit comments

Comments
 (0)