Tests registrar fecha de devolución terminados

parent 9f39bbee
...@@ -2,9 +2,11 @@ package com.mycompany.Modelo; ...@@ -2,9 +2,11 @@ package com.mycompany.Modelo;
import java.util.Vector; import java.util.Vector;
import com.mycompany.Modelo.Prestamo; import com.mycompany.Modelo.Prestamo;
import java.time.LocalDate;
import java.util.Date; import java.util.Date;
public class GestorPrestamos { public class GestorPrestamos {
public Vector<Prestamo> _gestiona = new Vector<Prestamo>(); public Vector<Prestamo> _gestiona = new Vector<Prestamo>();
public GestorBiblioteca _unnamed_GestorBiblioteca_10; public GestorBiblioteca _unnamed_GestorBiblioteca_10;
public HistorialPrestamos _accede; public HistorialPrestamos _accede;
...@@ -14,15 +16,32 @@ public class GestorPrestamos { ...@@ -14,15 +16,32 @@ public class GestorPrestamos {
} }
public void crearPrestamo(Prestamo aPrestamo) { public void crearPrestamo(Prestamo aPrestamo) {
throw new UnsupportedOperationException(); _gestiona.add(aPrestamo);
} }
public void modificar(String aIdPrestamo, Prestamo aPrestamo) { public void modificar(String aIdPrestamo, Prestamo aPrestamo) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public void registrarFechaDevolucion(String aIdPrestamo, Date aFechaDevolucion) { public String registrarFechaDevolucion(int aIdPrestamo, LocalDate aFechaDevolucion) {
throw new UnsupportedOperationException(); 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) { public String getIdUsuario(String aIdPrestamo) {
......
...@@ -4,12 +4,14 @@ import java.util.Vector; ...@@ -4,12 +4,14 @@ import java.util.Vector;
import com.mycompany.Modelo.Penalización; import com.mycompany.Modelo.Penalización;
import java.util.Date; import java.util.Date;
import com.mycompany.persistencia.PrestamoDAO; import com.mycompany.persistencia.PrestamoDAO;
import java.time.LocalDate;
public class Prestamo { public class Prestamo {
private int _idPrestamo; private int _idPrestamo;
private Date _fecha; private LocalDate _fecha;
private Date _fechaTope; private LocalDate _fechaTope;
private Date _fechaDev; private LocalDate _fechaDev;
private int _numProrrogas; private int _numProrrogas;
public Lector _lector; public Lector _lector;
public Ejemplar _ejemplar; public Ejemplar _ejemplar;
...@@ -18,16 +20,22 @@ public class Prestamo { ...@@ -18,16 +20,22 @@ public class Prestamo {
public Vector<Penalización> _penalizacións = new Vector<Penalización>(); public Vector<Penalización> _penalizacións = new Vector<Penalización>();
public PrestamoDAO _unnamed_PrestamoDAO_; 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) { public Prestamo get(int aIdPrestamo) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public void set(Date aFechaDevolucion) { public void set(LocalDate aFechaDevolucion) {
throw new UnsupportedOperationException(); this._fechaDev = aFechaDevolucion;
} }
public Date getFechaTope() { public LocalDate getFechaTope() {
throw new UnsupportedOperationException(); return this._fechaTope;
} }
public void crearMulta(float aImporte) { public void crearMulta(float aImporte) {
...@@ -49,4 +57,9 @@ public class Prestamo { ...@@ -49,4 +57,9 @@ public class Prestamo {
public String penalizar(String aIdUsuario, Date aFechaPenalizacion) { public String penalizar(String aIdUsuario, Date aFechaPenalizacion) {
throw new UnsupportedOperationException(); 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