Tests registrar fecha de devolución terminados

parent 9f39bbee
......@@ -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();
}
}
......@@ -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;
}
}
/*
* 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");
}
}
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