Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
400935a
Update README.md
ibaimoya Feb 20, 2025
bb9e2a3
Update README.md
ibaimoya Feb 20, 2025
3f9f967
Update README.md
ibaimoya Feb 20, 2025
ed867eb
Update README.md
ibaimoya Feb 20, 2025
6021e67
Update README.md
Nicop17 Feb 20, 2025
8198429
Update README.md
ibaimoya Feb 20, 2025
a3461ed
Actualización README.md
ibaimoya Feb 27, 2025
1a6e073
Añadido badge de maven a README.md
ibaimoya Feb 27, 2025
fe64a37
Update README.md
ibaimoya Feb 27, 2025
5c52efb
testGetInstance implemented
David52PG Feb 27, 2025
ec92da5
Merge branch 'master' of github.com:Nicop17/poolobject
David52PG Feb 27, 2025
cf8dece
fix testGetInstance
David52PG Feb 27, 2025
59907a6
Tests reusable y release
JuanUBU Feb 27, 2025
96ad05c
Método setUp de ReusablePoolTest.java
ibaimoya Feb 27, 2025
3908376
Añadida variable maxResources a ReusablPoolTest
ibaimoya Feb 27, 2025
898d3e4
Añadido try catch
JuanUBU Feb 27, 2025
33b8431
Update ReusablePoolTest.java
ibaimoya Feb 27, 2025
136a0e1
Update ReusablePoolTest.java
ibaimoya Feb 27, 2025
d94e42f
Modificación método tearDown()
Nicop17 Feb 27, 2025
ed7fa78
Update Java17CImaven.yml
Nicop17 Feb 27, 2025
302cd24
Update Java17CImaven.yml
Nicop17 Feb 27, 2025
01b6374
correciones de la falta de uso de releaseReusable en el ultimo caso d…
David52PG Feb 27, 2025
20fb49c
Merge branch 'master' of github.com:Nicop17/poolobject
David52PG Feb 27, 2025
351a0dd
workflow java17Clmaven.yml edit
David52PG Feb 27, 2025
4d5430b
Añadida badge de la Wiki en el Readme.md
ibaimoya Feb 27, 2025
37b80ba
Badge de la wiki corregida en el Readme
ibaimoya Feb 27, 2025
a85139b
Añadida badge de la licencia al README.md
ibaimoya Feb 27, 2025
2f25060
Correcciones README.md
ibaimoya Feb 27, 2025
8bef522
Más correcciones de README.md
ibaimoya Feb 27, 2025
39304bf
Borrado de directorio sobrante
ibaimoya Feb 27, 2025
ce8b53c
Ampliando pruebas para la cobertura completa de codigo
Nicop17 Feb 27, 2025
bbde4c5
Merge branch 'master' of https://github.com/Nicop17/poolobject
Nicop17 Feb 27, 2025
15bddfa
Mejora de los casos de prueba para conseguir mayor cobertura
ibaimoya Feb 27, 2025
e08a810
Mejora de los casos de prueba para obtener mayor cobertura de código
ibaimoya Feb 27, 2025
1fc89a9
Mejora de los casos de prueba para conseguir mayor cobertura
ibaimoya Feb 27, 2025
a4eba48
Mejora de los casos de prueba para conseguir mayor cobertura
ibaimoya Feb 27, 2025
96b6356
Mejora de los casos de prueba para conseguir mayor cobertura
ibaimoya Feb 27, 2025
de45e6d
Añadidos comentarios y correcciones menores
ibaimoya Feb 27, 2025
b20bfef
Añadidos comentarios y correcciones menores
ibaimoya Feb 27, 2025
d4c3247
Creación del directorio de imágenes
ibaimoya Feb 28, 2025
7f7b4d2
Añadida imagen de commits
ibaimoya Feb 28, 2025
b05c2f8
Borrado fichero temporal
ibaimoya Feb 28, 2025
919698f
Añadida la imagen de la cobertura
ibaimoya Feb 28, 2025
b5b102c
Añadida imagen de un error detectado por la integración continua
ibaimoya Feb 28, 2025
04236bd
Añadida imagen del número de workflow runs
ibaimoya Feb 28, 2025
c28e430
Create codacy-coverage.yml
Nicop17 Mar 12, 2025
75d1b92
Update codacy-coverage.yml
Nicop17 Mar 12, 2025
6aa89ad
Añadida badge de codebeat
ibaimoya Mar 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/Java17CImaven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ jobs:
- name: Update dependency graph
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
# Optional: Upload coverage report
- name: Check test coverage
uses: codecov/codecov-action@v4
- name: codecov
uses: codecov/codecov-action@v5.4.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: Nicop17/poolobject
41 changes: 41 additions & 0 deletions .github/workflows/codacy-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Codacy Coverage Reporter

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven

- name: Build with Maven
run: mvn -B package --file pom.xml

# Generar el reporte de cobertura de JaCoCo
- name: Run tests and generate coverage report
run: mvn test jacoco:report # Asegúrate de que se genere el reporte de cobertura

# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
- name: Update dependency graph
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6

# Subir el reporte de cobertura a Codacy
- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@v1.3.0
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: target/site/jacoco-aggregate.xml # Ruta del reporte generado por JaCoCo

15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
poolobject
==========

[![codecov](https://codecov.io/gh/Nicop17/poolobject/graph/badge.svg?token=D6XRI5RQA1)](https://codecov.io/gh/Nicop17/poolobject)
[![Java CI with Maven](https://github.com/Nicop17/poolobject/actions/workflows/Java17CImaven.yml/badge.svg)](https://github.com/Nicop17/poolobject/actions/workflows/Java17CImaven.yml)
[![codebeat badge](https://codebeat.co/badges/c0e21c3c-a6ab-4f31-a252-35818dd76e5a)](https://codebeat.co/projects/github-com-ibaimoya-poolobject-master)
[![License: GPL v2](https://img.shields.io/badge/License-GPL%20v2-orange.svg)](https://opensource.org/licenses/GPL-2.0)
[![Wiki Home](https://img.shields.io/badge/Wiki-Home-blue)](https://github.com/Nicop17/poolobject/wiki)




Java code example of creational design pattern pool object

Expand All @@ -10,3 +18,10 @@ Authors:

- Carlos Lopez Nozal
- Jesus Alonso Abad

Students:

- Ibai Moya
- Nicolás Pérez
- Juan García
- David Peñasco
Binary file added images/Ejemplo-error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Imagen-cobertura.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Monitorizacion-commits.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Numero-workflow.runs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
260 changes: 207 additions & 53 deletions src/test/java/ubu/gii/dass/c01/ReusablePoolTest.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,217 @@
/**
*
*/
package ubu.gii.dass.c01;

import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterEach;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Disabled;


import org.junit.jupiter.api.Test;

/**
* @author alumno
*
* Clase de pruebas unitarias.
* @author Ibai Moya
* @author David Peñasco
* @author Nicolás Pérez
* @author Juan García
*
*/
public class ReusablePoolTest {
private static ReusablePool pool;
private static final int MAX_RESOURCES = 2;

/**
* Reinicia la instancia del pool antes de cada prueba.
* @throws Exception si ocurre un error al reiniciar la instancia.
*/
@BeforeEach
public void resetPool() throws Exception {
Field instanceField = ReusablePool.class.getDeclaredField("instance");
instanceField.setAccessible(true);
instanceField.set(null, null);
pool = ReusablePool.getInstance();
}


/**
* Libera todas las instancias del pool al finalizar todas las pruebas.
* @throws Exception si ocurre un error al liberar las instancias.
*/
@AfterAll
public static void tearDown() throws Exception {
List<Reusable> acquiredReusables = new ArrayList<>();
/* Se adquieren todas las instancias disponibles del pool. */
while (true) {
try {
acquiredReusables.add(pool.acquireReusable());
} catch (NotFreeInstanceException e) {
break;
}
}
/* Se liberan las instancias obtenidas. */
for (Reusable reusable : acquiredReusables) {
try {
pool.releaseReusable(reusable);
} catch (DuplicatedInstanceException e) {
System.err.println("Error al liberar una instancia: " + e.getMessage());
}
}
}


/**
* Limpia el pool de reusables al finalizar cada prueba.
*/
@AfterEach
public void clearPools() {
List<Reusable> tempList = new ArrayList<>();
try {
/* Acumula todas las instancias adquiribles. */
while (true) {
tempList.add(pool.acquireReusable());
}
} catch (NotFreeInstanceException e) {
/* Cuando no se pueden adquirir más instancias se sale del bucle. */
}
/* Se devuelve todas las instancias acumuladas para restaurar el pool. */
for (Reusable reusable : tempList) {
try {
pool.releaseReusable(reusable);
} catch (Exception ex) {
/* Se ignoran las excepciones durante la restauración del pool. */
}
}
}


/**
* Método de prueba para la clase {@link ubu.gii.dass.c01.ReusablePool#getInstance()}.
*/
@Test
@DisplayName("testGetInstance")
public void testGetInstance() {
try {
ReusablePool pool1 = ReusablePool.getInstance();
ReusablePool pool2 = ReusablePool.getInstance();
assertNotNull(pool1, "La instancia pool1 no debería ser nula.");
assertNotNull(pool2, "La instancia pool2 no debería ser nula.");
assertSame(pool1, pool2, "Ambos deben ser idénticos.");
assertEquals(pool1, pool2, "Ambos deben ser iguales.");
} catch (Exception e) {
fail("Excepción en testGetInstance: " + e.getMessage());
}
}

/**
* Método de prueba para la clase {@link ubu.gii.dass.c01.ReusablePool#acquireReusable()}.
*/
@Test
@DisplayName("testAcquireReusable")
public void testAcquireReusable() {
/* Se almacenan las instancias adquiridas para posteriores comprobaciones. */
Reusable[] reusables = new Reusable[MAX_RESOURCES];

/* Se adquieren el número máximo de instancias disponibles. */
for (int i = 0; i < MAX_RESOURCES; i++) {
try {
reusables[i] = pool.acquireReusable();
assertNotNull(reusables[i], "El reusable obtenido es nulo.");
} catch (NotFreeInstanceException e) {
fail("Error al adquirir una nueva instancia reusable: " + e.getMessage());
}
}

/* Se verifica que cada instancia adquirida es única. */
for (int i = 0; i < MAX_RESOURCES - 1; i++) {
for (int j = i + 1; j < MAX_RESOURCES; j++) {
assertNotEquals(reusables[i], reusables[j], "Los reusables deben ser distintos.");
}
}

/* Se comprueba que una nueva adquisición lanza la excepción esperada. */
assertThrows(NotFreeInstanceException.class, () -> {
pool.acquireReusable();
}, "No se lanzó NotFreeInstanceException al intentar adquirir más instancias.");

/* Se prueba el caso límite: liberar una instancia y volver a adquirirla. */
try {
pool.releaseReusable(reusables[0]);
Reusable reciclado = pool.acquireReusable();
assertNotNull(reciclado, "El reusable reciclado es nulo.");
assertSame(reusables[0], reciclado, "El recurso debe ser reutilizado tras liberarlo.");
pool.releaseReusable(reciclado);
} catch (Exception e) {
fail("Error en el caso límite adicional de testAcquireReusable: " + e.getMessage());
}
}


/**
* Método de prueba para la clase {@link ubu.gii.dass.c01.ReusablePool#releaseReusable(ubu.gii.dass.c01.Reusable)}.
*/
@Test
@DisplayName("testReleaseReusable")
public void testReleaseReusable() {
try {
ReusablePool pool = ReusablePool.getInstance();
Reusable obj1 = pool.acquireReusable();
assertNotNull(obj1, "El reusable no debería ser nulo.");
pool.releaseReusable(obj1);

Reusable obj2 = pool.acquireReusable();
assertSame(obj1, obj2, "El reusable debe ser reutilizado.");
pool.releaseReusable(obj2);

/* Se prueba el caso límite: liberar null no debe lanzar excepción. */
assertDoesNotThrow(() -> pool.releaseReusable(null), "releaseReusable(null) no debe lanzar excepción.");

/* Se prueba el caso límite: liberar un objeto no gestionado por el pool no debe lanzar excepción. */
Reusable fakeReusable = new Reusable();
assertDoesNotThrow(() -> pool.releaseReusable(fakeReusable), "releaseReusable(fakeReusable) no debe lanzar excepción.");

/* Se prueba el caso límite: intentar liberar nuevamente el mismo objeto debe lanzar excepción. */
assertThrows(DuplicatedInstanceException.class, () -> {
pool.releaseReusable(obj2);
}, "No se lanzó DuplicatedInstanceException al intentar liberar dos veces el mismo objeto.");
} catch (Exception e) {
fail("Excepción en testReleaseReusable: " + e.getMessage());
}
}


/**
* Método de prueba para la clase {@link ubu.gii.dass.c01.Client#main()}.
*/
@Test
@DisplayName("testClientMain")
public void testClientMain() {

/* Se valida que Client se inicializa correctamente y que su método main se ejecute sin incidencias. */
Client clientInstance = new Client();
assertNotNull(clientInstance, "Se requería que la instancia de Client no fuese nula.");
assertDoesNotThrow(() -> Client.main(new String[]{}), "La ejecución de Client.main no debió lanzar excepción.");
}


/**
* Método de prueba para la clase {@link ubu.gii.dass.c01.Reusable#util()}.
*/
@Test
@DisplayName("testUtilMethod")
public void testUtilMethod() {


@BeforeAll
public static void setUp(){
}


@AfterAll
public static void tearDown() throws Exception {
}

/**
* Test method for {@link ubu.gii.dass.c01.ReusablePool#getInstance()}.
*/
@Test
@DisplayName("testGetInstance")
@Disabled("Not implemented yet")
public void testGetInstance() {

}

/**
* Test method for {@link ubu.gii.dass.c01.ReusablePool#acquireReusable()}.
*/
@Test
@DisplayName("testAcquireReusable")
@Disabled("Not implemented yet")

public void testAcquireReusable() {

}

/**
* Test method for {@link ubu.gii.dass.c01.ReusablePool#releaseReusable(ubu.gii.dass.c01.Reusable)}.
*/
@Test
@DisplayName("testReleaseReusable")
@Disabled("Not implemented yet")
public void testReleaseReusable() {

}

}
/* Se comprueba que el método util() retorne valores diferentes para instancias distintas. */
Reusable reusableA = new Reusable();
Reusable reusableB = new Reusable();
assertNotEquals(reusableA.util(), reusableB.util(), "Se esperaba que las salidas de util() fueran diferentes.");
}
}