Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Andrés Rojas Ortega
/
PR5_DS
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
8ca2e0e6
authored
Dec 21, 2022
by
Andrés Rojas Ortega
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Tests registrar fecha de devolución terminados
parent
9f39bbee
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
198 additions
and
82 deletions
prueba/src/main/java/com/mycompany/Modelo/GestorPrestamos.java
prueba/src/main/java/com/mycompany/Modelo/Prestamo.java
prueba/src/test/java/com/mycompany/Modelo/GestorPrestamosTest.java
prueba/src/main/java/com/mycompany/Modelo/GestorPrestamos.java
View file @
8ca2e0e6
...
...
@@ -2,42 +2,61 @@ package com.mycompany.Modelo;
import
java.util.Vector
;
import
com.mycompany.Modelo.Prestamo
;
import
java.time.LocalDate
;
import
java.util.Date
;
public
class
GestorPrestamos
{
public
Vector
<
Prestamo
>
_gestiona
=
new
Vector
<
Prestamo
>();
public
GestorBiblioteca
_unnamed_GestorBiblioteca_10
;
public
HistorialPrestamos
_accede
;
public
Prestamo
consultar
(
String
aIdPrestamo
)
{
throw
new
UnsupportedOperationException
();
}
public
void
crearPrestamo
(
Prestamo
aPrestamo
)
{
throw
new
UnsupportedOperationException
();
}
public
void
modificar
(
String
aIdPrestamo
,
Prestamo
aPrestamo
)
{
throw
new
UnsupportedOperationException
();
}
public
void
registrarFechaDevolucion
(
String
aIdPrestamo
,
Date
aFechaDevolucion
)
{
throw
new
UnsupportedOperationException
();
}
public
String
getIdUsuario
(
String
aIdPrestamo
)
{
throw
new
UnsupportedOperationException
();
}
public
String
crearMulta
(
String
aIdPrestamo
,
float
aImporte
)
{
throw
new
UnsupportedOperationException
();
}
public
void
multar
(
String
aIdUsuario
)
{
throw
new
UnsupportedOperationException
();
}
public
void
penalizarLector
(
String
aIdUsuario
,
Date
aFechaPenalizacion
)
{
throw
new
UnsupportedOperationException
();
}
}
\ No newline at end of file
public
Vector
<
Prestamo
>
_gestiona
=
new
Vector
<
Prestamo
>();
public
GestorBiblioteca
_unnamed_GestorBiblioteca_10
;
public
HistorialPrestamos
_accede
;
public
Prestamo
consultar
(
String
aIdPrestamo
)
{
throw
new
UnsupportedOperationException
();
}
public
void
crearPrestamo
(
Prestamo
aPrestamo
)
{
_gestiona
.
add
(
aPrestamo
);
}
public
void
modificar
(
String
aIdPrestamo
,
Prestamo
aPrestamo
)
{
throw
new
UnsupportedOperationException
();
}
public
String
registrarFechaDevolucion
(
int
aIdPrestamo
,
LocalDate
aFechaDevolucion
)
{
if
(
aIdPrestamo
<=
0
)
{
return
"ID del préstamo debe ser superior a 0"
;
}
else
if
(
aFechaDevolucion
.
isBefore
(
LocalDate
.
now
()))
{
return
"La fecha introducida debe ser actual o futura"
;
}
else
{
for
(
Prestamo
p
:
_gestiona
)
{
if
(
p
.
getIdPrestamo
()
==
aIdPrestamo
)
{
if
(
p
.
getFechaTope
().
isBefore
(
aFechaDevolucion
))
{
return
"Se ha sobrepasado la fecha tope de devolución"
;
}
else
{
p
.
set
(
aFechaDevolucion
);
return
"Fecha de devolución registrada"
;
}
}
}
}
return
"Préstamo no registrado en el sistema"
;
}
public
String
getIdUsuario
(
String
aIdPrestamo
)
{
throw
new
UnsupportedOperationException
();
}
public
String
crearMulta
(
String
aIdPrestamo
,
float
aImporte
)
{
throw
new
UnsupportedOperationException
();
}
public
void
multar
(
String
aIdUsuario
)
{
throw
new
UnsupportedOperationException
();
}
public
void
penalizarLector
(
String
aIdUsuario
,
Date
aFechaPenalizacion
)
{
throw
new
UnsupportedOperationException
();
}
}
prueba/src/main/java/com/mycompany/Modelo/Prestamo.java
View file @
8ca2e0e6
...
...
@@ -4,49 +4,62 @@ import java.util.Vector;
import
com.mycompany.Modelo.Penalizaci
ó
n
;
import
java.util.Date
;
import
com.mycompany.persistencia.PrestamoDAO
;
import
java.time.LocalDate
;
public
class
Prestamo
{
private
int
_idPrestamo
;
private
Date
_fecha
;
private
Date
_fechaTope
;
private
Date
_fechaDev
;
private
int
_numProrrogas
;
public
Lector
_lector
;
public
Ejemplar
_ejemplar
;
public
GestorPrestamos
_gestiona
;
public
HistorialPrestamos
_colecciona
;
public
Vector
<
Penalizaci
ó
n
>
_penalizaci
ó
ns
=
new
Vector
<
Penalizaci
ó
n
>();
public
PrestamoDAO
_unnamed_PrestamoDAO_
;
public
Prestamo
get
(
int
aIdPrestamo
)
{
throw
new
UnsupportedOperationException
();
}
public
void
set
(
Date
aFechaDevolucion
)
{
throw
new
UnsupportedOperationException
();
}
public
Date
getFechaTope
()
{
throw
new
UnsupportedOperationException
();
}
public
void
crearMulta
(
float
aImporte
)
{
throw
new
UnsupportedOperationException
();
}
public
Prestamo
getUltimo
()
{
throw
new
UnsupportedOperationException
();
}
public
String
getIdUsuario
()
{
throw
new
UnsupportedOperationException
();
}
public
void
multar
(
String
aIdUsuario
)
{
throw
new
UnsupportedOperationException
();
}
public
String
penalizar
(
String
aIdUsuario
,
Date
aFechaPenalizacion
)
{
throw
new
UnsupportedOperationException
();
}
}
\ No newline at end of file
private
int
_idPrestamo
;
private
LocalDate
_fecha
;
private
LocalDate
_fechaTope
;
private
LocalDate
_fechaDev
;
private
int
_numProrrogas
;
public
Lector
_lector
;
public
Ejemplar
_ejemplar
;
public
GestorPrestamos
_gestiona
;
public
HistorialPrestamos
_colecciona
;
public
Vector
<
Penalizaci
ó
n
>
_penalizaci
ó
ns
=
new
Vector
<
Penalizaci
ó
n
>();
public
PrestamoDAO
_unnamed_PrestamoDAO_
;
public
Prestamo
(
int
_idPrestamo
,
LocalDate
_fecha
,
LocalDate
_fechaTope
)
{
this
.
_idPrestamo
=
_idPrestamo
;
this
.
_fecha
=
_fecha
;
this
.
_fechaTope
=
_fechaTope
;
}
public
Prestamo
get
(
int
aIdPrestamo
)
{
throw
new
UnsupportedOperationException
();
}
public
void
set
(
LocalDate
aFechaDevolucion
)
{
this
.
_fechaDev
=
aFechaDevolucion
;
}
public
LocalDate
getFechaTope
()
{
return
this
.
_fechaTope
;
}
public
void
crearMulta
(
float
aImporte
)
{
throw
new
UnsupportedOperationException
();
}
public
Prestamo
getUltimo
()
{
throw
new
UnsupportedOperationException
();
}
public
String
getIdUsuario
()
{
throw
new
UnsupportedOperationException
();
}
public
void
multar
(
String
aIdUsuario
)
{
throw
new
UnsupportedOperationException
();
}
public
String
penalizar
(
String
aIdUsuario
,
Date
aFechaPenalizacion
)
{
throw
new
UnsupportedOperationException
();
}
public
int
getIdPrestamo
()
{
return
_idPrestamo
;
}
}
prueba/src/test/java/com/mycompany/Modelo/GestorPrestamosTest.java
0 → 100644
View file @
8ca2e0e6
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package
com
.
mycompany
.
Modelo
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.Month
;
import
org.assertj.core.api.Assertions
;
import
org.assertj.core.api.LocalDateTimeAssert
;
import
org.junit.Test
;
/**
*
* @author andresro
*/
public
class
GestorPrestamosTest
{
@Test
public
void
testRegistrarFechaDevolucion
()
{
GestorPrestamos
gestorPrestamos
=
new
GestorPrestamos
();
Prestamo
prestamo
=
new
Prestamo
(
1
,
LocalDate
.
of
(
2022
,
Month
.
DECEMBER
,
30
),
LocalDate
.
of
(
2023
,
Month
.
JANUARY
,
3
));
gestorPrestamos
.
crearPrestamo
(
prestamo
);
String
mensajeConfirmacion
=
gestorPrestamos
.
registrarFechaDevolucion
(
1
,
LocalDate
.
of
(
2022
,
Month
.
DECEMBER
,
26
));
Assertions
.
assertThat
(
mensajeConfirmacion
).
isEqualTo
(
"Fecha de devolución registrada"
);
}
@Test
public
void
testRegistrarFechaDevolucionPrestamoNoExiste
()
{
GestorPrestamos
gestorPrestamos
=
new
GestorPrestamos
();
String
mensajeConfirmacion
=
gestorPrestamos
.
registrarFechaDevolucion
(
1
,
LocalDate
.
of
(
2022
,
Month
.
DECEMBER
,
26
));
Assertions
.
assertThat
(
mensajeConfirmacion
).
isEqualTo
(
"Préstamo no registrado en el sistema"
);
}
@Test
public
void
testRegistrarFechaDevolucionPrestamoIdMenorZero
()
{
GestorPrestamos
gestorPrestamos
=
new
GestorPrestamos
();
String
mensajeConfirmacion
=
gestorPrestamos
.
registrarFechaDevolucion
(-
1
,
LocalDate
.
of
(
2022
,
Month
.
DECEMBER
,
26
));
Assertions
.
assertThat
(
mensajeConfirmacion
).
isEqualTo
(
"ID del préstamo debe ser superior a 0"
);
}
@Test
public
void
testRegistrarFechaDevolucionPrestamoIdIgualZero
()
{
GestorPrestamos
gestorPrestamos
=
new
GestorPrestamos
();
String
mensajeConfirmacion
=
gestorPrestamos
.
registrarFechaDevolucion
(-
1
,
LocalDate
.
of
(
2022
,
Month
.
DECEMBER
,
26
));
Assertions
.
assertThat
(
mensajeConfirmacion
).
isEqualTo
(
"ID del préstamo debe ser superior a 0"
);
}
@Test
public
void
testRegistrarFechaDevolucionFechaDevolucionSuperiorFechaTope
()
{
GestorPrestamos
gestorPrestamos
=
new
GestorPrestamos
();
Prestamo
prestamo
=
new
Prestamo
(
1
,
LocalDate
.
of
(
2022
,
Month
.
DECEMBER
,
30
),
LocalDate
.
of
(
2023
,
Month
.
JANUARY
,
3
));
gestorPrestamos
.
crearPrestamo
(
prestamo
);
String
mensajeConfirmacion
=
gestorPrestamos
.
registrarFechaDevolucion
(
1
,
LocalDate
.
of
(
2023
,
Month
.
DECEMBER
,
26
));
Assertions
.
assertThat
(
mensajeConfirmacion
).
isEqualTo
(
"Se ha sobrepasado la fecha tope de devolución"
);
}
@Test
public
void
testRegistrarFechaDevolucionFechaDevolucionPasada
()
{
GestorPrestamos
gestorPrestamos
=
new
GestorPrestamos
();
Prestamo
prestamo
=
new
Prestamo
(
1
,
LocalDate
.
of
(
2022
,
Month
.
DECEMBER
,
30
),
LocalDate
.
of
(
2023
,
Month
.
JANUARY
,
3
));
gestorPrestamos
.
crearPrestamo
(
prestamo
);
String
mensajeConfirmacion
=
gestorPrestamos
.
registrarFechaDevolucion
(
1
,
LocalDate
.
of
(
2021
,
Month
.
DECEMBER
,
26
));
Assertions
.
assertThat
(
mensajeConfirmacion
).
isEqualTo
(
"La fecha introducida debe ser actual o futura"
);
}
}
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