Skip to content

Commit

Permalink
unit tests for Player class
Browse files Browse the repository at this point in the history
  • Loading branch information
uo288061 committed Apr 5, 2024
1 parent d3b30cd commit 592fb21
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/test/java/com/uniovi/Wiq_UnitTests.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.uniovi;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.uniovi.components.generators.geography.BorderQuestionGenerator;
import com.uniovi.components.generators.geography.CapitalQuestionGenerator;
import com.uniovi.components.generators.geography.ContinentQuestionGeneration;
Expand Down Expand Up @@ -328,6 +329,42 @@ public void testGetDuration() {

Assertions.assertEquals("00:05:00", gameSession.getDuration());
}
@Test
@Order(22)
public void testPlayerToJson() {
Role role1 = new Role("ROLE_USER");
Role role2 = new Role("ROLE_ADMIN");

Set<Role> roles = new HashSet<>();
roles.add(role1);
roles.add(role2);

Player player = createPlayer();
player.setId(1L);
player.setRoles(roles);

GameSession gameSession = new GameSession(player, new ArrayList<>());
gameSession.setId(0L);
Set<GameSession> gameSessions = new HashSet<>();
gameSessions.add(gameSession);


player.setGameSessions(gameSessions);

JsonNode json = player.toJson();

Assertions.assertEquals(1L, json.get("id").asLong());
Assertions.assertEquals("name", json.get("username").asText());
Assertions.assertEquals("[email protected]", json.get("email").asText());

ArrayNode rolesArray = (ArrayNode) json.get("roles");
Assertions.assertEquals(2, rolesArray.size());

ArrayNode gameSessionsArray = (ArrayNode) json.get("gameSessions");
Assertions.assertEquals(1, gameSessionsArray.size());
// Se verifica que la sesión de juego está presente en el JSON
Assertions.assertEquals(gameSession.getId(), gameSessionsArray.get(0).get("id").asLong());
}


}

0 comments on commit 592fb21

Please sign in to comment.