|
Here is the solution for the assignment. Note that overdue book, send reminder, pay fine are implemented, but unregister user not.
Assignment: Library Application
The assignment for today is to continue with assignments one and two. If you are done with those, here are more features to implement
- Overdue book: A book is overdue if it is borrowed for more than 28 days (4 weeks). A user with an overdue book For each overdue book the user has to pay a fine of 100 DKK.
The challenge of "Overdue book" is, that it requires to "manipulate" time. That is, to advance the date by 29 days to make the book overdue. Here is some help of implementing the feature.
- Send reminder: The administrator can choose to send an e-mail reminder to all those users who have overdue books. The subject of the e-mail should be "Overdue book(s)" and the text should be ""You have n overdue book(s)", where n is the number of overdue books, the user has.
It would be rather unpractical to really send e-mails to the e-mail addresses of the test users. Instead, the same technology as for "Overdue book" should be used. The library application uses an e-mail server. In our implementation, the real e-mail server will just write to the console that it is sending a message to the user. In testing, the e-mail server be replaced by a mock object that records the message it is sent to it. Then the test can check, that the message indead was sent from the library application. Here are more hints implementing these tests.
- Borrow book: A user cannot borrow a book, if he has any overdue books. The user also cannot borrow a book, if he does not have overdue books, but has not yet paid his fine for his overdue books.
- Pay fine: A user, who has to pay a fine for overdue books, pays the fine. It is possible for the user to only pay part of the fine; however, without having paid all the fine, he cannot borrow more books
- Unregister user: The administrator (and only the administrator) can unregister users. Note, users that have borrwoed books or outstanding fines, cannot be unregistered.
Assignment: Systematic Tests
Given the following code that tests whether a number a is prime or not. A number is prime, if it is greater than 1 and only dividiable by itself or 1.
public class Primes {
public static boolean isPrime(int n) {
if (n <= 1) { // 1
return false; // 1a
}
for (int i = 2; i < n; i++ ) { // 2
if (n % i != 0) { // 3
return false; // 3a
}
}
return true; // 4
}
}
- Devise a set of white-box/structural partition tests for this method using two tables (similar to what we have done in the lecture). The first table describes the input partitions, and the second table describes the test cases.
- Implement the class Primes and the JUnit tests corresponding to the table of the test cases from part $a$ of this exercise.
- What is the code coverage for the isPrime method reported by EclEmma?
- Do the tests pass? If not, fix the code and create new partition tests and implement them in JUnit. Note that, since the partition tests are based on the code, you have to create new partition tests, when the code changes!
- Submit the Eclipse project as Zip file to huba@dtu.dk
|