-
Notifications
You must be signed in to change notification settings - Fork 135
Revisión de la práctica DASS01 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
a1c38df
9121a3b
b6dc09f
51a0c90
87a1fde
2bc1fda
63c412a
fab2ebd
28b9345
351f05c
4246606
089d527
8026e59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package ubu.gii.dass.c01; | ||
|
|
||
| public class FullPoolException extends Exception { | ||
|
|
||
| public FullPoolException(String msg){ | ||
| super(msg); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,23 +4,25 @@ | |
| import java.util.*; | ||
| /** | ||
| * Pool que gestiona dos objetos de tipo Reusables para poder ser compartidos. | ||
| * @author Carlos L�pez [email protected] | ||
| * @author Carlos López [email protected] | ||
| */ | ||
|
|
||
| public final class ReusablePool{ | ||
|
|
||
| private Vector<Reusable> reusables; | ||
| private static ReusablePool instance; | ||
| private int size; | ||
|
|
||
| private ReusablePool(int size){ | ||
| this.size = size; | ||
| reusables = new Vector<Reusable>(size); | ||
| for(int i=0;i<size;i++) | ||
| reusables.add(new Reusable()); | ||
| } | ||
|
|
||
| /** | ||
| * M�todo singleton que crea u obtiene la �nica instancia del Pool que gestiona dos objetos Reusables | ||
| * @return la instancia �nica del Pool | ||
| * Método singleton que crea u obtiene la única instancia del Pool que gestiona dos objetos Reusables | ||
| * @return la instancia única del Pool | ||
| * | ||
| */ | ||
| public static ReusablePool getInstance(){ | ||
|
|
@@ -49,11 +51,18 @@ public Reusable acquireReusable() throws NotFreeInstanceException{ | |
| * El cliente libera una instancia del objeto Reusable y se guarda en el Pool para poder ser utilizada por otro cliente. | ||
| * @param r una instancia objeto reusable | ||
| * @exception DuplicatedInstanceException si el objeto reusable ya existe en el pool | ||
| * @throws FullPoolException | ||
| * | ||
| */ | ||
|
|
||
| public void releaseReusable(Reusable r) throws DuplicatedInstanceException { | ||
| if (reusables.contains(r)==false){ | ||
| public void releaseReusable(Reusable r) throws DuplicatedInstanceException, FullPoolException { | ||
| if (r == null){ | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. El nombre de la excepción no es no es muy apropiado, ya que se lanza cuando recibe un objeto nulo. |
||
| throw new FullPoolException("No se puede liberar un objeto nulo"); | ||
| } | ||
| else if (reusables.size() >= this.size){ | ||
| throw new FullPoolException("No se puede liberar más objetos que la dimensión del pool"); | ||
| } | ||
| else if (reusables.contains(r)==false){ | ||
| reusables.add(r); | ||
| } | ||
| else{ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,56 +1,145 @@ | ||
| /** | ||
| * | ||
| */ | ||
| package ubu.gii.dass.test.c01; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * @author alumno | ||
| * | ||
| */ | ||
| public class ReusablePoolTest { | ||
|
|
||
| /** | ||
| * @throws java.lang.Exception | ||
| */ | ||
| @Before | ||
| public void setUp() throws Exception { | ||
| } | ||
|
|
||
| /** | ||
| * @throws java.lang.Exception | ||
| */ | ||
| @After | ||
| public void tearDown() throws Exception { | ||
| } | ||
|
|
||
| /** | ||
| * Test method for {@link ubu.gii.dass.c01.ReusablePool#getInstance()}. | ||
| */ | ||
| @Test | ||
| public void testGetInstance() { | ||
| fail("Not yet implemented"); | ||
| } | ||
|
|
||
| /** | ||
| * Test method for {@link ubu.gii.dass.c01.ReusablePool#acquireReusable()}. | ||
| */ | ||
| @Test | ||
| public void testAcquireReusable() { | ||
| fail("Not yet implemented"); | ||
| } | ||
|
|
||
| /** | ||
| * Test method for {@link ubu.gii.dass.c01.ReusablePool#releaseReusable(ubu.gii.dass.c01.Reusable)}. | ||
| */ | ||
| @Test | ||
| public void testReleaseReusable() { | ||
| fail("Not yet implemented"); | ||
| } | ||
|
|
||
| } | ||
| /** | ||
| * | ||
| */ | ||
| package ubu.gii.dass.test.c01; | ||
|
|
||
| import static org.junit.Assert.*; | ||
| import ubu.gii.dass.c01.*; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Clase Test que prueba la clase ReusablePool con 100% de cobertura. | ||
| * | ||
| * @author CUEVAS DÍEZ JOSÉ RAMÓN | ||
| * @author LÓPEZ MARÍN LAURA | ||
| * @author CUADRADO GARCÍA IRENE | ||
| * @author EPIKHIN ANTON | ||
| */ | ||
| public class ReusablePoolTest { | ||
|
|
||
| /** | ||
| * Pool que contendrá los objetos reusables | ||
| */ | ||
| private ReusablePool pool; | ||
| /** | ||
| * Objetos reusables; | ||
| */ | ||
| private Reusable reusable1, reusable2; | ||
|
|
||
| /** | ||
| * @throws java.lang.Exception | ||
| */ | ||
| @Before | ||
| public void setUp() throws Exception { | ||
| pool = ReusablePool.getInstance(); | ||
| reusable1 = pool.acquireReusable(); | ||
| reusable2 = pool.acquireReusable(); | ||
| } | ||
|
|
||
| /** | ||
| * @throws java.lang.Exception | ||
| */ | ||
| @After | ||
| public void tearDown() throws Exception { | ||
| pool.releaseReusable(reusable1); | ||
| pool.releaseReusable(reusable2); | ||
| } | ||
|
|
||
| /** | ||
| * Test method for {@link ubu.gii.dass.c01.ReusablePool#getInstance()}. | ||
| */ | ||
| @Test | ||
| public void testGetInstance() { | ||
| // Adquiere instancia de ReusablePool. | ||
| ReusablePool poolTest = ReusablePool.getInstance(); | ||
|
|
||
| // Comprueba que pool y poolTest son instancia de ReusablePool. | ||
| assertTrue(pool instanceof ReusablePool); | ||
| assertTrue(poolTest instanceof ReusablePool); | ||
|
|
||
| // Compara los dos objetos son de la misma instancia. | ||
| // Debido a que el metodo 'equals' no es sobreescrito, 'equals' y '==' | ||
| // darán el mismo resultado. | ||
| assertTrue(pool == poolTest); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Añadir el parámetro de mensaje informativo en el AssertTrue. Este comentario de texto debería estar extraido de la documentación de los casos de prueba de la memoria. |
||
| assertTrue(pool.equals(poolTest)); | ||
| } | ||
|
|
||
| /** | ||
| * Test method for {@link ubu.gii.dass.c01.ReusablePool#acquireReusable()}. | ||
| */ | ||
| @Test | ||
| public void testAcquireReusable() { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dividir el método en varios. Uno por cada caso de prueba. Utiliza el mismo nombre de método numerado. |
||
| // acquirir correctamente | ||
| try { | ||
| pool.releaseReusable(reusable2); | ||
| Reusable reusable3 = pool.acquireReusable(); | ||
| } catch (Exception e) { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cambiar estilo de comprobación de lanzamiento de excepciones guía |
||
| fail("No se esperaba ninguna excepción "); | ||
| } | ||
| try { | ||
| // acquirir sin posibilidad de hacerlo, NotFreeInstance | ||
| Reusable reusable4 = pool.acquireReusable(); | ||
| } catch (NotFreeInstanceException e) { | ||
| assertEquals("No hay más instancias reutilizables disponibles. Reintentalo más tarde", e.getMessage()); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Test method for | ||
| * {@link ubu.gii.dass.c01.ReusablePool#releaseReusable(ubu.gii.dass.c01.Reusable)} | ||
| * . | ||
| * | ||
| * @throws NotFreeInstanceException | ||
| */ | ||
| @Test | ||
| public void testReleaseReusable() throws NotFreeInstanceException { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. El método implementa múltiples casos de prueba. |
||
|
|
||
| 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"); | ||
| }catch (Exception e){ | ||
| assertEquals("No se puede liberar un objeto nulo", e.getMessage()); | ||
| } | ||
|
|
||
| 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, | ||
| } catch (Exception e) { | ||
| fail("No se espera ninguna excepcion"); | ||
| } | ||
| try{ | ||
| // DuplicatedInstanceException | ||
| reusable2 = pool.acquireReusable(); | ||
| pool.releaseReusable(reusable1); | ||
| fail("Se esperaba excepción de tipo DuplicatedInstanceException"); | ||
|
|
||
| } catch (DuplicatedInstanceException | FullPoolException e) { | ||
| assertEquals("Ya existe esa instancia en el pool.", e.getMessage()); | ||
| } | ||
|
|
||
| try{ | ||
| //se intenta liberar un objeto reusable, cuando ya esta completo el pool | ||
| pool.releaseReusable(reusable2); | ||
| Reusable reusable3=new Reusable(); | ||
| pool.releaseReusable(reusable3); | ||
| fail("Se esperaba excepción de tipo Exception que controle la dimensión máxima del pool"); | ||
| }catch(Exception e){ | ||
| assertEquals("No se puede liberar más objetos que la dimensión del pool", e.getMessage()); | ||
|
|
||
| } | ||
|
|
||
| // se añade los objetos reusables para dejar el pool vacio (estado inicial) | ||
| reusable1 = pool.acquireReusable(); | ||
| reusable2 = pool.acquireReusable(); | ||
|
|
||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Falta documentación de la excepción
FullPoolException