Skip to content

Instantly share code, notes, and snippets.

@AlfredoCasado
Created January 22, 2011 19:28
Show Gist options
  • Save AlfredoCasado/791377 to your computer and use it in GitHub Desktop.
Save AlfredoCasado/791377 to your computer and use it in GitHub Desktop.
public class CompraTestMocks {
PasarelaDePago pasarelaDePagoMock = createMock(PasarelaDePago.class);
Producto unProductoStub = createMock(Producto.class);
Compra compra = new Compra(pasarelaDePagoMock);
@Test public void
si_el_cliente_tiene_fondos_para_realizar_la_compra_tengo_que_cobrarle_a_traves_de_la_pasarela_de_pago() {
expect(unProductoStub.precio()).andReturn(50);
expect(pasarelaDePagoMock.tieneElUsuarioFondosPorValorDe(50)).andReturn(true);
pasarelaDePagoMock.cobrar(50);
replay(pasarelaDePagoMock);
replay(unProductoStub);
compra.anadir(unProductoStub);
compra.confirmar();
verify(pasarelaDePagoMock);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment