Skip to content
Open
Changes from 1 commit
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
31 changes: 29 additions & 2 deletions src/ubu/gii/dass/test/c01/ReusablePoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,45 @@ public void testAcquireReusable() {
*/
@Test
public void testReleaseReusable() throws NotFreeInstanceException {
Copy link
Owner Author

Choose a reason for hiding this comment

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

El método implementa múltiples casos de prueba.
Mejor crear un método por cada uno de los casos de prueba.
El nombre de los nuevos métodos puede ser testReleaseReusablexx, donde xx se corresponden con dos dígitos decimales que ayuden a identificar el caso de prueba en la documentación.


try {
// se libera del pool un objeto reusable, correcto
pool.releaseReusable(reusable1);
//se libera del pool un objeto reusable, correcto
pool.releaseReusable(reusable2);
// se intenta liberar el mismo objeto reusable,
// DuplicatedInstanceException
pool.releaseReusable(reusable1);
fail("Se esperaba excepci�n de tipo DuplicatedInstanceException");
Copy link
Owner Author

Choose a reason for hiding this comment

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

Utilizar etiquetas para probar lanzamiento de excepciones
@test(expected= DuplicatedInstanceException.class)
Repasar la documentación que se proporcionó en el enunciado de la práctica.


} catch (DuplicatedInstanceException e) {
assertEquals("Ya existe esa instancia en el pool.", e.getMessage());
} catch (Exception e) {
fail("No se espera ninguna excepcion");
}

// se a�ade el objeto reusable para dejar el pool vacio (estado inicial)

Copy link
Owner Author

Choose a reason for hiding this comment

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

¿Cuando se ejecuta este código de prueba?
El problema es que previamente se ha lanzado y capturado una excepción.

try {
//se intenta liberar un objeto nulo, Excepcion
pool.releaseReusable(null);
fail("Se esperaba excepci�n de tipo Exception que controle la liberaci�n de nulos");
Copy link
Owner Author

Choose a reason for hiding this comment

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

Eliminar el uso de fail para el tratamiento de excepciones ver esta documentación

}catch (Exception e){
Copy link
Owner Author

Choose a reason for hiding this comment

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

Utilizad el nombre de la clase concreta Excpetion capturada

assertEquals("No se puede liberar un objeto nulo", e.getMessage());
Copy link
Owner Author

Choose a reason for hiding this comment

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

¿Qué se comprueba con este assert?

}

try{
//se intenta liberar un objeto reusable, cuando ya esta completo el pool
Reusable reusable3=new Reusable();
pool.releaseReusable(reusable3);
fail("Se esperaba excepci�n de tipo Exception que controle la dimensi�n m�xima del pool");
Copy link
Owner Author

Choose a reason for hiding this comment

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

Comentado previamente.

}catch(Exception e){
assertEquals("No se puede liberar mas objetos que la dimension del pool", e.getMessage());

}

// se a�ade los objetos reusables para dejar el pool vacio (estado inicial)
reusable1 = pool.acquireReusable();
reusable2 = pool.acquireReusable();

}

}