Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pelayori committed Apr 26, 2024
1 parent 418b15e commit b3bceb7
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/test/java/com/uniovi/Wiq_UnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.uniovi.entities.*;
import com.uniovi.repositories.*;
import com.uniovi.services.*;
import jakarta.transaction.Transactional;
import jakarta.validation.constraints.AssertTrue;
import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -1634,7 +1635,7 @@ public void testScoreMultiplayerCodeAssignment() {
@Test
@Order(106)
public void GameSessionImpl_startNewMultiplayerGame() throws InterruptedException, IOException {
insertSomeQuestions();
testQuestions(10);

Long playerId = 1L;
Player player = createPlayer();
Expand All @@ -1653,7 +1654,7 @@ public void GameSessionImpl_startNewMultiplayerGame() throws InterruptedExcepti
@Test
@Order(107)
public void testRandomMultiplayerQuestions() throws InterruptedException, IOException {
insertSomeQuestions();
testQuestions(10);

Long playerId = 1L;
Player player = createPlayer();
Expand Down Expand Up @@ -1826,4 +1827,28 @@ private JSONObject parseJsonResponse(HttpResponse<String> response) throws JSONE
private void insertSomeQuestions() throws IOException, InterruptedException {
questionGeneratorService.generateTestQuestions();
}

public List<Question> testQuestions(int num) {
List<Question> res = new ArrayList<>();
Category c = new Category("Test category", "Test category");
categoryService.addNewCategory(c);
for (int i = 0; i < num; i++) {
Question q = new Question();
q.setStatement("Test question " + i);
q.setLanguage("es");
Associations.QuestionsCategory.addCategory(q, c);
List<Answer> answers = new ArrayList<>();
for (int j = 0; j < 4; j++) {
Answer a = new Answer();
a.setText("Test answer " + j);
a.setCorrect(j == 0);
if(j==0) q.setCorrectAnswer(a);
answers.add(a);
}
Associations.QuestionAnswers.addAnswer(q, answers);
questionService.addNewQuestion(q);
res.add(q);
}
return res;
}
}

0 comments on commit b3bceb7

Please sign in to comment.