Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Rubén Ramírez
/
MangAffinity
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ccc8c1ad
authored
Apr 20, 2025
by
Rubén Ramírez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat: [TestBibliotecaPersonal]: Testeada la función en la propia clase para añadir a favoritos
parent
7f5889c9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
src/test/java/com/ujaen/tfg/mangaffinity/entidades/TestBibliotecaPersonal.java
src/test/java/com/ujaen/tfg/mangaffinity/entidades/TestBibliotecaPersonal.java
0 → 100644
View file @
ccc8c1ad
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment