Skip to content

Instantly share code, notes, and snippets.

@AlfredoCasado
Created January 12, 2011 14:01
Show Gist options
  • Save AlfredoCasado/776187 to your computer and use it in GitHub Desktop.
Save AlfredoCasado/776187 to your computer and use it in GitHub Desktop.
Ejemplo stub
public class CompraTest {
Producto unProductoStub = mock(Producto.class);
Producto otroProductoStub = mock(Producto.class);
PasarelaDePago pasarelaDePagoStub = mock(PasarelaDePago.class);
Compra compra = new Compra(pasarelaDePagoStub);
@Test public void
si_el_cliente_tiene_fondos_para_realizar_la_compra_la_puedo_confirmar() {
when(unProductoStub.precio()).thenReturn(50);
when(otroProductoStub.precio()).thenReturn(25);
when(pasarelaDePagoStub.tieneElUsuarioFondosPorValorDe(75)).thenReturn(true);
compra.anadir(unProductoStub);
compra.anadir(otroProductoStub);
assertTrue(compra.confirmar());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment