Skip to content

Commit 8f9e20c

Browse files
committed
Addressed unused variable and empty catch block warnings.
Fixed unused variable by commenting it out. Fixed the empty catch warnings by renaming 'catch' parameter to 'ignored'.
1 parent fec5d6d commit 8f9e20c

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

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)