14
14
import java .util .ArrayList ;
15
15
import java .util .List ;
16
16
17
- import static org .junit .jupiter .api .Assertions .fail ;
18
17
19
18
/**
20
19
* [Feature: Deleting a Flashcard Set]
27
26
* - if it exists, ask for confirmation to delete from the user
28
27
* - when a flashcard set is deleted, all flashcards contained within are deleted
29
28
* - notify successful deletion of flashcard set to the user
29
+ *
30
+ * @author Edward Ishii
30
31
*/
31
-
32
32
public class DelFlashcardSetInteractorTest {
33
33
34
34
IFlashcardSetDataAccess flashcardSetRepo ;
35
35
IFlashcardDataAccess flashcardRepo ;
36
36
37
+ /**
38
+ * The setup for testing deletion, i.e., create and populate mock flashcard set and flashcard databases.
39
+ */
37
40
@ BeforeEach
38
41
public void setup () {
39
42
// Create a mock flashcard set repository
@@ -44,7 +47,7 @@ public void setup() {
44
47
45
48
// Populate flashcardRepo
46
49
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 (),
48
51
10 , 1 );
49
52
50
53
FlashcardDsRequestModel fc2 = new FlashcardDsRequestModel ("Bloaters" , "too much code" ,
@@ -84,6 +87,10 @@ public void setup() {
84
87
Assertions .assertEquals (1 , flashcardSetRepo .getFlashcardSet (2 ).getFlashcardIds ().size ());
85
88
}
86
89
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
+ */
87
94
@ Test
88
95
public void testDelete () {
89
96
// Create mock input
@@ -121,27 +128,31 @@ public void testDelete() {
121
128
Assertions .assertEquals ("Language" , flashcardRepo .getFlashcard (30 ).getTerm ());
122
129
}
123
130
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
+ */
124
135
@ Test
125
- public void testDeleteOnNonExistentFlashcardSet () throws FlashcardSetNotFound {
136
+ public void testDeleteOnNonExistentFlashcardSet () {
126
137
127
138
// Mock input with id of a flashcard set that doesn't exist
128
139
DelFlashcardSetRequestModel inputData = new DelFlashcardSetRequestModel (3 );
129
140
130
141
131
142
// 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
+ // };
145
156
146
157
DelFlashcardSetOutputBoundary presenter = new DelFlashcardSetPresenter ();
147
158
@@ -167,8 +178,8 @@ public DelFlashcardSetResponseModel prepareFailView(String error) throws Flashca
167
178
// Test part
168
179
try {
169
180
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 ) {
172
183
173
184
}
174
185
}
0 commit comments