Skip to content

Commit

Permalink
[#12048] Refactor tests for DeleteFeedbackQuestionActionTest (#13246)
Browse files Browse the repository at this point in the history
* Refactor test case initialisation

Remove final fields and create a
method to initialise the variables
before the test, so as to reduce
dependencies.

(cherry picked from commit 1dc9742)

* Rectify import classes

Imported BeforeEach from JUnit
previously, instead of BeforeMethod

---------

Co-authored-by: domoberzin <[email protected]>
  • Loading branch information
BunnyHoppp and domoberzin authored Feb 28, 2025
1 parent e9a0ea0 commit ca4f178
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.UUID;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import teammates.common.datatransfer.InstructorPrivileges;
Expand All @@ -21,11 +22,10 @@
*/
public class DeleteFeedbackQuestionActionTest extends BaseActionTest<DeleteFeedbackQuestionAction> {

private final Instructor typicalInstructor = getTypicalInstructor();
private final Course typicalCourse = typicalInstructor.getCourse();
private final FeedbackSession typicalFeedbackSession = getTypicalFeedbackSessionForCourse(typicalCourse);
private final FeedbackQuestion typicalFeedbackQuestion =
getTypicalFeedbackQuestionForSession(typicalFeedbackSession);
private Instructor typicalInstructor;
private Course typicalCourse;
private FeedbackSession typicalFeedbackSession;
private FeedbackQuestion typicalFeedbackQuestion;

@Override
protected String getActionUri() {
Expand All @@ -37,6 +37,14 @@ protected String getRequestMethod() {
return DELETE;
}

@BeforeMethod
void setUp() {
typicalInstructor = getTypicalInstructor();
typicalCourse = typicalInstructor.getCourse();
typicalFeedbackSession = getTypicalFeedbackSessionForCourse(typicalCourse);
typicalFeedbackQuestion = getTypicalFeedbackQuestionForSession(typicalFeedbackSession);
}

@Test
void testExecute_feedbackQuestionExists_success() {
when(mockLogic.getFeedbackQuestion(typicalFeedbackQuestion.getId())).thenReturn(typicalFeedbackQuestion);
Expand Down

0 comments on commit ca4f178

Please sign in to comment.