generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
backend/wiq/src/test/java/com/wiq/wiq/services/questionGenerator/question/QuestionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.wiq.wiq.services.questionGenerator.question; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
public class QuestionTests { | ||
|
||
private Question question; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
List<String> answers = Arrays.asList("A", "B", "C"); | ||
question = new Question("What is the capital of France?", answers); | ||
} | ||
|
||
@Test | ||
void testGetQuestion() { | ||
assertEquals("What is the capital of France?", question.getQuestion()); | ||
} | ||
|
||
@Test | ||
void testSetQuestion() { | ||
question.setQuestion("What is the capital of Germany?"); | ||
assertEquals("What is the capital of Germany?", question.getQuestion()); | ||
} | ||
|
||
@Test | ||
void testGetAnswers() { | ||
List<String> expectedAnswers = Arrays.asList("A", "B", "C"); | ||
assertEquals(expectedAnswers, question.getAnswers()); | ||
} | ||
|
||
@Test | ||
void testSetAnswers() { | ||
List<String> newAnswers = Arrays.asList("X", "Y", "Z"); | ||
question.setAnswers(newAnswers); | ||
assertEquals(newAnswers, question.getAnswers()); | ||
} | ||
|
||
@Test | ||
void testAddRightAnswer() { | ||
question.addRightAnswer("Paris"); | ||
List<String> expectedAnswers = Arrays.asList("Paris", "A", "B", "C"); | ||
assertEquals(expectedAnswers, question.getAnswers()); | ||
} | ||
|
||
@Test | ||
void testGetJSON() { | ||
try { | ||
JSONObject expectedJson = new JSONObject() | ||
.put("question", "What is the capital of France?") | ||
.put("answers", new JSONArray().put("A").put("B").put("C")); | ||
assertEquals(expectedJson.toString(), question.getJSON().toString()); | ||
} catch (JSONException e) { | ||
fail("JSONException occurred: " + e.getMessage()); | ||
} | ||
} | ||
} |