diff --git a/dist/Programa Caja.jar b/dist/Programa Caja.jar index 4b63ec0..1daf23b 100644 Binary files a/dist/Programa Caja.jar and b/dist/Programa Caja.jar differ diff --git a/src/danielcortes/xyz/Main.java b/src/danielcortes/xyz/Main.java index 01da4dd..8ff9f2f 100644 --- a/src/danielcortes/xyz/Main.java +++ b/src/danielcortes/xyz/Main.java @@ -40,6 +40,7 @@ public class Main { static { setUpSystemProperties(); + DAOManager.setup(); updateDatabase(); } diff --git a/src/danielcortes/xyz/controllers/CajasController.java b/src/danielcortes/xyz/controllers/CajasController.java index 78f5073..34434d6 100644 --- a/src/danielcortes/xyz/controllers/CajasController.java +++ b/src/danielcortes/xyz/controllers/CajasController.java @@ -113,8 +113,12 @@ public class CajasController { DAOManager.getEfectivoDAO().insertDefault(efectivo); Documentos documentos = new Documentos(); + documentos.setTarjetas(0); + documentos.setCheques(0); + documentos.setRetiros(0); documentos.setCaja(c); - DAOManager.getDocumentosDAO().insertDefault(documentos); + DAOManager.getDocumentosDAO().insert(documentos); + return c; }); diff --git a/src/danielcortes/xyz/data/DAOManager.java b/src/danielcortes/xyz/data/DAOManager.java index 1349517..453697f 100644 --- a/src/danielcortes/xyz/data/DAOManager.java +++ b/src/danielcortes/xyz/data/DAOManager.java @@ -47,18 +47,18 @@ import danielcortes.xyz.models.version.VersionDAO; public class DAOManager { - private static final CajaDAO cajaDAO; - private static final CalculoFondoDAO calculoFondoDAO; - private static final DocumentosDAO documentosDAO; - private static final EfectivoDAO efectivoDAO; - private static final EgresoDAO egresoDAO; - private static final IngresoDAO ingresoDAO; - private static final TipoEgresoDAO tipoEgresoDAO; - private static final TipoIngresoDAO tipoIngresoDAO; - private static final EstadoResultadoDAO estadoResultadoDAO; - private static final VersionDAO versionDAO; + private static CajaDAO cajaDAO; + private static CalculoFondoDAO calculoFondoDAO; + private static DocumentosDAO documentosDAO; + private static EfectivoDAO efectivoDAO; + private static EgresoDAO egresoDAO; + private static IngresoDAO ingresoDAO; + private static TipoEgresoDAO tipoEgresoDAO; + private static TipoIngresoDAO tipoIngresoDAO; + private static EstadoResultadoDAO estadoResultadoDAO; + private static VersionDAO versionDAO; - static { + public static void setup() { cajaDAO = new SQLiteCajaDAO(); calculoFondoDAO = new SQLiteCalculoFondoDAO(); documentosDAO = new SQLiteDocumentosDAO(); @@ -71,6 +71,19 @@ public class DAOManager { versionDAO = new SQLiteVersionDAO(); } + public static void setup(ConnectionHolder connectionHolder){ + cajaDAO = new SQLiteCajaDAO(connectionHolder); + calculoFondoDAO = new SQLiteCalculoFondoDAO(connectionHolder); + documentosDAO = new SQLiteDocumentosDAO(connectionHolder); + efectivoDAO = new SQLiteEfectivoDAO(connectionHolder); + egresoDAO = new SQLiteEgresoDAO(connectionHolder); + ingresoDAO = new SQLiteIngresoDAO(connectionHolder); + tipoEgresoDAO = new SQLiteTipoEgresoDAO(connectionHolder); + tipoIngresoDAO = new SQLiteTipoIngresoDAO(connectionHolder); + estadoResultadoDAO = new SQLiteEstadoResultadoDAO(connectionHolder); + versionDAO = new SQLiteVersionDAO(connectionHolder); + } + public static CajaDAO getCajaDAO() { return cajaDAO; } diff --git a/src/danielcortes/xyz/data/SQLiteConnectionHolder.java b/src/danielcortes/xyz/data/SQLiteConnectionHolder.java index 0315d5c..fe3029c 100644 --- a/src/danielcortes/xyz/data/SQLiteConnectionHolder.java +++ b/src/danielcortes/xyz/data/SQLiteConnectionHolder.java @@ -35,6 +35,10 @@ public class SQLiteConnectionHolder implements ConnectionHolder { this.databaseURI = Configuration.get("sqlite_database_uri"); } + public SQLiteConnectionHolder(String databaseURI){ + this.databaseURI = databaseURI; + } + @Override public Connection getConnection() throws SQLException { Connection con = null; diff --git a/src/danielcortes/xyz/models/caja/Caja.java b/src/danielcortes/xyz/models/caja/Caja.java index ebb0543..b5503b2 100644 --- a/src/danielcortes/xyz/models/caja/Caja.java +++ b/src/danielcortes/xyz/models/caja/Caja.java @@ -25,6 +25,7 @@ package danielcortes.xyz.models.caja; import java.time.LocalDate; +import java.util.Objects; public class Caja { public final static Caja EMPTY = new Caja(); @@ -66,6 +67,26 @@ public class Caja { return "Caja{" + "id=" + id + ", fecha=" + fecha + + ", fondo=" + fondo + '}'; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Caja)) { + return false; + } + Caja caja = (Caja) o; + return id == caja.id && + fondo == caja.fondo && + Objects.equals(fecha, caja.fecha); + } + + @Override + public int hashCode() { + return Objects.hash(id, fecha, fondo); + } } diff --git a/src/danielcortes/xyz/models/caja/SQLiteCajaDAO.java b/src/danielcortes/xyz/models/caja/SQLiteCajaDAO.java index 4cb6a38..6f4a25d 100644 --- a/src/danielcortes/xyz/models/caja/SQLiteCajaDAO.java +++ b/src/danielcortes/xyz/models/caja/SQLiteCajaDAO.java @@ -24,6 +24,7 @@ package danielcortes.xyz.models.caja; +import danielcortes.xyz.data.ConnectionHolder; import danielcortes.xyz.data.SQLiteConnectionHolder; import java.sql.Connection; import java.sql.PreparedStatement; @@ -38,12 +39,16 @@ import org.apache.logging.log4j.Logger; public class SQLiteCajaDAO implements CajaDAO { private static final Logger log = LogManager.getLogger(SQLiteCajaDAO.class); - private SQLiteConnectionHolder connectionHolder; + private ConnectionHolder connectionHolder; public SQLiteCajaDAO() { this.connectionHolder = new SQLiteConnectionHolder(); } + public SQLiteCajaDAO(ConnectionHolder connectionHolder) { + this.connectionHolder = connectionHolder; + } + @Override public List getAll() { log.debug("Se intentara conseguir todas las Cajas"); diff --git a/src/danielcortes/xyz/models/calculo_fondo/CalculoFondo.java b/src/danielcortes/xyz/models/calculo_fondo/CalculoFondo.java index 1c15cae..fb15b9b 100644 --- a/src/danielcortes/xyz/models/calculo_fondo/CalculoFondo.java +++ b/src/danielcortes/xyz/models/calculo_fondo/CalculoFondo.java @@ -25,6 +25,7 @@ package danielcortes.xyz.models.calculo_fondo; import danielcortes.xyz.models.caja.Caja; +import java.util.Objects; public class CalculoFondo { @@ -74,4 +75,24 @@ public class CalculoFondo { ", caja=" + caja + '}'; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof CalculoFondo)) { + return false; + } + CalculoFondo that = (CalculoFondo) o; + return id == that.id && + valor == that.valor && + Objects.equals(descripcion, that.descripcion) && + Objects.equals(caja, that.caja); + } + + @Override + public int hashCode() { + return Objects.hash(id, valor, descripcion, caja); + } } diff --git a/src/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAO.java b/src/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAO.java index 2580ad2..c29f9aa 100644 --- a/src/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAO.java +++ b/src/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAO.java @@ -46,6 +46,10 @@ public class SQLiteCalculoFondoDAO implements CalculoFondoDAO { this.connectionHolder = new SQLiteConnectionHolder(); } + public SQLiteCalculoFondoDAO(ConnectionHolder connectionHolder) { + this.connectionHolder = connectionHolder; + } + @Override public List getAll() { log.debug("Se intentara conseguir todos los CalculosFondo"); diff --git a/src/danielcortes/xyz/models/documentos/Documentos.java b/src/danielcortes/xyz/models/documentos/Documentos.java index 51047fa..839c33b 100644 --- a/src/danielcortes/xyz/models/documentos/Documentos.java +++ b/src/danielcortes/xyz/models/documentos/Documentos.java @@ -25,6 +25,7 @@ package danielcortes.xyz.models.documentos; import danielcortes.xyz.models.caja.Caja; +import java.util.Objects; public class Documentos { public final static Documentos EMPTY; @@ -90,4 +91,25 @@ public class Documentos { ", caja=" + caja + '}'; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Documentos)) { + return false; + } + Documentos that = (Documentos) o; + return id == that.id && + cheques == that.cheques && + tarjetas == that.tarjetas && + retiros == that.retiros && + Objects.equals(caja, that.caja); + } + + @Override + public int hashCode() { + return Objects.hash(id, cheques, tarjetas, retiros, caja); + } } diff --git a/src/danielcortes/xyz/models/documentos/DocumentosDAO.java b/src/danielcortes/xyz/models/documentos/DocumentosDAO.java index 38bef0e..f5d8644 100644 --- a/src/danielcortes/xyz/models/documentos/DocumentosDAO.java +++ b/src/danielcortes/xyz/models/documentos/DocumentosDAO.java @@ -67,12 +67,6 @@ public interface DocumentosDAO { */ void insert(Documentos documentos); - /** - * Inserta un documentos con valores por default. - * @param documentos Instancia del documento a guardar - */ - void insertDefault(Documentos documentos); - /** * Actualiza un documentos * @param documentos Documento a actualizar diff --git a/src/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java b/src/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java index c09411c..7bc62a1 100644 --- a/src/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java +++ b/src/danielcortes/xyz/models/documentos/SQLiteDocumentosDAO.java @@ -46,6 +46,10 @@ public class SQLiteDocumentosDAO implements DocumentosDAO { this.connectionHolder = new SQLiteConnectionHolder(); } + public SQLiteDocumentosDAO(ConnectionHolder connectionHolder) { + this.connectionHolder = connectionHolder; + } + @Override public List getAll() { log.debug("Se intentaran conseguir todos los Documentos"); @@ -193,27 +197,6 @@ public class SQLiteDocumentosDAO implements DocumentosDAO { log.debug("Se inserto el documentos " + documentos); } - @Override - public void insertDefault(Documentos documentos) { - log.debug("Se intentara insertar el documento default " + documentos); - String query = "insert into documentos (cheques, tarjetas, retiros, caja_id) values (0,0,0,?)"; - try (Connection conn = connectionHolder.getConnection()) { - try (PreparedStatement ps = conn.prepareStatement(query)) { - ps.setInt(1, documentos.getCaja().getId()); - ps.executeUpdate(); - } - try (PreparedStatement ps = conn.prepareStatement("select last_insert_rowid()")) { - try (ResultSet rs = ps.executeQuery()) { - rs.next(); - documentos.setId(rs.getInt(1)); - } - } - } catch (SQLException e) { - log.error("Error al intentar insertar el documento por default " + documentos, e); - } - log.debug("Se inserto el documento por default " + documentos); - } - @Override public void update(Documentos documentos) { log.debug("Se intentara actualizar el documentos " + documentos); @@ -240,6 +223,7 @@ public class SQLiteDocumentosDAO implements DocumentosDAO { try (Connection conn = connectionHolder.getConnection()) { try (PreparedStatement ps = conn.prepareStatement(query)) { ps.setInt(1, documentos.getId()); + ps.execute(); } } catch (SQLException e) { log.error("Error al eliminar el documentos " + documentos, e); diff --git a/src/danielcortes/xyz/models/efectivo/Efectivo.java b/src/danielcortes/xyz/models/efectivo/Efectivo.java index eff5749..b8fd220 100644 --- a/src/danielcortes/xyz/models/efectivo/Efectivo.java +++ b/src/danielcortes/xyz/models/efectivo/Efectivo.java @@ -25,6 +25,7 @@ package danielcortes.xyz.models.efectivo; import danielcortes.xyz.models.caja.Caja; +import java.util.Objects; public class Efectivo { public final static Efectivo EMPTY; @@ -150,4 +151,33 @@ public class Efectivo { ", caja=" + caja + '}'; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Efectivo)) { + return false; + } + Efectivo efectivo = (Efectivo) o; + return id == efectivo.id && + veinteMil == efectivo.veinteMil && + diezMil == efectivo.diezMil && + cincoMil == efectivo.cincoMil && + dosMil == efectivo.dosMil && + mil == efectivo.mil && + quinientos == efectivo.quinientos && + cien == efectivo.cien && + cincuenta == efectivo.cincuenta && + diez == efectivo.diez && + Objects.equals(caja, efectivo.caja); + } + + @Override + public int hashCode() { + return Objects + .hash(id, veinteMil, diezMil, cincoMil, dosMil, mil, quinientos, cien, cincuenta, diez, + caja); + } } diff --git a/src/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java b/src/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java index a93bbc9..29a9aba 100644 --- a/src/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java +++ b/src/danielcortes/xyz/models/efectivo/SQLiteEfectivoDAO.java @@ -47,6 +47,10 @@ public class SQLiteEfectivoDAO implements EfectivoDAO { this.connectionHolder = new SQLiteConnectionHolder(); } + public SQLiteEfectivoDAO(ConnectionHolder connectionHolder) { + this.connectionHolder = connectionHolder; + } + @Override public List getAll() { log.debug("Se intentara conseguir todas los Efectivo"); diff --git a/src/danielcortes/xyz/models/egreso/Egreso.java b/src/danielcortes/xyz/models/egreso/Egreso.java index 2ac98aa..9fb8624 100644 --- a/src/danielcortes/xyz/models/egreso/Egreso.java +++ b/src/danielcortes/xyz/models/egreso/Egreso.java @@ -26,6 +26,7 @@ package danielcortes.xyz.models.egreso; import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.tipo_egreso.TipoEgreso; +import java.util.Objects; public class Egreso { @@ -85,7 +86,8 @@ public class Egreso { } @Override - public String toString() { + public String + toString() { return "Egreso{" + "id=" + id + ", nro='" + nro + '\'' + @@ -95,4 +97,26 @@ public class Egreso { ", caja=" + caja + '}'; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Egreso)) { + return false; + } + Egreso egreso = (Egreso) o; + return id == egreso.id && + valor == egreso.valor && + Objects.equals(nro, egreso.nro) && + Objects.equals(descripcion, egreso.descripcion) && + Objects.equals(tipoEgreso, egreso.tipoEgreso) && + Objects.equals(caja, egreso.caja); + } + + @Override + public int hashCode() { + return Objects.hash(id, nro, descripcion, valor, tipoEgreso, caja); + } } diff --git a/src/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java b/src/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java index 02530af..9c29cb3 100644 --- a/src/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java +++ b/src/danielcortes/xyz/models/egreso/SQLiteEgresoDAO.java @@ -52,6 +52,10 @@ public class SQLiteEgresoDAO implements EgresoDAO { this.connectionHolder = new SQLiteConnectionHolder(); } + public SQLiteEgresoDAO(ConnectionHolder connectionHolder) { + this.connectionHolder = connectionHolder; + } + @Override public List getAll() { log.debug("Se intentara conseguir todos los Egreso"); diff --git a/src/danielcortes/xyz/models/estado_resultado/EstadoResultado.java b/src/danielcortes/xyz/models/estado_resultado/EstadoResultado.java index a27e8c2..32eaed9 100644 --- a/src/danielcortes/xyz/models/estado_resultado/EstadoResultado.java +++ b/src/danielcortes/xyz/models/estado_resultado/EstadoResultado.java @@ -1,6 +1,7 @@ package danielcortes.xyz.models.estado_resultado; import java.time.YearMonth; +import java.util.Objects; public class EstadoResultado { @@ -182,5 +183,67 @@ public class EstadoResultado { public void setIvaFavor(int ivaFavor) { this.ivaFavor = ivaFavor; } + + @Override + public String toString() { + return "EstadoResultado{" + + "id=" + id + + ", mes=" + mes + + ", costoVenta=" + costoVenta + + ", cuentaCorrienteFactura=" + cuentaCorrienteFactura + + ", cuentaCorrienteBoleta=" + cuentaCorrienteBoleta + + ", cuentaCorrienteSinRespaldo=" + cuentaCorrienteSinRespaldo + + ", remuneraciones=" + remuneraciones + + ", finiquitos=" + finiquitos + + ", aguinaldo=" + aguinaldo + + ", bonosPersonal=" + bonosPersonal + + ", honorariosContador=" + honorariosContador + + ", arriendo=" + arriendo + + ", agua=" + agua + + ", luz=" + luz + + ", gas=" + gas + + ", telefono=" + telefono + + ", otroServicio=" + otroServicio + + ", ppm=" + ppm + + ", ivaFavor=" + ivaFavor + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof EstadoResultado)) { + return false; + } + EstadoResultado that = (EstadoResultado) o; + return id == that.id && + costoVenta == that.costoVenta && + cuentaCorrienteFactura == that.cuentaCorrienteFactura && + cuentaCorrienteBoleta == that.cuentaCorrienteBoleta && + cuentaCorrienteSinRespaldo == that.cuentaCorrienteSinRespaldo && + remuneraciones == that.remuneraciones && + finiquitos == that.finiquitos && + aguinaldo == that.aguinaldo && + bonosPersonal == that.bonosPersonal && + honorariosContador == that.honorariosContador && + arriendo == that.arriendo && + agua == that.agua && + luz == that.luz && + gas == that.gas && + telefono == that.telefono && + otroServicio == that.otroServicio && + Double.compare(that.ppm, ppm) == 0 && + ivaFavor == that.ivaFavor && + Objects.equals(mes, that.mes); + } + + @Override + public int hashCode() { + return Objects.hash(id, mes, costoVenta, cuentaCorrienteFactura, cuentaCorrienteBoleta, + cuentaCorrienteSinRespaldo, remuneraciones, finiquitos, aguinaldo, bonosPersonal, + honorariosContador, arriendo, agua, luz, gas, telefono, otroServicio, ppm, ivaFavor); + } } diff --git a/src/danielcortes/xyz/models/estado_resultado/SQLiteEstadoResultadoDAO.java b/src/danielcortes/xyz/models/estado_resultado/SQLiteEstadoResultadoDAO.java index 3cf76e5..acc8f55 100644 --- a/src/danielcortes/xyz/models/estado_resultado/SQLiteEstadoResultadoDAO.java +++ b/src/danielcortes/xyz/models/estado_resultado/SQLiteEstadoResultadoDAO.java @@ -1,5 +1,6 @@ package danielcortes.xyz.models.estado_resultado; +import danielcortes.xyz.data.ConnectionHolder; import danielcortes.xyz.data.SQLiteConnectionHolder; import java.sql.Connection; import java.sql.PreparedStatement; @@ -16,12 +17,16 @@ import org.apache.logging.log4j.Logger; public class SQLiteEstadoResultadoDAO implements EstadoResultadoDAO { private static final Logger log = LogManager.getLogger(SQLiteEstadoResultadoDAO.class); - private SQLiteConnectionHolder connectionHolder; + private ConnectionHolder connectionHolder; public SQLiteEstadoResultadoDAO() { this.connectionHolder = new SQLiteConnectionHolder(); } + public SQLiteEstadoResultadoDAO(ConnectionHolder connectionHolder) { + this.connectionHolder = connectionHolder; + } + @Override public List getAll() { log.debug("Se intentara conseguir todos los EstadoResultado"); diff --git a/src/danielcortes/xyz/models/ingreso/Ingreso.java b/src/danielcortes/xyz/models/ingreso/Ingreso.java index b8b60de..938cc7a 100644 --- a/src/danielcortes/xyz/models/ingreso/Ingreso.java +++ b/src/danielcortes/xyz/models/ingreso/Ingreso.java @@ -26,6 +26,7 @@ package danielcortes.xyz.models.ingreso; import danielcortes.xyz.models.caja.Caja; import danielcortes.xyz.models.tipo_ingreso.TipoIngreso; +import java.util.Objects; public class Ingreso { @@ -115,4 +116,28 @@ public class Ingreso { ", caja=" + caja + '}'; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Ingreso)) { + return false; + } + Ingreso ingreso = (Ingreso) o; + return id == ingreso.id && + valor == ingreso.valor && + Objects.equals(nroZInicial, ingreso.nroZInicial) && + Objects.equals(nroZFinal, ingreso.nroZFinal) && + Objects.equals(nroInicial, ingreso.nroInicial) && + Objects.equals(nroFinal, ingreso.nroFinal) && + Objects.equals(tipoIngreso, ingreso.tipoIngreso) && + Objects.equals(caja, ingreso.caja); + } + + @Override + public int hashCode() { + return Objects.hash(id, valor, nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja); + } } diff --git a/src/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java b/src/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java index 5084a94..5cf59bc 100644 --- a/src/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java +++ b/src/danielcortes/xyz/models/ingreso/SQLiteIngresoDAO.java @@ -52,6 +52,10 @@ public class SQLiteIngresoDAO implements IngresoDAO { this.connectionHolder = new SQLiteConnectionHolder(); } + public SQLiteIngresoDAO(ConnectionHolder connectionHolder) { + this.connectionHolder = connectionHolder; + } + @Override public List getAll() { log.debug("Se intententaran conseguir todos los Ingreso"); diff --git a/src/danielcortes/xyz/models/tipo_egreso/SQLiteTipoEgresoDAO.java b/src/danielcortes/xyz/models/tipo_egreso/SQLiteTipoEgresoDAO.java index 7f41ad4..20e09f3 100644 --- a/src/danielcortes/xyz/models/tipo_egreso/SQLiteTipoEgresoDAO.java +++ b/src/danielcortes/xyz/models/tipo_egreso/SQLiteTipoEgresoDAO.java @@ -36,10 +36,6 @@ import java.util.Optional; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -/** - * Objeto DAO que realiza las querys y mapeos necesarios del objeto TipoEgreso. En especifico esta - * implementacion se comunica con la base de datos SQLite - */ public class SQLiteTipoEgresoDAO implements TipoEgresoDAO { private static final Logger log = LogManager.getLogger(SQLiteTipoEgresoDAO.class); @@ -49,6 +45,10 @@ public class SQLiteTipoEgresoDAO implements TipoEgresoDAO { this.connectionHolder = new SQLiteConnectionHolder(); } + public SQLiteTipoEgresoDAO(ConnectionHolder connectionHolder) { + this.connectionHolder = connectionHolder; + } + @Override public List getAll() { log.debug("Se intentara conseguir todos los tipoEgreso"); diff --git a/src/danielcortes/xyz/models/tipo_egreso/TipoEgreso.java b/src/danielcortes/xyz/models/tipo_egreso/TipoEgreso.java index f51e53f..9f6c0b5 100644 --- a/src/danielcortes/xyz/models/tipo_egreso/TipoEgreso.java +++ b/src/danielcortes/xyz/models/tipo_egreso/TipoEgreso.java @@ -48,6 +48,8 @@ package danielcortes.xyz.models.tipo_egreso; +import java.util.Objects; + public class TipoEgreso { public final static TipoEgreso EMPTY; @@ -94,4 +96,22 @@ public class TipoEgreso { ", nombre='" + nombre + '\'' + '}'; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof TipoEgreso)) { + return false; + } + TipoEgreso that = (TipoEgreso) o; + return id == that.id && + Objects.equals(nombre, that.nombre); + } + + @Override + public int hashCode() { + return Objects.hash(id, nombre); + } } diff --git a/src/danielcortes/xyz/models/tipo_ingreso/SQLiteTipoIngresoDAO.java b/src/danielcortes/xyz/models/tipo_ingreso/SQLiteTipoIngresoDAO.java index e492063..9646284 100644 --- a/src/danielcortes/xyz/models/tipo_ingreso/SQLiteTipoIngresoDAO.java +++ b/src/danielcortes/xyz/models/tipo_ingreso/SQLiteTipoIngresoDAO.java @@ -45,6 +45,10 @@ public class SQLiteTipoIngresoDAO implements TipoIngresoDAO { this.connectionHolder = new SQLiteConnectionHolder(); } + public SQLiteTipoIngresoDAO(ConnectionHolder connectionHolder) { + this.connectionHolder = connectionHolder; + } + @Override public List getAll() { log.debug("Se intentara conseguir todos los TipoIngreso"); diff --git a/src/danielcortes/xyz/models/tipo_ingreso/TipoIngreso.java b/src/danielcortes/xyz/models/tipo_ingreso/TipoIngreso.java index 69281f6..f227c9e 100644 --- a/src/danielcortes/xyz/models/tipo_ingreso/TipoIngreso.java +++ b/src/danielcortes/xyz/models/tipo_ingreso/TipoIngreso.java @@ -48,6 +48,8 @@ package danielcortes.xyz.models.tipo_ingreso; +import java.util.Objects; + public class TipoIngreso { public final static TipoIngreso EMPTY; @@ -94,4 +96,22 @@ public class TipoIngreso { ", nombre='" + nombre + '\'' + '}'; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof TipoIngreso)) { + return false; + } + TipoIngreso that = (TipoIngreso) o; + return id == that.id && + Objects.equals(nombre, that.nombre); + } + + @Override + public int hashCode() { + return Objects.hash(id, nombre); + } } diff --git a/src/danielcortes/xyz/models/version/SQLiteVersionDAO.java b/src/danielcortes/xyz/models/version/SQLiteVersionDAO.java index 45500c1..7e6b047 100644 --- a/src/danielcortes/xyz/models/version/SQLiteVersionDAO.java +++ b/src/danielcortes/xyz/models/version/SQLiteVersionDAO.java @@ -28,6 +28,10 @@ public class SQLiteVersionDAO implements VersionDAO { this.connectionHolder = new SQLiteConnectionHolder(); } + public SQLiteVersionDAO(ConnectionHolder connectionHolder) { + this.connectionHolder = connectionHolder; + } + private boolean tableVersionsExists() { try { DatabaseMetaData md = this.connectionHolder.getConnection().getMetaData(); diff --git a/src/danielcortes/xyz/utils/RandomLocalDate.java b/src/danielcortes/xyz/utils/RandomLocalDate.java new file mode 100644 index 0000000..e745a34 --- /dev/null +++ b/src/danielcortes/xyz/utils/RandomLocalDate.java @@ -0,0 +1,21 @@ +package danielcortes.xyz.utils; + +import java.time.LocalDate; +import java.util.concurrent.ThreadLocalRandom; + +public class RandomLocalDate { + private static final LocalDate DEFAULT_FROM = LocalDate.of(1970,1,1); + private static final LocalDate DEFAULT_TO = LocalDate.of(2038,1,19); + + public static LocalDate random(){ + return randomBetween(DEFAULT_FROM, DEFAULT_TO); + } + + public static LocalDate randomBetween(LocalDate from, LocalDate to){ + long min = from.toEpochDay(); + long max = to.toEpochDay(); + long random = ThreadLocalRandom.current().nextLong(min, max); + return LocalDate.ofEpochDay(random); + } + +} diff --git a/test/danielcortes/xyz/models/caja/SQLiteCajaDAOTest.java b/test/danielcortes/xyz/models/caja/SQLiteCajaDAOTest.java new file mode 100644 index 0000000..6fd4f64 --- /dev/null +++ b/test/danielcortes/xyz/models/caja/SQLiteCajaDAOTest.java @@ -0,0 +1,159 @@ +package danielcortes.xyz.models.caja; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.github.javafaker.Faker; +import danielcortes.xyz.data.ConnectionHolder; +import danielcortes.xyz.data.DAOManager; +import danielcortes.xyz.data.SQLiteConnectionHolder; +import danielcortes.xyz.models.version.SQLiteVersionDAO; +import danielcortes.xyz.utils.RandomLocalDate; +import java.io.File; +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class SQLiteCajaDAOTest { + + static private int databaseVersion = 2; + static private SQLiteVersionDAO versionDAO; + static private ConnectionHolder connectionHolder; + static private Faker faker; + private SQLiteCajaDAO cajaDAO; + + @BeforeAll + static void setAll() { + connectionHolder = new SQLiteConnectionHolder("jdbc:sqlite:/tmp/tmp.sqlite"); + DAOManager.setup(connectionHolder); + versionDAO = new SQLiteVersionDAO(connectionHolder); + faker = new Faker(); + } + + @BeforeEach + void setUp() { + versionDAO.updateTo(databaseVersion); + this.cajaDAO = new SQLiteCajaDAO(connectionHolder); + } + + @AfterEach + void tearDown() { + //noinspection ResultOfMethodCallIgnored + new File("/tmp/tmp.sqlite").delete(); + } + + @Test + void getAll() { + Caja c1 = giveRandomCaja(); + Caja c2 = giveRandomCaja(); + + this.cajaDAO.insert(c1); + this.cajaDAO.insert(c2); + + List list = this.cajaDAO.getAll(); + + assertThat(list) + .hasSize(2) + .containsExactlyInAnyOrder(c1, c2); + } + + @Test + void getById() { + Caja c1 = giveRandomCaja(); + Caja c2 = giveRandomCaja(); + + this.cajaDAO.insert(c1); + this.cajaDAO.insert(c2); + + Optional o1 = this.cajaDAO.getById(c1.getId()); + Optional o2 = this.cajaDAO.getById(c2.getId()); + + assertThat(o1) + .isPresent() + .contains(c1); + + assertThat(o2) + .isPresent() + .contains(c2); + } + + @Test + void getByFecha() { + Caja c1 = giveRandomCaja(); + Caja c2 = giveRandomCaja(); + + this.cajaDAO.insert(c1); + this.cajaDAO.insert(c2); + + Optional o1 = this.cajaDAO.getByFecha(c1.getFecha()); + Optional o2 = this.cajaDAO.getByFecha(c2.getFecha()); + + assertThat(o1) + .isPresent() + .contains(c1); + + assertThat(o2) + .isPresent() + .contains(c2); + } + + @Test + void insert() { + Caja c1 = giveRandomCaja(); + Caja c2 = giveRandomCaja(); + + assertThat(0) + .isEqualTo(c1.getId()) + .isEqualTo(c2.getId()); + + this.cajaDAO.insert(c1); + this.cajaDAO.insert(c2); + + assertThat(0) + .isNotEqualTo(c1.getId()) + .isNotEqualTo(c2.getId()); + + List l = this.cajaDAO.getAll(); + assertThat(l) + .hasSize(2) + .containsExactlyInAnyOrder(c1, c2); + } + + @Test + void update() { + Caja c1 = giveRandomCaja(); + Caja c2 = giveRandomCaja(); + + this.cajaDAO.insert(c1); + this.cajaDAO.insert(c2); + + Caja u1 = giveRandomCaja(c1.getId()); + Caja u2 = giveRandomCaja(c2.getId()); + + this.cajaDAO.update(c1); + this.cajaDAO.update(c2); + + List l = this.cajaDAO.getAll(); + + assertThat(l) + .hasSize(2) + .containsExactlyInAnyOrder(c1, c2); + } + + Caja giveRandomCaja() { + Caja caja = new Caja(); + caja.setFondo(faker.number().numberBetween(0, 10000000)); + caja.setFecha(RandomLocalDate.random()); + return caja; + } + + Caja giveRandomCaja(int id) { + Caja caja = new Caja(); + caja.setId(id); + caja.setFondo(faker.number().numberBetween(0, 10000000)); + caja.setFecha(RandomLocalDate.random()); + return caja; + } +} \ No newline at end of file diff --git a/test/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAOTest.java b/test/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAOTest.java new file mode 100644 index 0000000..1d93101 --- /dev/null +++ b/test/danielcortes/xyz/models/calculo_fondo/SQLiteCalculoFondoDAOTest.java @@ -0,0 +1,258 @@ +package danielcortes.xyz.models.calculo_fondo; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.github.javafaker.Faker; +import danielcortes.xyz.data.ConnectionHolder; +import danielcortes.xyz.data.DAOManager; +import danielcortes.xyz.data.SQLiteConnectionHolder; +import danielcortes.xyz.models.caja.Caja; +import danielcortes.xyz.models.caja.CajaDAO; +import danielcortes.xyz.models.version.SQLiteVersionDAO; +import danielcortes.xyz.models.version.VersionDAO; +import danielcortes.xyz.utils.RandomLocalDate; +import java.io.File; +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class SQLiteCalculoFondoDAOTest { + private static Faker faker; + private static final int databaseVersion = 2; + private static VersionDAO versionDAO; + private CalculoFondoDAO calculoFondoDAO; + private CajaDAO cajaDAO; + + @BeforeAll + static void setAll() { + ConnectionHolder connectionHolder = new SQLiteConnectionHolder("jdbc:sqlite:/tmp/tmp.sqlite"); + DAOManager.setup(connectionHolder); + versionDAO = new SQLiteVersionDAO(connectionHolder); + faker = new Faker(); + } + + @BeforeEach + void setUp() { + versionDAO.updateTo(databaseVersion); + this.calculoFondoDAO = DAOManager.getCalculoFondoDAO(); + this.cajaDAO = DAOManager.getCajaDAO(); + } + + @AfterEach + void tearDown() { + //noinspection ResultOfMethodCallIgnored + new File("/tmp/tmp.sqlite").delete(); + } + + @Test + void getAll() { + Caja c = giveRandomCaja(); + this.cajaDAO.insert(c); + + CalculoFondo f1 = giveRandomCalculoFondo(c); + CalculoFondo f2 = giveRandomCalculoFondo(c); + + this.calculoFondoDAO.insert(f1); + this.calculoFondoDAO.insert(f2); + + List list = this.calculoFondoDAO.getAll(); + + assertThat(list) + .hasSize(2) + .contains(f1) + .contains(f2); + } + + @Test + void getByCaja() { + Caja c1 = giveRandomCaja(); + Caja c2 = giveRandomCaja(); + + this.cajaDAO.insert(c1); + this.cajaDAO.insert(c2); + + CalculoFondo f1 = giveRandomCalculoFondo(c1); + CalculoFondo f2 = giveRandomCalculoFondo(c1); + + CalculoFondo f3 = giveRandomCalculoFondo(c2); + CalculoFondo f4 = giveRandomCalculoFondo(c2); + CalculoFondo f5 = giveRandomCalculoFondo(c2); + + this.calculoFondoDAO.insert(f1); + this.calculoFondoDAO.insert(f2); + this.calculoFondoDAO.insert(f3); + this.calculoFondoDAO.insert(f4); + this.calculoFondoDAO.insert(f5); + + List l1 = this.calculoFondoDAO.getByCaja(c1); + List l2 = this.calculoFondoDAO.getByCaja(c2); + List l3 = this.calculoFondoDAO.getByCaja(Caja.EMPTY); + + assertThat(l1) + .hasSize(2) + .containsExactlyInAnyOrder(f1, f2) + .doesNotContain(f3, f4, f5); + + assertThat(l2) + .hasSize(3) + .containsExactlyInAnyOrder(f3, f4, f5) + .doesNotContain(f1, f2); + + assertThat(l3) + .hasSize(0); + } + + @Test + void getById() { + Caja c1 = giveRandomCaja(); + this.cajaDAO.insert(c1); + + CalculoFondo f1 = giveRandomCalculoFondo(c1); + CalculoFondo f2 = giveRandomCalculoFondo(c1); + + this.calculoFondoDAO.insert(f1); + this.calculoFondoDAO.insert(f2); + + Optional o1 = this.calculoFondoDAO.getById(f1.getId()); + Optional o2 = this.calculoFondoDAO.getById(f2.getId()); + Optional o3 = this.calculoFondoDAO.getById(-1); + + assertThat(o1) + .isPresent() + .contains(f1); + assertThat(o2) + .isPresent() + .contains(f2); + assertThat(o3) + .isEmpty(); + } + + @Test + void getTotalCalculoFondo() { + Caja c1 = giveRandomCaja(); + Caja c2 = giveRandomCaja(); + + this.cajaDAO.insert(c1); + this.cajaDAO.insert(c2); + + CalculoFondo f1 = giveRandomCalculoFondo(c1); + CalculoFondo f2 = giveRandomCalculoFondo(c1); + CalculoFondo f3 = giveRandomCalculoFondo(c2); + CalculoFondo f4 = giveRandomCalculoFondo(c2); + CalculoFondo f5 = giveRandomCalculoFondo(c2); + + this.calculoFondoDAO.insert(f1); + this.calculoFondoDAO.insert(f2); + this.calculoFondoDAO.insert(f3); + this.calculoFondoDAO.insert(f4); + this.calculoFondoDAO.insert(f5); + + int t1 = this.calculoFondoDAO.getTotalCalculoFondo(c1); + int t2 = this.calculoFondoDAO.getTotalCalculoFondo(c2); + + assertThat(t1) + .isEqualTo(f1.getValor() + f2.getValor()); + assertThat(t2) + .isEqualTo(f3.getValor() + f4.getValor() + f5.getValor()); + } + + @Test + void insert() { + Caja c1 = giveRandomCaja(); + this.cajaDAO.insert(c1); + + CalculoFondo f1 = giveRandomCalculoFondo(c1); + CalculoFondo f2 = giveRandomCalculoFondo(c1); + + assertThat(0) + .isEqualTo(f1.getId()) + .isEqualTo(f2.getId()); + + this.calculoFondoDAO.insert(f1); + this.calculoFondoDAO.insert(f2); + + assertThat(0) + .isNotEqualTo(f1.getId()) + .isNotEqualTo(f2.getId()); + + List l = this.calculoFondoDAO.getAll(); + + assertThat(l) + .hasSize(2) + .containsExactlyInAnyOrder(f1, f2); + } + + @Test + void update() { + Caja c1 = giveRandomCaja(); + Caja c2 = giveRandomCaja(); + this.cajaDAO.insert(c1); + this.cajaDAO.insert(c2); + + CalculoFondo f1 = giveRandomCalculoFondo(c1); + CalculoFondo f2 = giveRandomCalculoFondo(c1); + + this.calculoFondoDAO.insert(f1); + this.calculoFondoDAO.insert(f2); + + f1 = giveRandomCalculoFondo(c2, f1.getId()); + f2 = giveRandomCalculoFondo(c2, f2.getId()); + + this.calculoFondoDAO.update(f1); + this.calculoFondoDAO.update(f2); + + List l = this.calculoFondoDAO.getAll(); + + assertThat(l) + .hasSize(2) + .containsExactlyInAnyOrder(f1, f2); + } + + @Test + void delete() { + Caja c1 = giveRandomCaja(); + this.cajaDAO.insert(c1); + + CalculoFondo f1 = giveRandomCalculoFondo(c1); + CalculoFondo f2 = giveRandomCalculoFondo(c1); + this.calculoFondoDAO.insert(f1); + this.calculoFondoDAO.insert(f2); + + List l1 = this.calculoFondoDAO.getAll(); + + assertThat(l1) + .hasSize(2); + + this.calculoFondoDAO.delete(f1); + this.calculoFondoDAO.delete(f2); + + List l2 = this.calculoFondoDAO.getAll(); + + assertThat(l2) + .hasSize(0); + } + + Caja giveRandomCaja() { + Caja caja = new Caja(); + caja.setFondo(faker.number().numberBetween(0, 10000000)); + caja.setFecha(RandomLocalDate.random()); + return caja; + } + + CalculoFondo giveRandomCalculoFondo(Caja caja) { + CalculoFondo calculoFondo = new CalculoFondo(); + calculoFondo.setCaja(caja); + calculoFondo.setDescripcion(faker.lorem().characters()); + calculoFondo.setValor(faker.number().numberBetween(0, 10000000)); + return calculoFondo; + } + + CalculoFondo giveRandomCalculoFondo(Caja caja, int id) { + CalculoFondo calculoFondo = giveRandomCalculoFondo(caja); + calculoFondo.setId(id); + return calculoFondo; + } +} \ No newline at end of file diff --git a/test/danielcortes/xyz/models/documentos/SQLiteDocumentosDAOTest.java b/test/danielcortes/xyz/models/documentos/SQLiteDocumentosDAOTest.java new file mode 100644 index 0000000..6262bfa --- /dev/null +++ b/test/danielcortes/xyz/models/documentos/SQLiteDocumentosDAOTest.java @@ -0,0 +1,243 @@ +package danielcortes.xyz.models.documentos; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.github.javafaker.Faker; +import danielcortes.xyz.data.ConnectionHolder; +import danielcortes.xyz.data.DAOManager; +import danielcortes.xyz.data.SQLiteConnectionHolder; +import danielcortes.xyz.models.caja.Caja; +import danielcortes.xyz.models.caja.CajaDAO; +import danielcortes.xyz.models.version.SQLiteVersionDAO; +import danielcortes.xyz.models.version.VersionDAO; +import danielcortes.xyz.utils.RandomLocalDate; +import java.io.File; +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class SQLiteDocumentosDAOTest { + + private static final int databaseVersion = 2; + private static Faker faker; + private static VersionDAO versionDAO; + private DocumentosDAO documentosDAO; + private CajaDAO cajaDAO; + + @BeforeAll + static void setAll() { + ConnectionHolder connectionHolder = new SQLiteConnectionHolder("jdbc:sqlite:/tmp/tmp.sqlite"); + DAOManager.setup(connectionHolder); + versionDAO = new SQLiteVersionDAO(connectionHolder); + faker = new Faker(); + } + + @BeforeEach + void setUp() { + versionDAO.updateTo(databaseVersion); + this.documentosDAO = DAOManager.getDocumentosDAO(); + this.cajaDAO = DAOManager.getCajaDAO(); + } + + @AfterEach + void tearDown() { + //noinspection ResultOfMethodCallIgnored + new File("/tmp/tmp.sqlite").delete(); + } + + @Test + void getAll() { + Caja c1 = giveRandomCaja(); + + this.cajaDAO.insert(c1); + + Documentos d1 = giveRandomDocumentos(c1); + Documentos d2 = giveRandomDocumentos(c1); + + this.documentosDAO.insert(d1); + this.documentosDAO.insert(d2); + + List l = this.documentosDAO.getAll(); + + assertThat(l) + .hasSize(2) + .containsExactlyInAnyOrder(d1, d2); + } + + @Test + void getById() { + Caja c1 = giveRandomCaja(); + + this.cajaDAO.insert(c1); + + Documentos d1 = giveRandomDocumentos(c1); + Documentos d2 = giveRandomDocumentos(c1); + + this.documentosDAO.insert(d1); + this.documentosDAO.insert(d2); + + Optional o1 = this.documentosDAO.getById(d1.getId()); + Optional o2 = this.documentosDAO.getById(d2.getId()); + Optional o3 = this.documentosDAO.getById(-1); + + assertThat(o1) + .isPresent() + .contains(d1); + + assertThat(o2) + .isPresent() + .contains(d2); + + assertThat(o3) + .isEmpty(); + } + + @Test + void getByCaja() { + Caja c1 = giveRandomCaja(); + Caja c2 = giveRandomCaja(); + + this.cajaDAO.insert(c1); + this.cajaDAO.insert(c2); + + Documentos d1 = giveRandomDocumentos(c1); + Documentos d2 = giveRandomDocumentos(c2); + + this.documentosDAO.insert(d1); + this.documentosDAO.insert(d2); + + Optional o1 = this.documentosDAO.getByCaja(c1); + Optional o2 = this.documentosDAO.getByCaja(c2); + Optional o3 = this.documentosDAO.getByCaja(Caja.EMPTY); + + assertThat(o1) + .isPresent() + .contains(d1); + + assertThat(o2) + .isPresent() + .contains(d2); + + assertThat(o3) + .isEmpty(); + } + + @Test + void getTotalDocumentos() { + Caja c1 = giveRandomCaja(); + Caja c2 = giveRandomCaja(); + + this.cajaDAO.insert(c1); + this.cajaDAO.insert(c2); + + Documentos d1 = giveRandomDocumentos(c1); + Documentos d2 = giveRandomDocumentos(c2); + + this.documentosDAO.insert(d1); + this.documentosDAO.insert(d2); + + int t1 = this.documentosDAO.getTotalDocumentos(c1); + int t2 = this.documentosDAO.getTotalDocumentos(c2); + + assertThat(t1) + .isEqualTo(d1.getCheques() + d1.getRetiros() + d1.getTarjetas()); + + assertThat(t2) + .isEqualTo(d2.getCheques() + d2.getRetiros() + d2.getTarjetas()); + } + + @Test + void insert() { + Caja c1 = giveRandomCaja(); + + this.cajaDAO.insert(c1); + + Documentos d1 = giveRandomDocumentos(c1); + + assertThat(d1.getId()) + .isEqualTo(0); + + this.documentosDAO.insert(d1); + + assertThat(d1.getId()) + .isNotEqualTo(0); + + List l = this.documentosDAO.getAll(); + + assertThat(l) + .hasSize(1) + .containsExactlyInAnyOrder(d1); + } + + @Test + void update() { + Caja c1 = giveRandomCaja(); + Caja c2 = giveRandomCaja(); + + this.cajaDAO.insert(c1); + this.cajaDAO.insert(c2); + + Documentos d1 = giveRandomDocumentos(c1); + + this.documentosDAO.insert(d1); + + Documentos d2 = updateRandomDocumentos(d1); + + this.documentosDAO.update(d2); + + assertThat(d1.getId()).isEqualTo(d2.getId()); + + Optional o = this.documentosDAO.getById(d2.getId()); + + assertThat(o) + .isPresent() + .contains(d2); + } + + @Test + void delete() { + Caja c1 = giveRandomCaja(); + this.cajaDAO.insert(c1); + + Documentos d1 =giveRandomDocumentos(c1); + this.documentosDAO.insert(d1); + + assertThat(this.documentosDAO.getById(d1.getId())) + .isPresent() + .contains(d1); + + this.documentosDAO.delete(d1); + assertThat(this.documentosDAO.getById(d1.getId())) + .isEmpty(); + + assertThat(this.cajaDAO.getById(c1.getId())) + .isPresent() + .contains(c1); + + } + + Caja giveRandomCaja() { + Caja caja = new Caja(); + caja.setFondo(faker.number().numberBetween(0, 10000000)); + caja.setFecha(RandomLocalDate.random()); + return caja; + } + + Documentos giveRandomDocumentos(Caja caja) { + Documentos d = new Documentos(); + d.setCaja(caja); + d.setRetiros(faker.number().numberBetween(0, 10000000)); + d.setCheques(faker.number().numberBetween(0, 10000000)); + d.setTarjetas(faker.number().numberBetween(0, 10000000)); + return d; + } + + Documentos updateRandomDocumentos(Documentos documentos) { + Documentos d = giveRandomDocumentos(documentos.getCaja()); + d.setId(documentos.getId()); + return d; + } +} \ No newline at end of file diff --git a/test/danielcortes/xyz/utils/NaturalOrderComparatorTest.java b/test/danielcortes/xyz/utils/NaturalOrderComparatorTest.java index 3c02f13..a975517 100644 --- a/test/danielcortes/xyz/utils/NaturalOrderComparatorTest.java +++ b/test/danielcortes/xyz/utils/NaturalOrderComparatorTest.java @@ -24,15 +24,13 @@ package danielcortes.xyz.utils; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; +import static org.assertj.core.api.Assertions.assertThat; import java.util.ArrayList; import java.util.Collections; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; @TestInstance(TestInstance.Lifecycle.PER_CLASS) class NaturalOrderComparatorTest { @@ -77,14 +75,13 @@ class NaturalOrderComparatorTest { @Test void testIfArraySortIsCorrect(){ - assertNotEquals(toCompare, original); - NaturalOrderComparator comparator = new NaturalOrderComparator(); toCompare.sort(comparator); - assertEquals(toCompare, natural); - assertNotEquals(toCompare, lexicographic); - assertNotEquals(toCompare, original); + assertThat(toCompare) + .containsSequence(natural) + .doesNotContainSequence(lexicographic) + .doesNotContainSequence(original); } } \ No newline at end of file diff --git a/test/danielcortes/xyz/utils/StringUtilsTest.java b/test/danielcortes/xyz/utils/StringUtilsTest.java index fb23f70..3208d59 100644 --- a/test/danielcortes/xyz/utils/StringUtilsTest.java +++ b/test/danielcortes/xyz/utils/StringUtilsTest.java @@ -24,17 +24,15 @@ package danielcortes.xyz.utils; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; - class StringUtilsTest { - @Test void testIfUpercasedCorrectly() { - assertEquals("Barycentric", StringUtils.capitalize("barycentric")); - assertEquals("Showcased", StringUtils.capitalize("showcased")); - assertEquals("Failures", StringUtils.capitalize("failures")); - assertEquals("Scroogie", StringUtils.capitalize("scroogie")); + assertThat("Barycentric").isEqualTo(StringUtils.capitalize("barycentric")); + assertThat("Showcased").isEqualTo(StringUtils.capitalize("showcased")); + assertThat("Failures").isEqualTo(StringUtils.capitalize("failures")); + assertThat("Scroogie").isEqualTo(StringUtils.capitalize("scroogie")); } } \ No newline at end of file