Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
jesus morales villegas
/
diseno_software
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
303c5d01
authored
Dec 28, 2023
by
David Rodríguez Muro
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Testing finalizado
parent
e7c4f4be
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
116 additions
and
36 deletions
Test/BibliotecaTest.java
src/Biblioteca.java
src/Catalogo.java
src/Ejemplar.java
src/Lector.java
src/Libro.java
src/Usuario.java
Test/BibliotecaTest.java
View file @
303c5d01
import
org.junit.
Assert
;
import
org.junit.
jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
class
BibliotecaTest
{
Biblioteca
biblioteca
;
@BeforeEach
void
setUp
()
{
biblioteca
=
Biblioteca
.
ObtenerInstancia
();
}
@Test
void
comprobarUsuario
()
{
Lector
l1
=
new
Lector
();
Lector
l2
=
new
Lector
();
l2
.
set_numPenalizaciones
(
1
);
l2
.
set_fechaPenalizacion
(
LocalDate
.
of
(
2024
,
2
,
12
));
biblioteca
.
addLector
(
l1
,
123
);
biblioteca
.
addLector
(
l2
,
333
);
assertAll
(
()
->
assertEquals
(
12
,
12
)
()
->
assertTrue
(
biblioteca
.
ComprobarUsuario
(
123
),
"El usuario existe y no está penalizado"
),
()
->
assertFalse
(
biblioteca
.
ComprobarUsuario
(
899
),
"El usuario no existe"
),
()
->
assertFalse
(
biblioteca
.
ComprobarUsuario
(
333
),
"El usuario existe y está penalizado"
)
);
}
@Test
void
comprobarSacarLibro
()
{
Ejemplar
e1
=
new
Ejemplar
();
biblioteca
.
addEjemplar
(
e1
,
123
);
Ejemplar
e2
=
new
Ejemplar
();
e2
.
set_estado
(
"deteriorado"
);
biblioteca
.
addEjemplar
(
e2
,
234
);
Ejemplar
e3
=
new
Ejemplar
();
e3
.
set_numReservas
(
1
);
biblioteca
.
addEjemplar
(
e3
,
557
);
Ejemplar
e4
=
new
Ejemplar
();
e4
.
set_numReservas
(
1
);
e4
.
set_estado
(
"deteriorado"
);
biblioteca
.
addEjemplar
(
e4
,
678
);
assertAll
(
()
->
assertEquals
(
12
,
12
)
()
->
assertTrue
(
biblioteca
.
ComprobarSacarLibro
(
123
),
"ISBN existente, estado no deteriorado y disponible"
),
()
->
assertFalse
(
biblioteca
.
ComprobarSacarLibro
(
234
),
"ISBN existente, estado deteriorado y disponible"
),
()
->
assertFalse
(
biblioteca
.
ComprobarSacarLibro
(
321
),
"ISBN no existente"
),
()
->
assertFalse
(
biblioteca
.
ComprobarSacarLibro
(
557
),
"ISBN existente, estado no deteriorado y no disponible"
),
()
->
assertFalse
(
biblioteca
.
ComprobarSacarLibro
(
678
),
"ISBN existente, estado deteriorado y no disponible"
)
);
}
}
\ No newline at end of file
src/Biblioteca.java
View file @
303c5d01
...
...
@@ -3,18 +3,44 @@ import java.time.format.DateTimeFormatter;
import
java.util.HashMap
;
public
class
Biblioteca
{
public
HashMap
<
Integer
,
Lector
>
usuarios
;
private
Biblioteca
_instancia
;
public
Catalogo
_unnamed_Catalogo_18
;
public
Usuario
_hay
;
public
EstrategiaHistorial
_unnamed_EstrategiaHistorial_
;
public
HashMap
<
Integer
,
Lector
>
usuarios
=
new
HashMap
<>();
private
static
Biblioteca
instancia
;
public
Catalogo
catalogo
=
new
Catalogo
();
public
int
_hay
=
0
;
public
EstrategiaHistorial
EstrategiaHistorial
=
new
EstrategiaHistorial
()
{
@Override
public
void
Anadir
()
{
}
@Override
public
void
Consultar
()
{
}
};
private
Biblioteca
()
{
throw
new
UnsupportedOperationException
();
}
public
Biblioteca
ObtenerInstancia
()
{
throw
new
UnsupportedOperationException
();
public
static
Biblioteca
ObtenerInstancia
()
{
if
(
instancia
==
null
)
{
instancia
=
new
Biblioteca
();
}
return
instancia
;
}
public
void
addLector
(
Lector
l
,
int
id
){
usuarios
.
put
(
id
,
l
);
_hay
++;
}
public
void
addEjemplar
(
Ejemplar
e
,
int
ISBN
){
catalogo
.
_controla
.
put
(
ISBN
,
e
);
}
public
Lector
getLector
(
int
id
){
return
usuarios
.
get
(
id
);
}
public
Boolean
ComprobarUsuario
(
Integer
idUsuario
)
{
...
...
@@ -24,7 +50,7 @@ public class Biblioteca {
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"dd-MM-yyyy"
);
String
fechaActual
=
fecha
.
format
(
formatter
);
LocalDate
fechaPenalizacion
=
LocalDate
.
parse
(
usuarios
.
get
(
idUsuario
).
get_fechaPenalizacion
(),
formatter
);
LocalDate
fechaPenalizacion
=
usuarios
.
get
(
idUsuario
).
get_fechaPenalizacion
(
);
LocalDate
fechaLocalActual
=
LocalDate
.
parse
(
fechaActual
,
formatter
);
return
!
fechaPenalizacion
.
isAfter
(
fechaLocalActual
);
...
...
@@ -57,8 +83,8 @@ public class Biblioteca {
}
public
Boolean
ComprobarSacarLibro
(
Integer
ISBN
)
{
if
(
_unnamed_Catalogo_18
.
_controla
.
containsKey
(
ISBN
)){
Ejemplar
ejemplar
=
_unnamed_Catalogo_18
.
_controla
.
get
(
ISBN
);
if
(
catalogo
.
_controla
.
containsKey
(
ISBN
)){
Ejemplar
ejemplar
=
catalogo
.
_controla
.
get
(
ISBN
);
return
!
ejemplar
.
get_estado
().
equals
(
"deteriorado"
)
&&
ejemplar
.
get_numReservas
()
==
0
;
}
else
return
false
;
...
...
src/Catalogo.java
View file @
303c5d01
...
...
@@ -4,5 +4,8 @@ public class Catalogo {
private
Integer
_numeroLibros
;
private
Boolean
_librosMalEstado
;
public
Biblioteca
_unnamed_Biblioteca_24
;
public
HashMap
<
Integer
,
Ejemplar
>
_controla
;
public
HashMap
<
Integer
,
Ejemplar
>
_controla
=
new
HashMap
<>();
public
Catalogo
()
{
}
}
\ No newline at end of file
src/Ejemplar.java
View file @
303c5d01
...
...
@@ -2,7 +2,7 @@ public class Ejemplar extends Libro {
private
String
_iSBN
;
private
Integer
_idInventario
;
private
String
_fechaCompra
;
private
String
_estado
;
private
String
_estado
=
""
;
private
Boolean
_subjectstate
;
private
Integer
_numReservas
;
public
Sancion
_unnamed_Sancion_6
;
...
...
src/Lector.java
View file @
303c5d01
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
Lector
extends
Usuario
{
private
String
_tipo
;
private
String
_estado
;
private
String
_fechaPenalizacion
;
private
Integer
_numPenalizaciones
;
private
List
<
String
>
_historialPrestamos
;
public
Sancion
_sancion
;
public
EstrategiaHistorial
_estrategiaHistorial
;
private
String
_tipo
=
""
;
private
String
_estado
=
""
;
private
LocalDate
_fechaPenalizacion
;
private
Integer
_numPenalizaciones
=
0
;
private
List
<
String
>
_historialPrestamos
=
new
ArrayList
<>();
public
Sancion
_sancion
=
new
Sancion
();
public
EstrategiaHistorial
_estrategiaHistorial
=
new
EstrategiaHistorial
()
{
@Override
public
void
Anadir
()
{
}
@Override
public
void
Consultar
()
{
}
};
public
void
NotificarEstado
()
{
throw
new
UnsupportedOperationException
();
...
...
@@ -37,11 +49,11 @@ public class Lector extends Usuario {
throw
new
UnsupportedOperationException
();
}
public
String
get_fechaPenalizacion
()
{
public
LocalDate
get_fechaPenalizacion
()
{
return
_fechaPenalizacion
;
}
public
void
set_fechaPenalizacion
(
String
_fechaPenalizacion
)
{
public
void
set_fechaPenalizacion
(
LocalDate
_fechaPenalizacion
)
{
this
.
_fechaPenalizacion
=
_fechaPenalizacion
;
}
...
...
src/Libro.java
View file @
303c5d01
import
java.util.Observer
;
public
abstract
class
Libro
{
public
class
Libro
{
private
int
_iD
;
private
String
_titulo
;
private
Integer
_ano
;
...
...
src/Usuario.java
View file @
303c5d01
public
abstract
class
Usuario
{
private
String
_email
;
private
Integer
_idUsuario
;
private
String
_nombre
;
private
String
_tipoUsuario
;
private
String
_contrasena
;
private
String
_direccion
;
public
Libro
_libro
;
public
Biblioteca
_hay
;
private
String
_email
=
""
;
private
Integer
_idUsuario
=
0
;
private
String
_nombre
=
""
;
private
String
_tipoUsuario
=
""
;
private
String
_contrasena
=
""
;
private
String
_direccion
=
""
;
public
Libro
_libro
=
new
Libro
()
;
public
Biblioteca
_hay
=
null
;
public
Usuario
()
{
throw
new
UnsupportedOperationException
();
}
public
abstract
void
NotificarEstado
();
...
...
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