diff --git a/src/opinion/Book.java b/src/opinion/Book.java index e2b8f614fd08a75639f3b5c6bca1b79be9d674a4..36e2095fc2059336b39df360bbfdb4485f114e83 100644 --- a/src/opinion/Book.java +++ b/src/opinion/Book.java @@ -1,16 +1,24 @@ package opinion; /** - * This class allows us to create books and to register new books + * <h3>A class that allows us to create books and to register new books</h3> + * + * @author Maryam TENGKU + * @author Neva MASSY + * @version 1.0 + * @since 1.0 */ public class Book { - //Declaration of private class variables + /** + * Declaration of private class variables : book title, kind and author + */ + private String title, kind, author, comment; private int nbPages; /** - * Initialization of private variables with constructor + * <b>Initialization of private variables with constructor</b> * * @param title The title of the book * @param kind The type of the book @@ -25,7 +33,7 @@ public class Book { } /** - * Return the title of the book + * <b>Return the title of the book</b> * * @return book's title */ @@ -34,7 +42,7 @@ public class Book { } /** - * Return the kind of the book + * <b>Return the kind of the book</b> * * @return book's kind */ @@ -43,7 +51,7 @@ public class Book { } /** - * Retrieve the author of the book + * <b>Retrieve the author of the book</b> * * @return book's author */ @@ -52,7 +60,7 @@ public class Book { } /** - * Return the number of pages of the book + * <b>Return the number of pages of the book</b> * * @return book's page number */ @@ -61,7 +69,7 @@ public class Book { } /** - * Identify if the current book's title is similar as another book + * <b>Identify if the current book's <i>title</i> is similar as another book</b> * * @param title2 other's book's title * @return true if same, false if different @@ -73,7 +81,7 @@ public class Book { } /** - * String function to display the details of a book + * <b>String function to display the details of a book</b> * * @return the book's details */ diff --git a/src/opinion/Member.java b/src/opinion/Member.java index 76fd06354008ef4adcac7f14c4273351d97c75a8..56235f81661705bd977325aa99e2f1522b8e71d7 100644 --- a/src/opinion/Member.java +++ b/src/opinion/Member.java @@ -2,8 +2,8 @@ package opinion; /** - * This class allows us to create and register new members - * A member has a login, a password and a profile that he has to register before connecting to the site + * <h3>A class that allows us to create and register new members</h3> + * A member has a <i>login</i>, a ,<i>password</i> and a <i>profile</i> that they have to register before connecting to the site * * @author Maryam TENGKU * @author Neva MASSY @@ -13,12 +13,12 @@ package opinion; public class Member { /** - * Declaration of member's login, password and profile. + * Declaration of private class variables : member's login, password and profile. */ private String login, password, profile; /** - * Construct new Member with specified login, password and profile. + * <b>Construct new Member with specified login, password and profile.</b> * * @param login member's login * @param password member's password @@ -31,7 +31,7 @@ public class Member { } /** - * Returns member's login + * <b>Returns member's login</b> * * @return login */ @@ -40,7 +40,7 @@ public class Member { } /** - * Returns member's password + * <b>Returns member's password</b> * * @return password */ @@ -50,7 +50,7 @@ public class Member { /** - * Returns member's profile + * <b>Returns member's profile</b> * * @return profile */ @@ -60,7 +60,7 @@ public class Member { /** - * String function to display details of a member (login and profile) + * <b>String function to display details of a member (<i>login</i> and <i>profile</i>)</b> * * @return string of details of a member */ diff --git a/src/tests/AddMemberTest.java b/src/tests/AddMemberTest.java index 843a66c1a621b1184452f73f4c9a7d86714f67b0..1311e4bb263b81cdfaf8f9d7f078eb9dd19c3851 100644 --- a/src/tests/AddMemberTest.java +++ b/src/tests/AddMemberTest.java @@ -10,332 +10,314 @@ import exceptions.NotTestReportException; /** * Tests for the SocialNetwork.<i>addMember()</i> method. - * + * * @author B. Prou, E. Cousin, GO * @version V2.0 - April 2018 */ public class AddMemberTest { - /** - * Check that trying to add this new member (login, pwd, profile) raises a - * BadEntry exception and does not change content of the - * <i>ISocialNetwork</i>. If OK, the method just returns 0. If not OK, - * displays an error message and returns 1. - * - * @param sn - * - the <i>ISocialNetwork</i> - * @param login - * - new member's login - * @param pwd - * - new member's password - * @param profile - * - new member's profile - * @param testId - * - the test ID that will prefix any error message displayed by - * this method - * @param errorMessage - * - the error message that will be displayed if no exception is - * thrown when adding this member - * @return 0 if the test is OK, 1 if not - */ - private static int addMemberBadEntryTest(ISocialNetwork sn, String login, - String pwd, String profile, String testId, String errorMessage) { + /** + * Check that trying to add this new member (login, pwd, profile) raises a + * BadEntry exception and does not change content of the + * <i>ISocialNetwork</i>. If OK, the method just returns 0. If not OK, + * displays an error message and returns 1. + * + * @param sn - the <i>ISocialNetwork</i> + * @param login - new member's login + * @param pwd - new member's password + * @param profile - new member's profile + * @param testId - the test ID that will prefix any error message displayed by + * this method + * @param errorMessage - the error message that will be displayed if no exception is + * thrown when adding this member + * @return 0 if the test is OK, 1 if not + */ + private static int addMemberBadEntryTest(ISocialNetwork sn, String login, + String pwd, String profile, String testId, String errorMessage) { - int nbMembers = sn.nbMembers(); // Number of members when starting to - // run this method - try { - sn.addMember(login, pwd, profile); // Try to add this member - // Reaching this point means that no exception was thrown by - // addMember() - System.out.println("Err " + testId + " : " + errorMessage); // display - // the - // error - // message - return 1; // and return the "error" value - } catch (BadEntryException e) { // BadEntry exception was thrown by - // addMember() : this is a good start! - // Let's now check if 'sn' was not - // impacted - if (sn.nbMembers() != nbMembers) { // The number of members has - // changed : this is an error - // case. - System.out - .println("Err " - + testId - + " : BadEntry was thrown but the number of members was changed"); // Display - // a - // specific - // error - // message - return 1; // return "error" value - } else - // The number of members hasn't changed, which is considered a - // good indicator that 'sn' was not modified - return 0; // return success value : everything seems OK, nothing - // to display - } catch (Exception e) { // An exception was thrown by addMember(), but - // it was not the expected exception BadEntry - System.out.println("Err " + testId + " : unexpected exception. " - + e); // Display a specific error message - e.printStackTrace(); // Display contextual info about what happened - return 1; // return error value - } - } + int nbMembers = sn.nbMembers(); // Number of members when starting to + // run this method + try { + sn.addMember(login, pwd, profile); // Try to add this member + // Reaching this point means that no exception was thrown by + // addMember() + System.out.println("Err " + testId + " : " + errorMessage); // display + // the + // error + // message + return 1; // and return the "error" value + } catch (BadEntryException e) { // BadEntry exception was thrown by + // addMember() : this is a good start! + // Let's now check if 'sn' was not + // impacted + if (sn.nbMembers() != nbMembers) { // The number of members has + // changed : this is an error + // case. + System.out + .println("Err " + + testId + + " : BadEntry was thrown but the number of members was changed"); // Display + // a + // specific + // error + // message + return 1; // return "error" value + } else + // The number of members hasn't changed, which is considered a + // good indicator that 'sn' was not modified + return 0; // return success value : everything seems OK, nothing + // to display + } catch (Exception e) { // An exception was thrown by addMember(), but + // it was not the expected exception BadEntry + System.out.println("Err " + testId + " : unexpected exception. " + + e); // Display a specific error message + e.printStackTrace(); // Display contextual info about what happened + return 1; // return error value + } + } - /** - * Check that trying to add this new member (login, pwd, profile) raises an - * AlreadyExists exception and does not change content of the - * <i>ISocialNetwork</i>. If OK, the method just returns 0. If not OK, - * displays an error message and returns 1. - * - * @param sn - * - the <i>ISocialNetwork</i> - * @param login - * - new member's login - * @param pwd - * - new member's password - * @param profile - * - new member's profile - * @param testId - * - the test ID that will prefix any error message displayed by - * this method - * @param errorMessage - * - the error message that will be displayed if no exception is - * thrown when adding this member - * @return 0 if the test is OK, 1 if not - */ - private static int addMemberAlreadyExistsTest(ISocialNetwork sn, - String login, String pwd, String profile, String testId, - String errorMessage) { - int nbMembers = sn.nbMembers(); // Number of members when starting to - // process this method - try { - sn.addMember(login, pwd, profile); // Try to add this member - // Reaching this point means that no exception was thrown by - // addMember() - System.out.println("Err " + testId + " : " + errorMessage); // display - // the - // error - // message - return 1; // and return the "error" value - } catch (MemberAlreadyExistsException e) {// AlreadyExists exception was - // thrown by addMember() : - // this is a good start! - // Let's now check if 'sn' - // was not impacted - if (sn.nbMembers() != nbMembers) { - System.out - .println("Err " - + testId - + " : MemberAlreadyExists was thrown, but the number of members was changed"); // Display - // a - // specific - // error - // message - return 1;// and return the "error" value - } else - return 0; // return success value : everything is OK, nothing to - // display - } catch (Exception e) { // An exception was thrown by addMember(), but - // it was not the expected exception - // AlreadyExists - System.out.println("Err " + testId + " : unexpected exception. " - + e); // Display a specific error message - e.printStackTrace(); // Display contextual info about what happened - return 1; // return error value - } - } + /** + * Check that trying to add this new member (login, pwd, profile) raises an + * AlreadyExists exception and does not change content of the + * <i>ISocialNetwork</i>. If OK, the method just returns 0. If not OK, + * displays an error message and returns 1. + * + * @param sn - the <i>ISocialNetwork</i> + * @param login - new member's login + * @param pwd - new member's password + * @param profile - new member's profile + * @param testId - the test ID that will prefix any error message displayed by + * this method + * @param errorMessage - the error message that will be displayed if no exception is + * thrown when adding this member + * @return 0 if the test is OK, 1 if not + */ + private static int addMemberAlreadyExistsTest(ISocialNetwork sn, + String login, String pwd, String profile, String testId, + String errorMessage) { + int nbMembers = sn.nbMembers(); // Number of members when starting to + // process this method + try { + sn.addMember(login, pwd, profile); // Try to add this member + // Reaching this point means that no exception was thrown by + // addMember() + System.out.println("Err " + testId + " : " + errorMessage); // display + // the + // error + // message + return 1; // and return the "error" value + } catch (MemberAlreadyExistsException e) {// AlreadyExists exception was + // thrown by addMember() : + // this is a good start! + // Let's now check if 'sn' + // was not impacted + if (sn.nbMembers() != nbMembers) { + System.out + .println("Err " + + testId + + " : MemberAlreadyExists was thrown, but the number of members was changed"); // Display + // a + // specific + // error + // message + return 1;// and return the "error" value + } else + return 0; // return success value : everything is OK, nothing to + // display + } catch (Exception e) { // An exception was thrown by addMember(), but + // it was not the expected exception + // AlreadyExists + System.out.println("Err " + testId + " : unexpected exception. " + + e); // Display a specific error message + e.printStackTrace(); // Display contextual info about what happened + return 1; // return error value + } + } - /** - * Check that this new member (login, pwd, profile) can be (and <i>is</i>) - * added to the <i>ISocialNetwork</i>.</br> If OK, the method just returns 0 - * : the new member was added.</br> If not OK, an error message is displayed - * and 1 is returned ; the new member was not correctly added. - * - * @param sn - * - the <i>ISocialNetwork</i> - * @param login - * - new member's login - * @param pwd - * - new member's password - * @param profile - * - new member's profile - * @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 addMemberOKTest(ISocialNetwork sn, String login, - String pwd, String profile, String testId) { - int nbMembers = sn.nbMembers(); // Number of members when starting to - // process this method - try { - sn.addMember(login, pwd, profile); // Try to add this member - // No exception was thrown. That's a good start ! - if (sn.nbMembers() != nbMembers + 1) { // But the number of members - // hasn't changed - // accordingly - System.out.println("Err " + testId - + " : the number of members (" + nbMembers - + ") was not incremented"); // Error message displayed - return 1; // return error code - } else - return 0; // return success code : everything is OK, nothing to - // display - } catch (Exception e) {// An exception was thrown by addMember() : this - // is an error case - System.out - .println("Err " + testId + " : unexpected exception " + e); // Error - // message - // displayed - e.printStackTrace(); // Display contextual info about what happened - return 1; // return error code - } - } + /** + * Check that this new member (login, pwd, profile) can be (and <i>is</i>) + * added to the <i>ISocialNetwork</i>.</br> If OK, the method just returns 0 + * : the new member was added.</br> If not OK, an error message is displayed + * and 1 is returned ; the new member was not correctly added. + * + * @param sn - the <i>ISocialNetwork</i> + * @param login - new member's login + * @param pwd - new member's password + * @param profile - new member's profile + * @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 addMemberOKTest(ISocialNetwork sn, String login, + String pwd, String profile, String testId) { + int nbMembers = sn.nbMembers(); // Number of members when starting to + // process this method + try { + sn.addMember(login, pwd, profile); // Try to add this member + // No exception was thrown. That's a good start ! + if (sn.nbMembers() != nbMembers + 1) { // But the number of members + // hasn't changed + // accordingly + System.out.println("Err " + testId + + " : the number of members (" + nbMembers + + ") was not incremented"); // Error message displayed + return 1; // return error code + } else + return 0; // return success code : everything is OK, nothing to + // display + } catch (Exception e) {// An exception was thrown by addMember() : this + // is an error case + System.out + .println("Err " + testId + " : unexpected exception " + e); // Error + // message + // displayed + e.printStackTrace(); // Display contextual info about what happened + return 1; // return error code + } + } - /** - * <i>addMember()</i> main test : - * <ul> - * <li>check if members can be added</li> - * <li>check if incorrect parameters cause addMember() to throw BadEntry - * exception</li> - * <li>check if adding already registered members cause addMember() to throw - * AlreadyExists exception</li> - * </ul> - * - * @return a summary of the performed tests - */ - public static TestReport test(){ + /** + * <i>addMember()</i> main test : + * <ul> + * <li>check if members can be added</li> + * <li>check if incorrect parameters cause addMember() to throw BadEntry + * exception</li> + * <li>check if adding already registered members cause addMember() to throw + * AlreadyExists exception</li> + * </ul> + * + * @return a summary of the performed tests + */ + public static TestReport test() { - ISocialNetwork sn = new SocialNetwork(); + ISocialNetwork sn = new SocialNetwork(); - int nbBooks = sn.nbBooks(); // number of books in 'sn' (should be 0 - // here) - int nbFilms = sn.nbFilms(); // number of films in 'sn' (should be 0 - // here) + int nbBooks = sn.nbBooks(); // number of books in 'sn' (should be 0 + // here) + int nbFilms = sn.nbFilms(); // number of films in 'sn' (should be 0 + // here) - int nbTests = 0; // total number of performed tests - int nbErrors = 0; // total number of failed tests + int nbTests = 0; // total number of performed tests + int nbErrors = 0; // total number of failed tests - System.out.println("Testing addMember()"); + System.out.println("Testing addMember()"); - // <=> test n°1 + // <=> test n°1 - // check if incorrect parameters cause addMember() to throw BadEntry - // exception + // check if incorrect parameters cause addMember() to throw BadEntry + // exception - nbTests++; - nbErrors += addMemberBadEntryTest(sn, null, "qsdfgh", "", "1.1", - "addMember() doesn't reject null logins"); - nbTests++; - nbErrors += addMemberBadEntryTest( - sn, - " ", - "qsdfgh", - "", - "1.2", - "addMember() doesn't reject logins that don't contain at least one character other than space"); - nbTests++; - nbErrors += addMemberBadEntryTest(sn, "B", null, "", "1.3", - "addMember() doesn't reject null passwords"); - nbTests++; - nbErrors += addMemberBadEntryTest( - sn, - "B", - " qwd ", - "", - "1.4", - "addMember() doesn't reject passwords that don't contain at least 4 characters (not taking into account leading or trailing blanks)"); - nbTests++; - nbErrors += addMemberBadEntryTest(sn, "BBBB", "bbbb", null, "1.5", - "addMember() doesn't reject null profiles"); + nbTests++; + nbErrors += addMemberBadEntryTest(sn, null, "qsdfgh", "", "1.1", + "addMember() doesn't reject null logins"); + nbTests++; + nbErrors += addMemberBadEntryTest( + sn, + " ", + "qsdfgh", + "", + "1.2", + "addMember() doesn't reject logins that don't contain at least one character other than space"); + nbTests++; + nbErrors += addMemberBadEntryTest(sn, "B", null, "", "1.3", + "addMember() doesn't reject null passwords"); + nbTests++; + nbErrors += addMemberBadEntryTest( + sn, + "B", + " qwd ", + "", + "1.4", + "addMember() doesn't reject passwords that don't contain at least 4 characters (not taking into account leading or trailing blanks)"); + nbTests++; + nbErrors += addMemberBadEntryTest(sn, "BBBB", "bbbb", null, "1.5", + "addMember() doesn't reject null profiles"); - // <=> test n°2 + // <=> test n°2 - // populate 'sn' with 3 members + // populate 'sn' with 3 members - nbTests++; - nbErrors += addMemberOKTest(sn, "Paul", "paul", "lecteur impulsif", - "2.1a"); - nbTests++; - nbErrors += addMemberOKTest(sn, "Antoine", "antoine", - "grand amoureux de la littérature", "2.1b"); - nbTests++; - nbErrors += addMemberOKTest(sn, "Alice", "alice", - "passionnée de bande dessinée", "2.1c"); + nbTests++; + nbErrors += addMemberOKTest(sn, "Paul", "paul", "lecteur impulsif", + "2.1a"); + nbTests++; + nbErrors += addMemberOKTest(sn, "Antoine", "antoine", + "grand amoureux de la littérature", "2.1b"); + nbTests++; + nbErrors += addMemberOKTest(sn, "Alice", "alice", + "passionnée de bande dessinée", "2.1c"); - // try to add already registered members + // try to add already registered members - nbTests++; - nbErrors += addMemberAlreadyExistsTest(sn, new String("Paul"), - "abcdefghij", "", "2.2", - "The login of the first member was accepted as login for a new member"); - nbTests++; - nbErrors += addMemberAlreadyExistsTest(sn, new String("Alice"), - "abcdefghij", "", "2.3", - "The login of the last member was accepted as login for a new member"); - nbTests++; - nbErrors += addMemberAlreadyExistsTest( - sn, - new String("anToine"), - "abcdefghij", - "", - "2.4", - "An already registered login, but with different case, was accepted as login for a new member"); - nbTests++; - nbErrors += addMemberAlreadyExistsTest( - sn, - new String(" Antoine "), - "abcdefghij", - "", - "2.5", - "An already registered login, surrounded by leading/trailing blanks, was accepted as login for a new member"); - nbTests++; - nbErrors += addMemberAlreadyExistsTest( - sn, - "An" + "toi" + "ne", - "abcdefghij", - "", - "2.6", - "A String concatenation building an already registered login was accepted as login for a new member"); + nbTests++; + nbErrors += addMemberAlreadyExistsTest(sn, new String("Paul"), + "abcdefghij", "", "2.2", + "The login of the first member was accepted as login for a new member"); + nbTests++; + nbErrors += addMemberAlreadyExistsTest(sn, new String("Alice"), + "abcdefghij", "", "2.3", + "The login of the last member was accepted as login for a new member"); + nbTests++; + nbErrors += addMemberAlreadyExistsTest( + sn, + new String("anToine"), + "abcdefghij", + "", + "2.4", + "An already registered login, but with different case, was accepted as login for a new member"); + nbTests++; + nbErrors += addMemberAlreadyExistsTest( + sn, + new String(" Antoine "), + "abcdefghij", + "", + "2.5", + "An already registered login, surrounded by leading/trailing blanks, was accepted as login for a new member"); + nbTests++; + nbErrors += addMemberAlreadyExistsTest( + sn, + "An" + "toi" + "ne", + "abcdefghij", + "", + "2.6", + "A String concatenation building an already registered login was accepted as login for a new member"); - nbTests++; - // check that 'sn' was not modified - if (nbFilms != sn.nbFilms()) { - System.out - .println("Error : the number of films was unexepectedly changed by addMember()"); - nbErrors++; - } - nbTests++; - if (nbBooks != sn.nbBooks()) { - System.out - .println("Error : the number of books was unexepectedly changed by addMember()"); - nbErrors++; - } + nbTests++; + // check that 'sn' was not modified + if (nbFilms != sn.nbFilms()) { + System.out + .println("Error : the number of films was unexepectedly changed by addMember()"); + nbErrors++; + } + nbTests++; + if (nbBooks != sn.nbBooks()) { + System.out + .println("Error : the number of books was unexepectedly changed by addMember()"); + nbErrors++; + } - // Display final state of 'sn' - System.out.println("Final state of the social network : " + sn); + // Display final state of 'sn' + System.out.println("Final state of the social network : " + sn); - // Print a summary of the tests and return test results - try{ - TestReport tr = new TestReport(nbTests, nbErrors); - System.out.println("AddMemberTest : " + tr); - return tr; - } - catch (NotTestReportException e){ //This shouldn't happen - System.out.println("Unexpected error in AddMemberTest test code - Can't return valuable test results"); - return null; - } - } - - - - /** - * Launches test() - * @param args not used - */ - public static void main(String[] args) { - test(); - } + // Print a summary of the tests and return test results + try { + TestReport tr = new TestReport(nbTests, nbErrors); + System.out.println("AddMemberTest : " + tr); + return tr; + } catch (NotTestReportException e) { //This shouldn't happen + System.out.println("Unexpected error in AddMemberTest test code - Can't return valuable test results"); + return null; + } + } + + + /** + * Launches test() + * + * @param args not used + */ + public static void main(String[] args) { + test(); + } }