Tests registrar fecha de devolución terminados

parent 9f39bbee
...@@ -2,42 +2,61 @@ package com.mycompany.Modelo; ...@@ -2,42 +2,61 @@ 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 GestorBiblioteca _unnamed_GestorBiblioteca_10; public Vector<Prestamo> _gestiona = new Vector<Prestamo>();
public HistorialPrestamos _accede; public GestorBiblioteca _unnamed_GestorBiblioteca_10;
public HistorialPrestamos _accede;
public Prestamo consultar(String aIdPrestamo) {
throw new UnsupportedOperationException(); public Prestamo consultar(String aIdPrestamo) {
} throw new UnsupportedOperationException();
}
public void crearPrestamo(Prestamo aPrestamo) {
throw new UnsupportedOperationException(); public void crearPrestamo(Prestamo aPrestamo) {
} _gestiona.add(aPrestamo);
}
public void modificar(String aIdPrestamo, 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 registrarFechaDevolucion(int aIdPrestamo, LocalDate aFechaDevolucion) {
} if (aIdPrestamo <= 0) {
return "ID del préstamo debe ser superior a 0";
public String getIdUsuario(String aIdPrestamo) { } else if (aFechaDevolucion.isBefore(LocalDate.now())) {
throw new UnsupportedOperationException(); return "La fecha introducida debe ser actual o futura";
} } else {
for (Prestamo p : _gestiona) {
public String crearMulta(String aIdPrestamo, float aImporte) { if (p.getIdPrestamo() == aIdPrestamo) {
throw new UnsupportedOperationException(); if (p.getFechaTope().isBefore(aFechaDevolucion)) {
} return "Se ha sobrepasado la fecha tope de devolución";
} else {
public void multar(String aIdUsuario) { p.set(aFechaDevolucion);
throw new UnsupportedOperationException(); return "Fecha de devolución registrada";
} }
}
public void penalizarLector(String aIdUsuario, Date aFechaPenalizacion) {
throw new UnsupportedOperationException(); }
} }
} return "Préstamo no registrado en el sistema";
\ No newline at end of file }
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; ...@@ -4,49 +4,62 @@ 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 Date _fecha; private int _idPrestamo;
private Date _fechaTope; private LocalDate _fecha;
private Date _fechaDev; private LocalDate _fechaTope;
private int _numProrrogas; private LocalDate _fechaDev;
public Lector _lector; private int _numProrrogas;
public Ejemplar _ejemplar; public Lector _lector;
public GestorPrestamos _gestiona; public Ejemplar _ejemplar;
public HistorialPrestamos _colecciona; public GestorPrestamos _gestiona;
public Vector<Penalización> _penalizacións = new Vector<Penalización>(); public HistorialPrestamos _colecciona;
public PrestamoDAO _unnamed_PrestamoDAO_; public Vector<Penalización> _penalizacións = new Vector<Penalización>();
public PrestamoDAO _unnamed_PrestamoDAO_;
public Prestamo get(int aIdPrestamo) {
throw new UnsupportedOperationException(); public Prestamo(int _idPrestamo, LocalDate _fecha, LocalDate _fechaTope) {
} this._idPrestamo = _idPrestamo;
this._fecha = _fecha;
public void set(Date aFechaDevolucion) { this._fechaTope = _fechaTope;
throw new UnsupportedOperationException(); }
}
public Prestamo get(int aIdPrestamo) {
public Date getFechaTope() { throw new UnsupportedOperationException();
throw new UnsupportedOperationException(); }
}
public void set(LocalDate aFechaDevolucion) {
public void crearMulta(float aImporte) { this._fechaDev = aFechaDevolucion;
throw new UnsupportedOperationException(); }
}
public LocalDate getFechaTope() {
public Prestamo getUltimo() { return this._fechaTope;
throw new UnsupportedOperationException(); }
}
public void crearMulta(float aImporte) {
public String getIdUsuario() { throw new UnsupportedOperationException();
throw new UnsupportedOperationException(); }
}
public Prestamo getUltimo() {
public void multar(String aIdUsuario) { throw new UnsupportedOperationException();
throw new UnsupportedOperationException(); }
}
public String getIdUsuario() {
public String penalizar(String aIdUsuario, Date aFechaPenalizacion) { throw new UnsupportedOperationException();
throw new UnsupportedOperationException(); }
}
} public void multar(String aIdUsuario) {
\ No newline at end of file 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