Skip to content

Commit a25ea1a

Browse files
authored
Merge pull request #86 from CSC207-2022F-UofT/fix-warnings-for-create-and-delete-flashcard-sets
Addressed warnings in create/delete flashcard sets
2 parents ea48ce8 + 8f9e20c commit a25ea1a

File tree

5 files changed

+75
-52
lines changed

5 files changed

+75
-52
lines changed

src/main/java/create_flashcard_set_use_case/CreationScreen.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package create_flashcard_set_use_case;
22

33
import login_and_signup_use_case.UserLoginResponseModel;
4-
import view.Screen;
54

65
import javax.swing.*;
76
import java.awt.*;
@@ -11,13 +10,18 @@
1110

1211
// Frameworks/Drivers (Blue) layer
1312

14-
public class CreationScreen extends Screen implements ActionListener {
13+
/**
14+
* The flashcard set creation screen.
15+
*
16+
* @author Edward Ishii
17+
*/
18+
public class CreationScreen extends JFrame implements ActionListener {
1519
/**
16-
* The title of the flashcard set chosen by the user
20+
* The title of the flashcard set chosen by the user.
1721
*/
1822
JTextField title = new JTextField(15);
1923
/**
20-
* The description of the flashcard set
24+
* The description of the flashcard set.
2125
*/
2226
JTextField description = new JTextField(15);
2327
// /**
@@ -26,10 +30,13 @@ public class CreationScreen extends Screen implements ActionListener {
2630
// JTextField username = new JTextField(15);
2731

2832
/**
29-
* The controller
33+
* The controller.
3034
*/
3135
FlashcardSetController flashcardSetController;
3236

37+
/**
38+
* The user.
39+
*/
3340
UserLoginResponseModel user;
3441

3542
private boolean privateSelected; // for public or private status of flashcard set
@@ -93,10 +100,10 @@ public void actionPerformed(ActionEvent evt) {
93100
privateSelected = !privateSelected; // toggle every time clicked
94101
} else {
95102
try {
96-
flashcardSetController.create(title.getText(), description.getText(),
97-
privateSelected, user.getSignedInUsername());
103+
FlashcardSetResponseModel responseModel = flashcardSetController.create(title.getText(),
104+
description.getText(), privateSelected, user.getSignedInUsername());
98105
JOptionPane.showMessageDialog(this,
99-
String.format("Flashcard Set: [%s] created.", title.getText()));
106+
String.format("Flashcard Set: [%s] has been created.", responseModel.getFs().getTitle()));
100107
this.dispose(); // exit creation screen
101108
} catch (FlashcardSetCreationFailed e) {
102109
JOptionPane.showMessageDialog(this, e.getMessage());

src/main/java/delete_flashcard_set_use_case/DelFlashcardSetInteractor.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// Use case (Red) layer
44

55
import data_access.DBGateway;
6-
import data_access.IFlashcardDataAccess;
7-
import data_access.IFlashcardSetDataAccess;
86

97
/**
108
* [Feature: Deleting a Flashcard Set]
@@ -21,8 +19,7 @@
2119
public class DelFlashcardSetInteractor implements DelFlashcardSetInputBoundary {
2220

2321
DBGateway dbGateway;
24-
IFlashcardSetDataAccess flashcardSetDataAccess; // for testing
25-
IFlashcardDataAccess flashcardDataAccess; // for testing
22+
2623
DelFlashcardSetOutputBoundary outputBoundary;
2724

2825
public DelFlashcardSetInteractor(DBGateway dbGateway, DelFlashcardSetOutputBoundary outputBoundary) {

src/main/java/delete_flashcard_set_use_case/DeletionScreen.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package delete_flashcard_set_use_case;
22

3-
43
import data_access.DBGateway;
54
import login_and_signup_use_case.UserLoginResponseModel;
6-
import view.Screen;
75

86
import javax.swing.*;
97
import java.awt.*;
@@ -13,18 +11,30 @@
1311

1412
// Frameworks/Drivers (Blue) layer
1513

16-
public class DeletionScreen extends Screen implements ActionListener {
14+
/**
15+
* The flashcard set deletion screen.
16+
*
17+
* @author Edward Ishii
18+
*/
19+
public class DeletionScreen extends JFrame implements ActionListener {
1720
/**
18-
* The id of the flashcard set to be deleted
21+
* The id of the flashcard set to be deleted.
1922
*/
2023
int flashcardSetID;
2124

25+
/**
26+
* The user.
27+
*/
2228
UserLoginResponseModel user;
2329

2430
/**
25-
* The controller
31+
* The controller.
2632
*/
2733
DelFlashcardSetController controller;
34+
35+
/**
36+
* The database gateway.
37+
*/
2838
DBGateway gateway;
2939

3040
// /**
@@ -37,7 +47,7 @@ public class DeletionScreen extends Screen implements ActionListener {
3747
*/
3848
public DeletionScreen(int flashcardSetID, DelFlashcardSetController controller, UserLoginResponseModel user,
3949
DBGateway gateway) {
40-
this.user=user;
50+
this.user = user;
4151
this.flashcardSetID = flashcardSetID;
4252
this.controller = controller;
4353
this.gateway = gateway;
@@ -78,19 +88,16 @@ public void actionPerformed(ActionEvent evt) {
7888
// Exit deletion screen if user cancels deletion
7989
if (Objects.equals(evt.getActionCommand(), "Cancel")) {
8090
this.dispose();
81-
}
82-
83-
else { // Delete was pressed
91+
} else { // Delete was pressed
8492
// try {
8593
// int id = Integer.parseInt(flashcardSetID.getText()); // check input is an integer
8694

8795
// Ask for confirmation
8896
String title;
8997
// Admin deletion
90-
if (user.getFlashcardSets().get(flashcardSetID) == null){
91-
title = gateway.getFlashcardSet(flashcardSetID).getTitle();
92-
}
93-
else{
98+
if (user.getFlashcardSets().get(flashcardSetID) == null) {
99+
title = gateway.getFlashcardSet(flashcardSetID).getTitle();
100+
} else {
94101
// User deletion
95102
title = user.getFlashcardSets().get(flashcardSetID)[0];
96103
}
@@ -101,8 +108,9 @@ public void actionPerformed(ActionEvent evt) {
101108
"Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
102109
if (confirmation == 0) {
103110
try {
104-
controller.delete(flashcardSetID);
105-
JOptionPane.showMessageDialog(this, title + " has been deleted.");
111+
DelFlashcardSetResponseModel responseModel = controller.delete(flashcardSetID);
112+
responseModel.setMessage(title + " has been deleted.");
113+
JOptionPane.showMessageDialog(this, responseModel.getMessage());
106114
this.dispose(); // exit deletion screen
107115
} catch (FlashcardSetNotFound e) {
108116
JOptionPane.showMessageDialog(this, e.getMessage());

src/test/java/create_flashcard_set_use_case/FlashcardSetInteractorTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public FlashcardSetResponseModel prepareFailView(String error) {
6565
}
6666

6767
@Test
68-
public void testMissingTitleException() throws FlashcardSetCreationFailed {
68+
public void testMissingTitleException() {
6969
// Create a mock user input with no title
7070
FlashcardSetRequestModel requestModel = new FlashcardSetRequestModel("",
7171
"Final Exam Review", false, "uncle_bob69");
@@ -92,14 +92,14 @@ public FlashcardSetResponseModel prepareFailView(String error) {
9292
try {
9393
interactor.create(requestModel); // no title should go immediately to catch block (i.e., pass test)
9494
assert (false); // if title is included, then this line is reached and test fails
95-
} catch (FlashcardSetCreationFailed e) {
95+
} catch (FlashcardSetCreationFailed ignored) {
9696

9797
}
9898

9999
}
100100

101101
@Test
102-
public void testMissingDescriptionException() throws FlashcardSetCreationFailed {
102+
public void testMissingDescriptionException() {
103103
// Create a mock user input with no description
104104
FlashcardSetRequestModel requestModel = new FlashcardSetRequestModel("CSC207",
105105
"", false, "uncle_bob69");
@@ -126,14 +126,14 @@ public FlashcardSetResponseModel prepareFailView(String error) {
126126
try {
127127
interactor.create(requestModel);
128128
assert (false);
129-
} catch (FlashcardSetCreationFailed e) {
129+
} catch (FlashcardSetCreationFailed ignored) {
130130

131131
}
132132

133133
}
134134

135135
@Test
136-
public void testMissingUsernameException() throws FlashcardSetCreationFailed {
136+
public void testMissingUsernameException() {
137137
// Create a mock user input with no username
138138
FlashcardSetRequestModel requestModel = new FlashcardSetRequestModel("CSC207",
139139
"Final Exam Review", false, "");
@@ -160,7 +160,7 @@ public FlashcardSetResponseModel prepareFailView(String error) {
160160
try {
161161
interactor.create(requestModel);
162162
assert (false);
163-
} catch (FlashcardSetCreationFailed e) {
163+
} catch (FlashcardSetCreationFailed ignored) {
164164

165165
}
166166

src/test/java/delete_flashcard_set_use_case/DelFlashcardSetInteractorTest.java

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.ArrayList;
1515
import java.util.List;
1616

17-
import static org.junit.jupiter.api.Assertions.fail;
1817

1918
/**
2019
* [Feature: Deleting a Flashcard Set]
@@ -27,13 +26,17 @@
2726
* - if it exists, ask for confirmation to delete from the user
2827
* - when a flashcard set is deleted, all flashcards contained within are deleted
2928
* - notify successful deletion of flashcard set to the user
29+
*
30+
* @author Edward Ishii
3031
*/
31-
3232
public class DelFlashcardSetInteractorTest {
3333

3434
IFlashcardSetDataAccess flashcardSetRepo;
3535
IFlashcardDataAccess flashcardRepo;
3636

37+
/**
38+
* The setup for testing deletion, i.e., create and populate mock flashcard set and flashcard databases.
39+
*/
3740
@BeforeEach
3841
public void setup() {
3942
// Create a mock flashcard set repository
@@ -44,7 +47,7 @@ public void setup() {
4447

4548
// Populate flashcardRepo
4649
FlashcardDsRequestModel fc1 = new FlashcardDsRequestModel("SOLID", "Single responsibility, " +
47-
"Open/closed, Liskov substitution, Interface segregation, Dependency inversion", LocalDateTime.now(),
50+
"Open/closed, Liskov substitution, Interface segragation, Dependency inversion", LocalDateTime.now(),
4851
10, 1);
4952

5053
FlashcardDsRequestModel fc2 = new FlashcardDsRequestModel("Bloaters", "too much code",
@@ -84,6 +87,10 @@ public void setup() {
8487
Assertions.assertEquals(1, flashcardSetRepo.getFlashcardSet(2).getFlashcardIds().size());
8588
}
8689

90+
/**
91+
* Test that when a flashcard set is deleted, the set is deleted from the flashcard set database, AND all
92+
* the associated flashcards within that set is also deleted from the flashcard database.
93+
*/
8794
@Test
8895
public void testDelete() {
8996
// Create mock input
@@ -121,27 +128,31 @@ public void testDelete() {
121128
Assertions.assertEquals("Language", flashcardRepo.getFlashcard(30).getTerm());
122129
}
123130

131+
/**
132+
* Test that the proper exception is thrown when the id of the flashcard set to be deleted does not exist
133+
* within the database.
134+
*/
124135
@Test
125-
public void testDeleteOnNonExistentFlashcardSet() throws FlashcardSetNotFound {
136+
public void testDeleteOnNonExistentFlashcardSet() {
126137

127138
// Mock input with id of a flashcard set that doesn't exist
128139
DelFlashcardSetRequestModel inputData = new DelFlashcardSetRequestModel(3);
129140

130141

131142
// Implement output boundaries to throw an exception
132-
DelFlashcardSetOutputBoundary outputBoundary = new DelFlashcardSetOutputBoundary() {
133-
@Override
134-
public DelFlashcardSetResponseModel prepareSuccessView(String message) {
135-
fail("Something went wrong since we are testing for failing deletion.");
136-
return null;
137-
}
138-
139-
@Override
140-
public DelFlashcardSetResponseModel prepareFailView(String error) throws FlashcardSetNotFound {
141-
throw new FlashcardSetNotFound("Flashcard set #" + inputData.getFlashcardSetId()
142-
+ " does not exist.");
143-
}
144-
};
143+
// DelFlashcardSetOutputBoundary outputBoundary = new DelFlashcardSetOutputBoundary() {
144+
// @Override
145+
// public DelFlashcardSetResponseModel prepareSuccessView(String message) {
146+
// fail("Something went wrong since we are testing for failing deletion.");
147+
// return null;
148+
// }
149+
//
150+
// @Override
151+
// public DelFlashcardSetResponseModel prepareFailView(String error) throws FlashcardSetNotFound {
152+
// throw new FlashcardSetNotFound("Flashcard set #" + inputData.getFlashcardSetId()
153+
// + " does not exist.");
154+
// }
155+
// };
145156

146157
DelFlashcardSetOutputBoundary presenter = new DelFlashcardSetPresenter();
147158

@@ -167,8 +178,8 @@ public DelFlashcardSetResponseModel prepareFailView(String error) throws Flashca
167178
// Test part
168179
try {
169180
interactor.delete(inputData); // invalid id should go immediately to catch block (i.e., pass test)
170-
assert(false); // if id exists, then this line is reached and test fails
171-
} catch (FlashcardSetNotFound e) {
181+
assert (false); // if id exists, then this line is reached and test fails
182+
} catch (FlashcardSetNotFound ignored) {
172183

173184
}
174185
}

0 commit comments

Comments
 (0)