@@ -7,19 +7,10 @@ | |||
<version>1.0</version> | |||
<name>LibrarySystem</name> | |||
<url>http://maven.apache.org</url> | |||
<properties> | |||
<kotlin.version>1.1.3-2</kotlin.version> | |||
</properties> | |||
<dependencies> | |||
<dependency> | |||
<groupId>junit</groupId> | |||
<artifactId>junit</artifactId> | |||
<version>3.8.1</version> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.json</groupId> | |||
<artifactId>org.json</artifactId> | |||
@@ -41,6 +32,17 @@ | |||
<artifactId>forms_rt</artifactId> | |||
<version>7.0.3</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.junit.jupiter</groupId> | |||
<artifactId>junit-jupiter-api</artifactId> | |||
<version>RELEASE</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>junit</groupId> | |||
<artifactId>junit</artifactId> | |||
<version>4.12</version> | |||
<scope>test</scope> | |||
</dependency> | |||
</dependencies> | |||
<build> | |||
<plugins> | |||
@@ -55,7 +57,6 @@ | |||
</goals> | |||
</execution> | |||
</executions> | |||
<configuration> | |||
<fork>true</fork> | |||
<debug>true</debug> | |||
@@ -122,6 +123,7 @@ | |||
<configuration> | |||
<sourceDirs> | |||
<source>src/test/java</source> | |||
<source>src/test/kotlin</source> | |||
</sourceDirs> | |||
</configuration> | |||
</execution> | |||
@@ -1,127 +0,0 @@ | |||
package libsys; | |||
import junit.framework.Test; | |||
import junit.framework.TestCase; | |||
import junit.framework.TestSuite; | |||
/** | |||
* Test Book related operations | |||
*/ | |||
public class BookTest extends TestCase | |||
{ | |||
private Book book1; | |||
private Book book2; | |||
/** | |||
* Test Book related operations | |||
* @param testName name of the test case | |||
*/ | |||
public BookTest(String testName) | |||
{ | |||
super(testName); | |||
} | |||
/** | |||
* @return suite of tests being tested | |||
*/ | |||
public static Test suite() | |||
{ | |||
return new TestSuite(BookTest.class); | |||
} | |||
/** | |||
* Run all tests | |||
*/ | |||
public void testApp() | |||
{ | |||
valueTest(); | |||
rentTest(); | |||
returnTest(); | |||
setTitlesTest(); | |||
constructorTest(); | |||
} | |||
/** | |||
* Set up before testing | |||
* @throws Exception Exception | |||
*/ | |||
public void setUp() throws Exception | |||
{ | |||
super.setUp(); | |||
book1 = new Book("Book1", 10, "AVAILABLE"); | |||
book2 = new Book("Book2", 12, "NOT AVAILABLE"); | |||
} | |||
/** | |||
* Test if the values are accurate | |||
*/ | |||
private void valueTest() | |||
{ | |||
assertEquals("Title is \"Book1\"", book1.getTitle(), "Book1"); | |||
assertEquals("Status is \"AVAILABLE\"", book1.getStatus(), "AVAILABLE"); | |||
assertEquals("Book id is 10", book1.getId(), 10); | |||
assertEquals("Title is \"Book2\"", book2.getTitle(), "Book2"); | |||
assertEquals("Status is \"NOT AVAILABLE\"", book2.getStatus(), "NOT AVAILABLE"); | |||
assertEquals("Book id is 12", book2.getId(), 12); | |||
} | |||
/** | |||
* Test the rent(int[]) function functionality | |||
*/ | |||
private void rentTest() | |||
{ | |||
int[] date = new int[]{2018, 10, 5}; | |||
assertTrue("Rent should be successful", book1.rent(date)); | |||
assertEquals("Book status is \"RENTED\"", book1.getStatus(), "RENTED"); | |||
assertEquals("Book due date is 2018/10/5",book1.getDueDate(), date); | |||
assertFalse("Book2 is not rent-able", book2.rent(date)); | |||
} | |||
/** | |||
* Test the returned() function functionality | |||
*/ | |||
private void returnTest() | |||
{ | |||
book1.returned(); | |||
assertTrue("Book1 is \"AVAILABLE\"", book1.getStatus().equals("AVAILABLE")); | |||
} | |||
/** | |||
* Test the setTitles(String) functionality | |||
*/ | |||
private void setTitlesTest() | |||
{ | |||
String newBook1Title = "New Book 1"; | |||
book1.setTitle(newBook1Title); | |||
assertEquals("Title is \"New Book 1\"", book1.getTitle(), newBook1Title); | |||
String newBook2Title = "New Book 2"; | |||
book2.setTitle(newBook2Title); | |||
assertEquals("Title is \"New Book 2\"", book2.getTitle(), newBook2Title); | |||
} | |||
/** | |||
* Test the functionality for all different types of constructor | |||
*/ | |||
private void constructorTest() | |||
{ | |||
Book testBook1 = new Book(10); | |||
Book testBook2 = new Book("Test Title", 20, "RESERVED"); | |||
Book testBook3 = new Book(15, "Test Title 2", "RENTED", (new int[]{2019, 3, 23})); | |||
assertEquals("Book name is \"UNDEFINED\"", testBook1.getTitle(), "UNDEFINED"); | |||
assertEquals("Book1 id is 10", testBook1.getId(), 10); | |||
assertEquals("Book1 status is \"NOT AVAILABLE\"", testBook1.getStatus(), "NOT AVAILABLE"); | |||
assertEquals("Book2 title is \"Test Title\"", testBook2.getTitle(), "Test Title"); | |||
assertEquals("Book2 id is 20", testBook2.getId(), 20); | |||
assertEquals("Book2 status is \"RESERVED\"", testBook2.getStatus(), "RESERVED"); | |||
assertEquals("Book3 title is \"Test Title 2\"", testBook3.getTitle(), "Test Title 2"); | |||
assertEquals("Book3 id is 15", testBook3.getId(), 15); | |||
assertEquals("Book3 status is \"RENTED\"", testBook3.getStatus(), "RENTED"); | |||
int[] dueDate = testBook3.getDueDate(); | |||
assertEquals("Book3 due date year is 2019", dueDate[0], 2019); | |||
assertEquals("Book3 due date month is 3", dueDate[1], 3); | |||
assertEquals("Book3 due date day is 23", dueDate[2], 23); | |||
} | |||
} |
@@ -1,109 +0,0 @@ | |||
package libsys; | |||
import junit.framework.Test; | |||
import junit.framework.TestCase; | |||
import junit.framework.TestSuite; | |||
import java.util.ArrayList; | |||
/** | |||
* Test User related operations | |||
*/ | |||
public class UserTest extends TestCase | |||
{ | |||
private User user1; | |||
private User user2; | |||
/** | |||
* Test User related operations | |||
* @param testName name of the test case | |||
*/ | |||
public UserTest(String testName) | |||
{ | |||
super(testName); | |||
} | |||
/** | |||
* @return suite of the tests being tested | |||
*/ | |||
public static Test suite() | |||
{ | |||
return new TestSuite(UserTest.class); | |||
} | |||
/** | |||
* Run all tests | |||
*/ | |||
public void testApp() | |||
{ | |||
valueTest(); | |||
setterTest(); | |||
bookInteractionTest(); | |||
} | |||
/** | |||
* Set up before testing | |||
* @throws Exception Exception | |||
*/ | |||
public void setUp() throws Exception | |||
{ | |||
super.setUp(); | |||
user1 = new User("User1", 0, 10, new ArrayList<Integer>()); | |||
ArrayList<Integer> user2List = new ArrayList<Integer>(); | |||
user2List.add(0); | |||
user2 = new User("User2", 2, 8, user2List); | |||
} | |||
/** | |||
* Test if the values are accurate | |||
*/ | |||
private void valueTest() | |||
{ | |||
assertEquals("Name is \"User1\"", user1.getName(), "User1"); | |||
assertEquals("id is 0", user1.getId(), 0); | |||
assertEquals("Limit is 10", user1.getLimit(), 10); | |||
int[] bookIds = user1.bookStatus(); | |||
assertEquals("Book list is empty", bookIds.length, 0); | |||
assertEquals("Name is \"User2\"", user2.getName(), "User2"); | |||
assertEquals("id is 2", user2.getId(), 2); | |||
assertEquals("Limit is 8", user2.getLimit(), 8); | |||
bookIds = user2.bookStatus(); | |||
assertEquals("Book list is empty", bookIds.length, 1); | |||
assertEquals("Book id is 0", bookIds[0], 0); | |||
} | |||
/** | |||
* Test the setter functions | |||
*/ | |||
private void setterTest() | |||
{ | |||
String newName = "New User 1"; | |||
user1.setName(newName); | |||
assertEquals("New name for User1 is \"New User 1\"", user1.getName(), newName); | |||
user1.setLimit(1); | |||
assertEquals("New limit for User1 is 8", user1.getLimit(), 1); | |||
newName = "New User 2"; | |||
user2.setName(newName); | |||
assertEquals("New name for User2 is \"New User 2\"", user2.getName(), newName); | |||
user2.setLimit(3); | |||
assertEquals("New limit for User2 is 3", user2.getLimit(), 3); | |||
} | |||
/** | |||
* Test all functions related to Book | |||
*/ | |||
private void bookInteractionTest() | |||
{ | |||
assertTrue(user1.borrowNewBook(3)); | |||
int[] bookIds = user1.bookStatus(); | |||
assertEquals("User1 is now borrowing Book3", bookIds[0], 3); | |||
assertFalse("User1 reached the limit", user1.status()); | |||
assertFalse("User1 fail to borrow another book", user1.borrowNewBook(5)); | |||
assertFalse("User1 failed to return Book2 that was not borrowed", user1.returnBook(2)); | |||
assertTrue("User1 return Book3", user1.returnBook(3)); | |||
assertTrue("User1 can now borrow book", user1.status()); | |||
assertEquals("User1 is not borrowing anything", user1.bookStatus().length, 0); | |||
} | |||
} |
@@ -0,0 +1,71 @@ | |||
package libsys | |||
import org.junit.* | |||
/** | |||
* Test Book related operations | |||
*/ | |||
class BookTest | |||
{ | |||
private var book1: Book? = null | |||
private var book2: Book? = null | |||
/** | |||
* Set up before testing | |||
*/ | |||
@Before fun prepareTest() | |||
{ | |||
book1 = Book("Book1", 10, "AVAILABLE") | |||
book2 = Book("Book2", 12, "NOT AVAILABLE") | |||
} | |||
/** | |||
* Test Book related operations | |||
*/ | |||
@Test fun bookTest() | |||
{ | |||
Assert.assertEquals("Title is \"Book1\"", book1!!.title, "Book1") | |||
Assert.assertEquals("Status is \"AVAILABLE\"", book1!!.status, "AVAILABLE") | |||
Assert.assertEquals("Book id is 10", book1!!.id, 10) | |||
Assert.assertEquals("Title is \"Book2\"", book2!!.title, "Book2") | |||
Assert.assertEquals("Status is \"NOT AVAILABLE\"", book2!!.status, "NOT AVAILABLE") | |||
Assert.assertEquals("Book id is 12", book2!!.id, 12) | |||
val date = intArrayOf(2018, 10, 5) | |||
Assert.assertTrue("Rent should be successful", book1!!.rent(date)) | |||
Assert.assertEquals("Book status is \"RENTED\"", book1!!.status, "RENTED") | |||
Assert.assertEquals("Book due date is 2018/10/5", book1!!.dueDate, date) | |||
Assert.assertFalse("Book2 is not rent-able", book2!!.rent(date)) | |||
book1!!.returned() | |||
Assert.assertTrue("Book1 is \"AVAILABLE\"", book1!!.status == "AVAILABLE") | |||
val newBook1Title = "New Book 1" | |||
book1!!.title = newBook1Title | |||
Assert.assertEquals("Title is \"New Book 1\"", book1!!.title, newBook1Title) | |||
val newBook2Title = "New Book 2" | |||
book2!!.title = newBook2Title | |||
Assert.assertEquals("Title is \"New Book 2\"", book2!!.title, newBook2Title) | |||
val testBook1 = Book(10) | |||
val testBook2 = Book("Test Title", 20, "RESERVED") | |||
val testBook3 = Book(15, "Test Title 2", "RENTED", intArrayOf(2019, 3, 23)) | |||
Assert.assertEquals("Book name is \"UNDEFINED\"", testBook1.title, "UNDEFINED") | |||
Assert.assertEquals("Book1 id is 10", testBook1.id, 10) | |||
Assert.assertEquals("Book1 status is \"NOT AVAILABLE\"", testBook1.status, "NOT AVAILABLE") | |||
Assert.assertEquals("Book2 title is \"Test Title\"", testBook2.title, "Test Title") | |||
Assert.assertEquals("Book2 id is 20", testBook2.id, 20) | |||
Assert.assertEquals("Book2 status is \"RESERVED\"", testBook2.status, "RESERVED") | |||
Assert.assertEquals("Book3 title is \"Test Title 2\"", testBook3.title, "Test Title 2") | |||
Assert.assertEquals("Book3 id is 15", testBook3.id, 15) | |||
Assert.assertEquals("Book3 status is \"RENTED\"", testBook3.status, "RENTED") | |||
val dueDate = testBook3.dueDate | |||
Assert.assertEquals("Book3 due date year is 2019", dueDate[0], 2019) | |||
Assert.assertEquals("Book3 due date month is 3", dueDate[1], 3) | |||
Assert.assertEquals("Book3 due date day is 23", dueDate[2], 23) | |||
} | |||
} |
@@ -0,0 +1,62 @@ | |||
package libsys | |||
import org.junit.* | |||
import java.util.ArrayList | |||
/** | |||
* Test User related operations | |||
*/ | |||
class UserTest | |||
{ | |||
private var user1: User? = null | |||
private var user2: User? = null | |||
@Before fun prepareTest() | |||
{ | |||
user1 = User("User1", 0, 10, ArrayList<Int>()) | |||
val user2List = ArrayList<Int>() | |||
user2List.add(0) | |||
user2 = User("User2", 2, 8, user2List) | |||
} | |||
/** | |||
* Test User related operations | |||
*/ | |||
@Test fun userTest() | |||
{ | |||
Assert.assertEquals("Name is \"User1\"", user1!!.name, "User1") | |||
Assert.assertEquals("id is 0", user1!!.id, 0) | |||
Assert.assertEquals("Limit is 10", user1!!.limit, 10) | |||
var bookIds: IntArray = user1!!.bookStatus() | |||
Assert.assertEquals("Book list is empty", bookIds.size, 0) | |||
Assert.assertEquals("Name is \"User2\"", user2!!.name, "User2") | |||
Assert.assertEquals("id is 2", user2!!.id, 2) | |||
Assert.assertEquals("Limit is 8", user2!!.limit, 8) | |||
bookIds = user2!!.bookStatus() | |||
Assert.assertEquals("Book list is empty", bookIds.size, 1) | |||
Assert.assertEquals("Book id is 0", bookIds[0], 0) | |||
var newName = "New User 1" | |||
user1!!.name = newName | |||
Assert.assertEquals("New name for User1 is \"New User 1\"", user1!!.name, newName) | |||
user1!!.limit = 1 | |||
Assert.assertEquals("New limit for User1 is 8", user1!!.limit, 1) | |||
newName = "New User 2" | |||
user2!!.name = newName | |||
Assert.assertEquals("New name for User2 is \"New User 2\"", user2!!.name, newName) | |||
user2!!.limit = 3 | |||
Assert.assertEquals("New limit for User2 is 3", user2!!.limit, 3) | |||
Assert.assertTrue(user1!!.borrowNewBook(3)) | |||
bookIds = user1!!.bookStatus() | |||
Assert.assertEquals("User1 is now borrowing Book3", bookIds[0], 3) | |||
Assert.assertFalse("User1 reached the limit", user1!!.status()) | |||
Assert.assertFalse("User1 fail to borrow another book", user1!!.borrowNewBook(5)) | |||
Assert.assertFalse("User1 failed to return Book2 that was not borrowed", user1!!.returnBook(2)) | |||
Assert.assertTrue("User1 return Book3", user1!!.returnBook(3)) | |||
Assert.assertTrue("User1 can now borrow book", user1!!.status()) | |||
Assert.assertEquals("User1 is not borrowing anything", user1!!.bookStatus().size, 0) | |||
} | |||
} |