This file contains hidden or 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
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); |
This file contains hidden or 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
public class Compra { | |
private final List<Producto> productos = new ArrayList(); | |
private final PasarelaDePago pasarelaDePago; | |
public Compra(PasarelaDePago pasarelaDePagoStub) { | |
this.pasarelaDePago = pasarelaDePagoStub; | |
} | |
public void anadir(Producto producto) { |
This file contains hidden or 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
@Test public void | |
al_confirmar_la_compra_me_devuelve_el_importe_cobrado_usuario_sin_usar_mockito() { | |
Producto productoStubCreadoManualmente = new Producto() { | |
@Override | |
public int precio() { | |
return PRECIO_DEL_UNICO_PRODUCTO_COMPRADO; | |
} | |
}; | |
compra.anadir(productoStubCreadoManualmente); |
This file contains hidden or 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
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); |
This file contains hidden or 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
public interface Descuento { | |
int aplicar(int precioAntesDeAplciarDescuento); | |
} | |
public class DescuentoConPorcentaje implements Descuento { | |
private int porcentajeDeDescuento; | |
public int aplicar(int precioAntesDeAplicarDescuento) { | |
return (porcentajeDeDescuento/100)*precioAntesDeAplicarDescuento; | |
} |
This file contains hidden or 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
public class Descuento { | |
private int porcentajeDeDescuento; | |
private int cantidadFijaDeDescuento; | |
private String tipoDeDescuento; | |
public int getPorcentajeDeDescuento() { | |
return porcentajeDeDescuento; | |
} |
This file contains hidden or 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
public class Descuento { | |
private int porcentajeDeDescuento; | |
public int aplicar(int precioAntesDeAplicarDescuento) { | |
return (porcentajeDeDescuento/100)*precioAntesDeAplicarDescuento; | |
} | |
} |
This file contains hidden or 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
public class Descuento { | |
private int porcentajeDeDescuento; | |
public int getPorcentajeDeDescuento() { | |
return porcentajeDeDescuento; | |
} | |
public void setPorcentajeDeDescuento(int porcentajeDeDescuento) { | |
this.porcentajeDeDescuento = porcentajeDeDescuento; |
This file contains hidden or 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
public class Producto { | |
private int precio; | |
public int precio() { | |
return precio; | |
} | |
} |
This file contains hidden or 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
public class Producto { | |
private int precio; | |
public int getPrecio() { | |
return precio; | |
} | |
public void setPrecio(int precio) { | |
this.precio = precio; |