Skip to content
Snippets Groups Projects
Commit 404c84aa authored by tmnaqeesha's avatar tmnaqeesha
Browse files

fix: Clean code and improve comments

parent a0a36728
No related branches found
No related tags found
1 merge request!5Merge code for Iteration 2 with main
...@@ -125,12 +125,6 @@ public class SocialNetwork implements ISocialNetwork { ...@@ -125,12 +125,6 @@ public class SocialNetwork implements ISocialNetwork {
if(title == null || title.length() <= 1 ){ if(title == null || title.length() <= 1 ){
throw new BadEntryException("title is null or empty"); throw new BadEntryException("title is null or empty");
} }
// for(Book b : listBook) {
// if(title.toUpperCase().trim().equals(book.getTitle().toUpperCase().trim())) {
// result = true;
// }
// }
// return result;
for (Book b : listBook) { for (Book b : listBook) {
if (b.compareTitle(title)) { if (b.compareTitle(title)) {
return true; return true;
...@@ -191,29 +185,11 @@ public class SocialNetwork implements ISocialNetwork { ...@@ -191,29 +185,11 @@ public class SocialNetwork implements ISocialNetwork {
throw new ItemBookAlreadyExistsException(); throw new ItemBookAlreadyExistsException();
} }
} }
Book newBook = new Book(title.trim(), kind.trim(), author.trim(), nbPages); book = new Book(title.trim(), kind.trim(), author.trim(), nbPages);
listBook.add(newBook); listBook.add(book);
nbbooks++; nbbooks++;
} }
// public void addItemBook(String login, String password, String title,
// String kind, String author, int nbPages) throws BadEntryException,
// NotMemberException, ItemBookAlreadyExistsException {
// if (validateuser(login,password)){
// if (!memberRegister(login)) {
// throw new NotMemberException("This user does not exist");
//
// }
// if (validatebook(title)) {
// throw new ItemBookAlreadyExistsException();
// }
// else{
// book = new Book(title, kind, author, nbPages);
// listBook.add(book);
// }
// }
// }
@Override @Override
public void addItemFilm(String login, String password, String title, String kind, String director, String scriptwriter, int duration) public void addItemFilm(String login, String password, String title, String kind, String director, String scriptwriter, int duration)
throws BadEntryException, NotMemberException, ItemFilmAlreadyExistsException { throws BadEntryException, NotMemberException, ItemFilmAlreadyExistsException {
...@@ -241,7 +217,6 @@ public class SocialNetwork implements ISocialNetwork { ...@@ -241,7 +217,6 @@ public class SocialNetwork implements ISocialNetwork {
counter++; counter++;
} }
return ret.trim(); return ret.trim();
//return (listMember.toString());
} }
@Override @Override
......
...@@ -17,25 +17,16 @@ public class AddItemBookTest { ...@@ -17,25 +17,16 @@ public class AddItemBookTest {
* Check that the method addItemBook throws BadEntryException or NotMemberException correctly. * Check that the method addItemBook throws BadEntryException or NotMemberException correctly.
* If OK, the method just returns 0. If not OK, displays an error message and returns 1. * If OK, the method just returns 0. If not OK, displays an error message and returns 1.
* *
* @param sn * @param sn the <i>ISocialNetwork</i>
* - the <i>ISocialNetwork</i> * @param login the login of the member
* @param login * @param password the password of the member
* - login of the member * @param title the title of the book
* @param password * @param kind the kind of the book
* - password of the member * @param author the author of the book
* @param title * @param nbPages the page number of the book
* - title of the book * @param expectedException the expected exception class
* @param kind * @param testId the test ID
* - kind of the book * @return 0 if test is OK, 1 if not OK
* @param author
* - author of the book
* @param nbPages
* - number of pages of the book
* @param expectedException
* - the expected exception class
* @param testId
* - the test ID that will prefix any error message displayed by this method
* @return 0 if the test is OK, 1 if not
*/ */
private static int checkAddItemBookException(ISocialNetwork sn, String login, String password, String title, String kind, String author, int nbPages, Class<?> expectedException, String testId) { private static int checkAddItemBookException(ISocialNetwork sn, String login, String password, String title, String kind, String author, int nbPages, Class<?> expectedException, String testId) {
try { try {
...@@ -57,23 +48,15 @@ public class AddItemBookTest { ...@@ -57,23 +48,15 @@ public class AddItemBookTest {
* Check that the method addItemBook succeeds. * Check that the method addItemBook succeeds.
* If OK, the method just returns 0. If not OK, displays an error message and returns 1. * If OK, the method just returns 0. If not OK, displays an error message and returns 1.
* *
* @param sn * @param sn the <i>ISocialNetwork</i>
* - the <i>ISocialNetwork</i> * @param login the login of the member
* @param login * @param password the password of the member
* - login of the member * @param title the title of the book
* @param password * @param kind the kind of the book
* - password of the member * @param author the author of the book
* @param title * @param nbPages the number of pages of the book
* - title of the book * @param testId the test's ID
* @param kind * @return 0 if test is OK, 1 if not OK
* - kind of the book
* @param author
* - author of the book
* @param nbPages
* - number of pages of the book
* @param testId
* - the test ID that will prefix any error message displayed by this method
* @return 0 if the test is OK, 1 if not
*/ */
private static int checkAddItemBookSuccess(ISocialNetwork sn, String login, String password, String title, String kind, String author, int nbPages, String testId) { private static int checkAddItemBookSuccess(ISocialNetwork sn, String login, String password, String title, String kind, String author, int nbPages, String testId) {
try { try {
...@@ -88,10 +71,8 @@ public class AddItemBookTest { ...@@ -88,10 +71,8 @@ public class AddItemBookTest {
/** /**
* Main test for addItemBook: * Main test for addItemBook:
* <ul> * Checks if the method throws BadEntryException or NotMemberException in non-nominal conditions
* <li>check if the method throws BadEntryException or NotMemberException in non-nominal conditions</li> * Checks if the method works correctly in nominal conditions
* <li>check if the method works correctly in nominal conditions</li>
* </ul>
* *
* @return a summary of the performed tests * @return a summary of the performed tests
*/ */
...@@ -112,45 +93,45 @@ public class AddItemBookTest { ...@@ -112,45 +93,45 @@ public class AddItemBookTest {
// Non-nominal scenarios // Non-nominal scenarios
// Scenario 1: Invalid login (empty) // Test 2.1 : Invalid login (empty)
nbTests++; nbTests++;
nbErrors += checkAddItemBookException(sn, "", "passwordtest1", "New Book", "Comedy", "Juan Perez", 300, BadEntryException.class, "2.1"); nbErrors += checkAddItemBookException(sn, "", "passwordtest1", "New Book", "Comedy", "Juan Perez", 300, BadEntryException.class, "2.1");
// Scenario 2: Invalid password(less than 8 characters) // Test 2.2 : Invalid password(less than 8 characters)
nbTests++; nbTests++;
nbErrors += checkAddItemBookException(sn, "usertest", "abc", "New Book", "Comedy", "Juan Perez", 300, BadEntryException.class, "2.2"); nbErrors += checkAddItemBookException(sn, "usertest", "abc", "New Book", "Comedy", "Juan Perez", 300, BadEntryException.class, "2.2");
// Scenario 3: Invalid title (empty) // Test 2.3 : Invalid title (empty)
nbTests++; nbTests++;
nbErrors += checkAddItemBookException(sn, "usertest", "passwordtest1", "", "Comedy", "Juan Perez", 300, BadEntryException.class, "2.3"); nbErrors += checkAddItemBookException(sn, "usertest", "passwordtest1", "", "Comedy", "Juan Perez", 300, BadEntryException.class, "2.3");
// Scenario 4: Uninstantiated kind // Test 2.4 : Uninstantiated kind
nbTests++; nbTests++;
nbErrors += checkAddItemBookException(sn, "usertest", "passwordtest1", "New Book", null, "Juan Perez", 300, BadEntryException.class, "2.4"); nbErrors += checkAddItemBookException(sn, "usertest", "passwordtest1", "New Book", null, "Juan Perez", 300, BadEntryException.class, "2.4");
// Scenario 5: Uninstantiated author // Test 2.5 : Uninstantiated author
nbTests++; nbTests++;
nbErrors += checkAddItemBookException(sn, "usertest", "passwordtest1", "New Book", "Comedy", null, 300, BadEntryException.class, "2.5"); nbErrors += checkAddItemBookException(sn, "usertest", "passwordtest1", "New Book", "Comedy", null, 300, BadEntryException.class, "2.5");
// Scenario 6: Invalid number of pages (not strictly positive) // Test 2.6 : Invalid number of pages (not strictly positive)
nbTests++; nbTests++;
nbErrors += checkAddItemBookException(sn, "usertest", "passwordtest1", "New Book", "Comedy", "Juan Perez", 0, BadEntryException.class, "2.6"); nbErrors += checkAddItemBookException(sn, "usertest", "passwordtest1", "New Book", "Comedy", "Juan Perez", 0, BadEntryException.class, "2.6");
// Scenario 7: Non-existent member // Test 2.7 : Non-existent member
nbTests++; nbTests++;
nbErrors += checkAddItemBookException(sn, "nonExistentUser", "passwordtest1", "New Book", "Comedy", "Juan Perez", 300, NotMemberException.class, "2.7"); nbErrors += checkAddItemBookException(sn, "nonExistentUser", "passwordtest1", "New Book", "Comedy", "Juan Perez", 300, NotMemberException.class, "2.7");
// Scenario 8: Invalid password(null) // Test 2.8 : Invalid password(null)
nbTests++; nbTests++;
nbErrors += checkAddItemBookException(sn, "usertest", "", "New Book", "Comedy", "Juan Perez", 300, BadEntryException.class, "2.8"); nbErrors += checkAddItemBookException(sn, "usertest", "", "New Book", "Comedy", "Juan Perez", 300, BadEntryException.class, "2.8");
// Nominal scenarios // Nominal scenarios
// Scenario 1: Valid book addition // Test 2.9 : Valid book addition
nbTests++; nbTests++;
nbErrors += checkAddItemBookSuccess(sn, "usertest", "passwordtest1", "Effective Java", "Programming", "Joshua Bloch", 416, "2.9"); nbErrors += checkAddItemBookSuccess(sn, "usertest", "passwordtest1", "Effective Java", "Programming", "Joshua Bloch", 416, "2.9");
// Scenario 2: Adding an existing book // Test 2.10 : Add an existing book
nbTests++; nbTests++;
nbErrors += checkAddItemBookException(sn, "usertest", "passwordtest1", "Effective Java", "Programming", "Jose Pablo", 416, ItemBookAlreadyExistsException.class, "2.10"); nbErrors += checkAddItemBookException(sn, "usertest", "passwordtest1", "Effective Java", "Programming", "Jose Pablo", 416, ItemBookAlreadyExistsException.class, "2.10");
...@@ -159,7 +140,7 @@ public class AddItemBookTest { ...@@ -159,7 +140,7 @@ public class AddItemBookTest {
TestReport tr = new TestReport(nbTests, nbErrors); TestReport tr = new TestReport(nbTests, nbErrors);
System.out.println("AddItemBookTest : " + tr); System.out.println("AddItemBookTest : " + tr);
return tr; return tr;
} catch (NotTestReportException e) { // This shouldn't happen } catch (NotTestReportException e) {
System.out.println("Unexpected error in AddItemBookTest test code - Can't return valuable test results"); System.out.println("Unexpected error in AddItemBookTest test code - Can't return valuable test results");
return null; return null;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment