Created
January 16, 2010 23:11
-
-
Save plagelao/279081 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.blogspot.plagelao.contracttest; | |
import java.util.Collection; | |
import org.junit.Before; | |
import org.junit.Test; | |
import static org.junit.Assert.*; | |
public abstract class ContratoParaColecciones { | |
public ContratoParaColecciones() { | |
} | |
private Collection collection; | |
@Before | |
public final void setUp() { | |
collection = nuevaColeccion(); | |
} | |
public abstract Collection nuevaColeccion(); | |
@Test | |
public void unaColeccionNuevaDebeEstarVacia() { | |
assertTrue("Una colección recién creada debe estar vacía", collection.isEmpty()); | |
} | |
@Test | |
public void unaColeccionNuevaDebeTenerLongitudNula() { | |
assertEquals("Una colección recién creada debe tener longitud nula", 0, collection.size()); | |
} | |
@Test | |
public void insertarYEliminarElementosEnUnaColeccionModificaSuLongitud() { | |
Object objeto = new Object(); | |
collection.add(objeto); | |
assertEquals("Añadir un elemento aumenta en 1 su tamaño", 1, collection.size()); | |
collection.remove(objeto); | |
assertEquals("Eliminar un elemento disminuye en 1 su tamaño", 0, collection.size()); | |
} | |
@Test | |
public void limpiarUnaColeccionLaVaciaYDejaSuLongitudACero() { | |
collection.add(new Object()); | |
assertEquals("Añadir un elemento aumenta en 1 su tamaño", 1, collection.size()); | |
collection.add(new Object()); | |
assertEquals("Añadir un elemento aumenta en 1 su tamaño", 2, collection.size()); | |
collection.clear(); | |
assertTrue("Limpiar una colección la vacía", collection.isEmpty()); | |
assertEquals("Limpiar una colección la vacía", 0, collection.size()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment