Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@

#mvn target
/target

#Eclipse folders
/.settings
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
poolobject
==========
[![codecov](https://codecov.io/gh/CesarRodrigu/poolobject/graph/badge.svg?token=V19DNXQV64)](https://codecov.io/gh/CesarRodrigu/poolobject)
[![Java CI with Maven](https://github.com/CesarRodrigu/poolobject/actions/workflows/Java17CImaven.yml/badge.svg)](https://github.com/CesarRodrigu/poolobject/actions/workflows/Java17CImaven.yml)
[![codebeat badge](https://codebeat.co/badges/acb21344-f723-45e0-b21a-888590cce52e)](https://codebeat.co/projects/github-com-cesarrodrigu-poolobject-master)



Java code example of creational design pattern pool object
Expand All @@ -10,3 +14,15 @@ Authors:

- Carlos Lopez Nozal
- Jesus Alonso Abad

Editors:
- @CesarRodrigu - César Rodríguez Villagrá
- @cnunez1 - Christian Andrés Núñez Duque
- @Tibbitea - Beatrice Izabel Toth
- @Miiaalll - Salomiia Luhova


Información sobre las pruebas de cobertura:
https://github.com/CesarRodrigu/poolobject/wiki/Informe-de-Actividad,-Pruebas-y-Cobertura
https://github.com/CesarRodrigu/poolobject/wiki/Informe-de-Actividad,-Pruebas-y-Cobertura-2

119 changes: 97 additions & 22 deletions src/test/java/ubu/gii/dass/c01/ReusablePoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,136 @@
*/
package ubu.gii.dass.c01;

import static org.junit.jupiter.api.Assertions.assertTrue;
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.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
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
*
*/
public class ReusablePoolTest {
private static final int num = 2;
Copy link
Owner

@clopezno clopezno Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dos comentarios

  1. Por convención de nombres en Java las constantes se escriben en mayúsculas
  2. num no describe con precisión su objetivo, aconsejo renombrar POOL_TAM_MAX


/*
* Funcionalidad: Se ejecuta después de cada prueba e intenta adquirir todas las instancias reutilizables
* del pool y luego libera nuevas instancias para restablecer el estado del pool.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este comentario no es necesario.

*
* @throws NotFreeInstanceException si no hay instancias libres disponibles en el pool.
* @throws DuplicatedInstanceException si una instancia se libera más de una vez.
*/
@AfterEach
public void despues() {
ReusablePool pool = ReusablePool.getInstance();
System.out.println("Antes" + pool);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No se incluyen System.out.println en los test

try {
while (true) {
pool.acquireReusable();
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El objetivo de @AfterEach es liberar todo lo que se haya reservado en @beforeeach. Esta porción de código no procede.

} catch (NotFreeInstanceException e) {
try {
System.out.println("Med" + pool);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No se incluyen System.out.println en los test


for (int i = 0; i < ReusablePoolTest.num; i++) {
pool.releaseReusable(new Reusable());
}
} catch (Exception e1) {

}
}
System.out.println("Despues" + pool);


@BeforeAll
public static void setUp(){
}


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

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

ReusablePool pool1 = ReusablePool.getInstance();
ReusablePool pool2 = ReusablePool.getInstance();
assertNotNull(pool1);
assertNotNull(pool2);
assertSame(pool1, pool2);
assertEquals(pool1, pool2);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Añadir mensajes descriptivos del caso de prueba en los assert ayuda a mejorar la comprensión en caso de producirse el error detectado por la prueba. Este comentario de revisión intenta mejorar la facilidad de mantenimiento.

}

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

@DisplayName("testAcquireReusable")
public void testAcquireReusable() {

ReusablePool pool = ReusablePool.getInstance();
System.out.println(pool);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No se añade un system.out.println a una caso de prueba

try {
for (int i = 0; i < ReusablePoolTest.num; i++) {
pool.acquireReusable();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se necesita probar que pool.acquireReusable() retorna un objeto de Reusable.

Reusable reusable = pool.acquireReusable();
assertNotNull(reusable,"El objeto reusable adquirido no debería ser nulo");
assertTrue(reusable instanceof Reusable, "El objeto adquirido debe ser una instancia de Reusable");

}
} catch (NotFreeInstanceException e) {
fail("No deberia de llegar aqui");
}
assertThrows(NotFreeInstanceException.class, () -> {
pool.acquireReusable();
});
}

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

ReusablePool pool = ReusablePool.getInstance();
Reusable reusable = null;
try {
reusable = pool.acquireReusable();
} catch (NotFreeInstanceException e) {
fail("No debería llegar aquí");
}
try {
pool.releaseReusable(reusable);
} catch (DuplicatedInstanceException e) {
fail("No debería llegar aquí");
}
Reusable finalReusable = reusable;
assertThrows(DuplicatedInstanceException.class, () -> pool.releaseReusable(finalReusable));
}

/**
* Test method for {@link ubu.gii.dass.c01.Reusable#util}.
*/
@Test
@DisplayName("testReusableUtil")
public void testReusableUtil() {
assertNotEquals((new Reusable()).util(), (new Reusable()).util());
}

/**
* Test method for {@link ubu.gii.dass.c01.Client}.
*/
@Test
@DisplayName("testClient")
public void testClient() {
assertNotNull(new Client());
assertDoesNotThrow(() -> Client.main(null));
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esta prueba esta fuera del contexto de prueba Reusablepool se debería eliminar de este fichero. Además, Reusable es una implementación de compromiso que no debería ser probada. Entiendo que se ha añadido para conseguir el 100% de cobertura del sistema. Si se quiere eliminar el seguimiento de su cobertura se puede indicar en el fichero de configuración de .codecov.yml añadiendo

  ignore:
  - "src/main/java/ubu/gii/dass/c01/Client.java"
  - "src/main/java/ubu/gii/dass/c01/Reusable.java" 

}