Commit ccc8c1ad by Rubén Ramírez

feat: [TestBibliotecaPersonal]: Testeada la función en la propia clase para añadir a favoritos

parent 7f5889c9
package com.ujaen.tfg.mangaffinity.entidades;
import com.ujaen.tfg.mangaffinity.excepciones.NumeroMaximoFavoritos;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
public class TestBibliotecaPersonal {
private BibliotecaPersonal biblioteca;
@BeforeEach
void setUp() {
biblioteca = new BibliotecaPersonal();
}
@Test
void testFuncionamientoCompletoFavoritos() {
BibliotecaPersonal biblioteca = new BibliotecaPersonal();
// Añadir favoritos únicos
biblioteca.anadirFavorito(1L);
biblioteca.anadirFavorito(2L);
biblioteca.anadirFavorito(3L);
biblioteca.anadirFavorito(4L);
// Verificar que están añadidos
List<Long> favoritos = biblioteca.obtenerFavoritos();
assertEquals(4, favoritos.size());
assertTrue(favoritos.containsAll(List.of(1L, 2L, 3L, 4L)));
// No debe duplicar
biblioteca.anadirFavorito(2L);
assertEquals(4, biblioteca.obtenerFavoritos().size());
// Excepción al intentar añadir el quinto
assertThrows(NumeroMaximoFavoritos.class, () -> biblioteca.anadirFavorito(5L));
// Eliminar uno y volver a añadir otro
biblioteca.eliminarFavorito(3L);
biblioteca.anadirFavorito(5L);
assertTrue(biblioteca.obtenerFavoritos().contains(5L));
assertFalse(biblioteca.obtenerFavoritos().contains(3L));
assertEquals(4, biblioteca.obtenerFavoritos().size());
// Verificar que la lista es inmutable
assertThrows(UnsupportedOperationException.class, () -> biblioteca.obtenerFavoritos().add(99L));
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment