Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Nota {
- int valorInicial;
- Nota(int valorInicial){
- if (valorInicial >= 0 && valorInicial <=10){
- this.valorInicial = valorInicial;
- }
- }
- int getValor(){
- return valorInicial;
- }
- boolean aprobado(){
- return (valorInicial >= 4);
- }
- boolean desaprobado(){
- return (valorInicial <= 4);
- }
- void recuperar(int nuevoValor){
- if (valorInicial < 4 && nuevoValor > valorInicial && nuevoValor >= 0 && nuevoValor <= 10){
- valorInicial = nuevoValor;
- }
- }
- }
- import org.junit.Test;
- import org.junit.Assert;
- public class PruebaNota {
- @Test
- public void valorInicialNoCumpleCondiciones(){
- Nota nota = new Nota(15);
- int valorInicial = nota.getValor();
- Assert.assertEquals(0, valorInicial);
- }
- @Test
- public void pruebaRecuperarYAprobar(){
- Nota nota = new Nota(2);
- nota.recuperar(7);
- Assert.assertTrue(nota.aprobado());
- }
- @Test
- public void pruebaRecuperarYDesaprobar(){
- Nota nota = new Nota(2);
- nota.recuperar(1);
- int valorInicial = nota.getValor();
- Assert.assertEquals(2, valorInicial);
- }
- @Test
- public void recuperaYNuevoValorNoCumpleCondiciones(){
- Nota nota = new Nota(2);
- nota.recuperar(12);
- int valorInicial = nota.getValor();
- Assert.assertEquals(2, valorInicial);
- }
- @Test
- public void recuperarSiAprobe(){
- Nota nota = new Nota(4);
- nota.recuperar(8);
- int valor = nota.getValor();
- Assert.assertEquals(4, valor);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement