Skip to content
Snippets Groups Projects
Commit 46b09cc5 authored by MASSY FERNANDEZ Neva Aracely's avatar MASSY FERNANDEZ Neva Aracely
Browse files

doc: Improve comments on code

parent 25aa8f39
Branches main
No related tags found
1 merge request!5Merge code for Iteration 2 with main
...@@ -24,43 +24,27 @@ public class AddItemBookTest { ...@@ -24,43 +24,27 @@ public class AddItemBookTest {
private static int addItemBookBadEntryTest(ISocialNetwork sn, String login, private static int addItemBookBadEntryTest(ISocialNetwork sn, String login,
String pwd, String title, String kind, String author, int nbPages, String testId, String errorMessage) { String pwd, String title, String kind, String author, int nbPages, String testId, String errorMessage) {
int nbBooks = sn.nbBooks(); // Number of books when starting to int nbBooks = sn.nbBooks(); // Number of books when starting to run this method
// run this method
try { try {
sn.addItemBook(login, pwd, title, kind, author, nbPages); // Try to add this book sn.addItemBook(login, pwd, title, kind, author, nbPages); // Try to add this book
// Reaching this point means that no exception was thrown by System.out.println("Err " + testId + " : " + errorMessage); // display error
// addItemBook()
System.out.println("Err " + testId + " : " + errorMessage); // display
// the
// error
// message
return 1; // and return the "error" value return 1; // and return the "error" value
} catch (BadEntryException e) { // BadEntry exception was thrown by } catch (BadEntryException e) { // BadEntry exception was thrown
// addItemBook() : this is a good start! // check if 'sn' was not impacted
// Let's now check if 'sn' was not if (sn.nbBooks() != nbBooks) {
// impacted
if (sn.nbBooks() != nbBooks) { // The number of members has
// changed : this is an error
// case.
System.out System.out
.println("Err " .println("Err "
+ testId + testId
+ " : BadEntry was thrown but the number of books was changed"); // Display + " : BadEntry was thrown but the number of books was changed");
// a // Display error for the number of books
// specific
// error
// message
return 1; // return "error" value return 1; // return "error" value
} else } else
// The number of books hasn't changed, which is considered a // The number of books hasn't changed,'sn' not modified
// good indicator that 'sn' was not modified return 0; // everything seems OK
return 0; // return success value : everything seems OK, nothing } catch (Exception e) { // An exception was thrown by addItemBook(), Unexpected exception
// to display
} catch (Exception e) { // An exception was thrown by addItemBook(), but
// it was not the expected exception BadEntry
System.out.println("Err " + testId + " : unexpected exception. " System.out.println("Err " + testId + " : unexpected exception. "
+ e); // Display a specific error message + e); // Display a specific error message
e.printStackTrace(); // Display contextual info about what happened e.printStackTrace();
return 1; // return error value return 1; // return error value
} }
} }
...@@ -81,40 +65,25 @@ public class AddItemBookTest { ...@@ -81,40 +65,25 @@ public class AddItemBookTest {
private static int addItemBookAlreadyExistsTest(ISocialNetwork sn, private static int addItemBookAlreadyExistsTest(ISocialNetwork sn,
String login, String pwd, String title, String kind, String author, int nbPages, String testId, String login, String pwd, String title, String kind, String author, int nbPages, String testId,
String errorMessage) { String errorMessage) {
int nbBooks = sn.nbBooks(); // Number of members when starting to int nbBooks = sn.nbBooks(); // Number of members when starting to process this method
// process this method
try { try {
sn.addItemBook(login, pwd, title, kind, author, nbPages); // Try to add this book sn.addItemBook(login, pwd, title, kind, author, nbPages); // Try to add this book that exists
// Reaching this point means that no exception was thrown by System.out.println("Err " + testId + " : " + errorMessage); // display error message
// addItemBook()
System.out.println("Err " + testId + " : " + errorMessage); // display
// the
// error
// message
return 1; // and return the "error" value return 1; // and return the "error" value
} catch ( ItemBookAlreadyExistsException e) {// AlreadyExists exception was } catch ( ItemBookAlreadyExistsException e) {// AlreadyExists exception was launched
// thrown by addItemBook() : //checking sn changes
// this is a good start!
// Let's now check if 'sn'
// was not impacted
if (sn.nbBooks() != nbBooks) { if (sn.nbBooks() != nbBooks) {
System.out System.out
.println("Err " .println("Err "
+ testId + testId
+ " : ItemBookAlreadyExists was thrown, but the number of books was changed"); // Display + " : ItemBookAlreadyExists was thrown, but the number of books was changed"); // Display
// a // error message
// specific return 1;// error value assigned
// error
// message
return 1;// and return the "error" value
} else } else
return 0; // return success value : everything is OK, nothing to return 0; // OK value
// display // display
} catch (Exception e) { // An exception was thrown by addMember(), but } catch (Exception e) { // An exception was thrown by addMember()
// it was not the expected exception System.out.println("Err " + testId + " : unexpected exception. " + e); // Display unexpected exception
// AlreadyExists
System.out.println("Err " + testId + " : unexpected exception. "
+ e); // Display a specific error message
e.printStackTrace(); // Display contextual info about what happened e.printStackTrace(); // Display contextual info about what happened
return 1; // return error value return 1; // return error value
} }
...@@ -135,27 +104,20 @@ public class AddItemBookTest { ...@@ -135,27 +104,20 @@ public class AddItemBookTest {
*/ */
private static int addItemBookOKTest(ISocialNetwork sn, String login, private static int addItemBookOKTest(ISocialNetwork sn, String login,
String pwd, String title, String kind, String author, int nbPages, String testId) { String pwd, String title, String kind, String author, int nbPages, String testId) {
int nbBooks = sn.nbBooks(); // Number of books when starting to int nbBooks = sn.nbBooks(); // Number of books
// process this method
try { try {
sn.addItemBook(login, pwd, title, kind, author, nbPages); // Try to add this book sn.addItemBook(login, pwd, title, kind, author, nbPages); // Try to add this book
// No exception was thrown. That's a good start ! if (sn.nbBooks() != nbBooks + 1) { // Number does not changed
if (sn.nbBooks() != nbBooks + 1) { // But the number of books
// hasn't changed
// accordingly
System.out.println("Err " + testId System.out.println("Err " + testId
+ " : the number of books (" + nbBooks + " : the number of books (" + nbBooks
+ ") was not incremented"); // Error message displayed + ") was not incremented"); // Error message displayed
return 1; // return error code return 1; // return error code
} else } else
return 0; // return success code : everything is OK, nothing to return 0; // return OK code
// display // display
} catch (Exception e) {// An exception was thrown by addMember() : this } catch (Exception e) {// An exception was thrown by addMember()
// is an error case
System.out System.out
.println("Err " + testId + " : unexpected exception " + e); // Error .println("Err " + testId + " : unexpected exception " + e); // Error message
// message
// displayed
e.printStackTrace(); // Display contextual info about what happened e.printStackTrace(); // Display contextual info about what happened
return 1; // return error code return 1; // return error code
} }
...@@ -181,31 +143,20 @@ public class AddItemBookTest { ...@@ -181,31 +143,20 @@ public class AddItemBookTest {
// process this method // process this method
try { try {
sn.addItemBook(login, pwd, title, kind, author, nbPages); // Try to add this book sn.addItemBook(login, pwd, title, kind, author, nbPages); // Try to add this book
// Reaching this point means that no exception was thrown by // Reaching this point means that no exception was thrown by addItemBook()
// addItemBook() System.out.println("Err " + testId + " : " + errorMessage); // display error message
System.out.println("Err " + testId + " : " + errorMessage); // display
// the
// error
// message
return 1; // and return the "error" value return 1; // and return the "error" value
} catch ( NotMemberException e) {// AlreadyExists exception was } catch ( NotMemberException e) {// AlreadyExists exception was thrown by addItemBook() :
// thrown by addItemBook() : //check if 'sn' was not impacted
// this is a good start!
// Let's now check if 'sn'
// was not impacted
if (sn.nbBooks() != nbBooks) { if (sn.nbBooks() != nbBooks) {
System.out System.out
.println("Err " .println("Err "
+ testId + testId
+ " : NotMember was thrown, but the number of books was changed"); // Display + " : NotMember was thrown, but the number of books was changed"); // Display
// a // a error message launched
// specific
// error
// message
return 1;// and return the "error" value return 1;// and return the "error" value
} else } else
return 0; // return success value : everything is OK, nothing to return 0; // return OK value
// display
} catch (Exception e) { // An exception was thrown by addMember(), but } catch (Exception e) { // An exception was thrown by addMember(), but
// it was not the expected exception // it was not the expected exception
// AlreadyExists // AlreadyExists
...@@ -241,14 +192,10 @@ public class AddItemBookTest { ...@@ -241,14 +192,10 @@ public class AddItemBookTest {
+ ") was not incremented"); // Error message displayed + ") was not incremented"); // Error message displayed
return 1; // return error code return 1; // return error code
} else } else
return 0; // return success code : everything is OK, nothing to return 0; // return success code
// display } catch (Exception e) {// An exception was thrown by addMember() : error case
} catch (Exception e) {// An exception was thrown by addMember() : this
// is an error case
System.out System.out
.println("Err " + testId + " : unexpected exception " + e); // Error .println("Err " + testId + " : unexpected exception " + e); // Error message
// message
// displayed
e.printStackTrace(); // Display contextual info about what happened e.printStackTrace(); // Display contextual info about what happened
return 1; // return error code return 1; // return error code
} }
...@@ -268,8 +215,7 @@ public class AddItemBookTest { ...@@ -268,8 +215,7 @@ public class AddItemBookTest {
System.out.println("Testing addItemBook()"); System.out.println("Testing addItemBook()");
// <=> test n°1 // <=> test n°1
// check if incorrect parameters cause addItemBook() to throw BadEntry // check if incorrect parameters cause addItemBook() to throw BadEntry exception
// exception
//populate 'sn' with 3 members //populate 'sn' with 3 members
nbErrors += addMemberOKTest(sn,"Paul","paul","Student","1.0a"); nbErrors += addMemberOKTest(sn,"Paul","paul","Student","1.0a");
...@@ -357,7 +303,7 @@ public class AddItemBookTest { ...@@ -357,7 +303,7 @@ public class AddItemBookTest {
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 AddMemberTest test code - Can't return valuable test results"); System.out.println("Unexpected error in AddMemberTest 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