Skip to content

Instantly share code, notes, and snippets.

Set<String> cesta = new HashSet();
cesta.add("manzana");
cesta.add("platano");
cesta.add("fresa");
assertThat(cesta, anyOf(hasItem("manzana"),
hasItem("pera")));
Expected: (a collection containing "manzana" or a collection containing "pera")
got: <[kiwi, fresa, platano]>
)
public class EmailNotifierTest {
static final String TEST_BODY = "cuerpo de test";
static final String TEST_SUBJECT = "asunto de test";
final MailAdress alfredo = new MailAdress("[email protected]");
final EmailNotifier emailNotifier = new EmailNotifier();
@Test
public void shouldSendOneEmailToTheGivenEmailAdress() throws Exception {
public class MailTestMatchersAndUtilities {
public static Inbox inboxOf(final MailAdress userMailAdress) throws Exception {
return new Inbox(userMailAdress);
}
public static TypeSafeMatcher<Inbox> hasOneEmailWithSubject(final String expectedSubject) {
return new TypeSafeMatcher<Inbox>() {
@Override
public boolean matchesSafely(Inbox inbox) {
Expected: a message with subject: "test subject", in inbox
got: <Mails in inbox: 1 [subject: bad subject] >
)
public class Inbox {
public static final String INBOX = "INBOX";
public static final String POP3 = "pop3";
public Message[] inboxMessages;
public Inbox(final MailAdress mailAdress) throws Exception {
Folder folder = openInboxFolder(mailAdress);
inboxMessages = folder.getMessages();
}
@AlfredoCasado
AlfredoCasado / gist:772280
Created January 10, 2011 02:56
Iteración 1 con modelo anémico
public class Producto {
private int precio;
public int getPrecio() {
return precio;
}
public void setPrecio(int precio) {
this.precio = precio;
@AlfredoCasado
AlfredoCasado / gist:772297
Created January 10, 2011 03:10
Iteracion 1 con modelo
public class Producto {
private int precio;
public int precio() {
return precio;
}
}
@AlfredoCasado
AlfredoCasado / gist:772310
Created January 10, 2011 03:35
Iteracion 2 modelo anémico
public class Descuento {
private int porcentajeDeDescuento;
public int getPorcentajeDeDescuento() {
return porcentajeDeDescuento;
}
public void setPorcentajeDeDescuento(int porcentajeDeDescuento) {
this.porcentajeDeDescuento = porcentajeDeDescuento;
@AlfredoCasado
AlfredoCasado / gist:772333
Created January 10, 2011 03:55
Iteracion 2 modelo
public class Descuento {
private int porcentajeDeDescuento;
public int aplicar(int precioAntesDeAplicarDescuento) {
return (porcentajeDeDescuento/100)*precioAntesDeAplicarDescuento;
}
}