diff --git a/.github/workflows/Java17CImaven.yml b/.github/workflows/Java17CImaven.yml index 038cd61b..2b5d5f40 100644 --- a/.github/workflows/Java17CImaven.yml +++ b/.github/workflows/Java17CImaven.yml @@ -1,3 +1,5 @@ +#copio el archivo para ver si soluciona el problema por el que no me da el test ok + # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven @@ -22,19 +24,56 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' cache: maven - name: Build with Maven run: mvn -B package --file pom.xml + + - name: Check test coverage + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + + + + +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven - # 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 - # Optional: Upload coverage report +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +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@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml + - name: Check test coverage uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} + diff --git a/.github/workflows/Javamaven.yml b/.github/workflows/Javamaven.yml new file mode 100644 index 00000000..13b28ed9 --- /dev/null +++ b/.github/workflows/Javamaven.yml @@ -0,0 +1,39 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +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@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml + + - name: Check test coverage + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + + + diff --git a/README.md b/README.md index 47c98e44..b6ec4192 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,9 @@ Authors: - Carlos Lopez Nozal - Jesus Alonso Abad + +Alumnos grupo: +- Luis Ignacio de Luna +- Ahmad Marie Pascual +- Adrian Zamora +- Estíbalitz Díez diff --git a/src/test/java/ubu/gii/dass/c01/ReusablePoolTest.java b/src/test/java/ubu/gii/dass/c01/ReusablePoolTest.java index 4e8c38d0..137c8c15 100644 --- a/src/test/java/ubu/gii/dass/c01/ReusablePoolTest.java +++ b/src/test/java/ubu/gii/dass/c01/ReusablePoolTest.java @@ -3,7 +3,14 @@ */ package ubu.gii.dass.c01; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import java.lang.reflect.Field; +import java.util.Vector; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -11,20 +18,16 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Disabled; - - /** * @author alumno * */ public class ReusablePoolTest { - @BeforeAll - public static void setUp(){ + public static void setUp() { } - @AfterAll public static void tearDown() throws Exception { } @@ -32,32 +35,88 @@ public static void tearDown() throws Exception { /** * Test method for {@link ubu.gii.dass.c01.ReusablePool#getInstance()}. */ - @Test - @DisplayName("testGetInstance") - @Disabled("Not implemented yet") + @Test + @DisplayName("testGetInstance") + @Disabled("Not implemented yet") public void testGetInstance() { - + } /** * Test method for {@link ubu.gii.dass.c01.ReusablePool#acquireReusable()}. + * + * @author Ahmad Mareie Pascual + * Fecha: 09/02/2025 + * @throws Exception + * */ @Test - @DisplayName("testAcquireReusable") - @Disabled("Not implemented yet") - - public void testAcquireReusable() { - + @DisplayName("testAcquireReusable") + public void testAcquireReusable() throws Exception { + ReusablePool pool = ReusablePool.getInstance(); + Reusable external = new Reusable(); // Asumiendo constructor público + int initialSize = getPoolSize(pool); + pool.releaseReusable(external); // Agregar nueva instancia externa + assertEquals(initialSize + 1, getPoolSize(pool), "Superado el límite de tamaño del pool"); + // Adquirimos todas las instancias (originales + externa) + for (int i = 0; i < initialSize + 1; i++) { + pool.acquireReusable(); + } + try { + pool.acquireReusable(); + fail("Debería lanzar NotFreeInstanceException"); + } catch (NotFreeInstanceException e) { + System.err.println(e.getMessage()); + } } + // Método helper para obtener el tamaño del pool usando reflection + private int getPoolSize(ReusablePool pool) throws Exception { + Field reusablesField = ReusablePool.class.getDeclaredField("reusables"); + reusablesField.setAccessible(true); + Vector reusables = (Vector) reusablesField.get(pool); + return reusables.size(); + } + /** - * 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() { - + * Test method for + * {@link ubu.gii.dass.c01.ReusablePool#releaseReusable(ubu.gii.dass.c01.Reusable)}. + * Realizado por: Luis Ignacio de Luna Gómez + * Fecha: 09/02/2025 + * @throws DuplicatedInstanceException + */ + @Test + @DisplayName("git commit -m \"testReleaseReusable: Implementación del test para liberar y reutilizar objetos en ReusablePool\"\r\n" + // + "") + //@Disabled("Not implemented yet") //Desactivar para poder ejectuar la prueba + public void testReleaseReusable() throws DuplicatedInstanceException { + + try { + // Creo una instancia del pool + ReusablePool pool = ReusablePool.getInstance(); + + // Adquiero un objeto reutilizable + Reusable objeto = pool.acquireReusable(); + + assertNotNull(objeto, "El objeto adquirido no debe ser nulo"); + + // Libero el objeto reutilizable + pool.releaseReusable(objeto); + + // Adquiero un objeto reutilizable de nuevo + Reusable objetoNuevo = pool.acquireReusable(); + assertSame(objeto, objetoNuevo, "El objeto adquirido debe ser el mismo que el liberado"); + + //Verifico que el pool sigue permitiendonos la adquisición de objetos + Reusable objetoVerificador = pool.acquireReusable(); + assertNotNull(objetoVerificador, "El objeto adquirido no debe ser nulo"); + } + + catch (NotFreeInstanceException e) { + e.printStackTrace(); + assertTrue(false, "No debería lanzar excepción"); + } + } }