Created
July 15, 2018 19:22
-
-
Save rodrigovilar/ac15e2a389622223ad877821bb7f0147 to your computer and use it in GitHub Desktop.
POO Aula 11/07/2018
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 Produto { | |
private int id; | |
private String descricao; | |
private double preco; | |
public Produto() { } | |
public Produto(int id, String descricao, double preco) { | |
this.id = id; | |
this.descricao = descricao; | |
this.preco = preco; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public int getId() { | |
return id; | |
} | |
public void setDescricao(String descricao) { | |
this.descricao = descricao; | |
} | |
public String getDescricao() { | |
return descricao; | |
} | |
public void setPreco(double preco) { | |
this.preco = preco; | |
} | |
public double getPreco() { | |
return preco; | |
} | |
public void reajustarPreco(double percentual) { | |
if (percentual > 0) { | |
double reajuste = getPreco() * (percentual / 100); | |
setPreco(getPreco() + reajuste); | |
} | |
} | |
} |
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
import static org.junit.Assert.*; | |
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Test; | |
/** | |
* The test class ProdutoTest. | |
* | |
* @author (your name) | |
* @version (a version number or a date) | |
*/ | |
public class ProdutoTest | |
{ | |
/** | |
* Default constructor for test class ProdutoTest | |
*/ | |
public ProdutoTest() | |
{ | |
} | |
/** | |
* Sets up the test fixture. | |
* | |
* Called before every test case method. | |
*/ | |
@Before | |
public void setUp() | |
{ | |
} | |
/** | |
* Tears down the test fixture. | |
* | |
* Called after every test case method. | |
*/ | |
@After | |
public void tearDown() | |
{ | |
} | |
@Test | |
public void reajusteDezPorcento() | |
{ | |
Produto produto2 = new Produto(1, "Pastel", 10.00); | |
produto2.reajustarPreco(10.0); | |
assertEquals(11.0, produto2.getPreco(), 0.1); | |
} | |
@Test | |
public void reajuste20porcento() | |
{ | |
Produto produto1 = new Produto(2, "abc", 5.50); | |
produto1.reajustarPreco(20); | |
assertEquals(6.6, produto1.getPreco(), 0.1); | |
} | |
@Test | |
public void reajusteNegativo() | |
{ | |
Produto produto1 = new Produto(4, "Chocolate", 3); | |
produto1.reajustarPreco(-50); | |
assertEquals(3.0, produto1.getPreco(), 0.1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment