Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fip112-2025-g41
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BINTI TENGKU MASRULHISHAM Tengku Maryam Naqeesha
fip112-2025-g41
Commits
404c84aa
There was an error fetching the commit references. Please try again later.
Commit
404c84aa
authored
1 month ago
by
tmnaqeesha
Browse files
Options
Downloads
Patches
Plain Diff
fix: Clean code and improve comments
parent
a0a36728
No related branches found
No related tags found
1 merge request
!5
Merge code for Iteration 2 with main
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/opinion/SocialNetwork.java
+2
-27
2 additions, 27 deletions
src/opinion/SocialNetwork.java
src/tests/AddItemBookTest.java
+32
-51
32 additions, 51 deletions
src/tests/AddItemBookTest.java
with
34 additions
and
78 deletions
src/opinion/SocialNetwork.java
+
2
−
27
View file @
404c84aa
...
@@ -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
newB
ook
=
new
Book
(
title
.
trim
(),
kind
.
trim
(),
author
.
trim
(),
nbPages
);
b
ook
=
new
Book
(
title
.
trim
(),
kind
.
trim
(),
author
.
trim
(),
nbPages
);
listBook
.
add
(
newB
ook
);
listBook
.
add
(
b
ook
);
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
...
...
This diff is collapsed.
Click to expand it.
src/tests/AddItemBookTest.java
+
32
−
51
View file @
404c84aa
...
@@ -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
: Add
ing
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
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment