├── .gitignore ├── .idea ├── .gitignore ├── vcs.xml ├── misc.xml ├── modules.xml └── uiDesigner.xml ├── src ├── main │ └── java │ │ ├── day04 │ │ ├── CurrentAccount.java │ │ ├── BankAccount.java │ │ └── SavingsAccount2.java │ │ ├── day03 │ │ ├── enums │ │ │ ├── Fruit.java │ │ │ └── FuelType.java │ │ ├── Monkey.java │ │ ├── Person.java │ │ └── GasStation.java │ │ ├── day05 │ │ ├── bank │ │ │ ├── Taxable.java │ │ │ └── Account.java │ │ └── forms │ │ │ ├── CalculableArea.java │ │ │ ├── Square.java │ │ │ ├── Circle.java │ │ │ ├── Rectangle.java │ │ │ └── Trapeze.java │ │ ├── day02 │ │ ├── Calculator.java │ │ ├── Employee.java │ │ └── Tv.java │ │ └── day01 │ │ ├── Invoice.java │ │ ├── PhysicalAssessment.java │ │ └── Client.java ├── Main.java └── test │ └── java │ ├── day05 │ ├── SquareTest.java │ ├── RectangleTest.java │ ├── TrapezeTest.java │ ├── CircleTest.java │ └── FormsTest.java │ ├── day01 │ ├── InvoiceTest.java │ ├── ClientTest.java │ └── PhysicalAssessmentTest.java │ ├── day02 │ ├── EmployeeTest.java │ ├── CalculatorTest.java │ └── TvTest.java │ ├── day03 │ ├── MonkeyTest.java │ ├── PersonTest.java │ └── GasStationTest.java │ └── day04 │ └── BankAccountTest.java ├── lib ├── opentest4j-1.2.0.jar ├── junit-jupiter-5.8.1.jar ├── apiguardian-api-1.1.2.jar ├── junit-jupiter-api-5.8.1.jar ├── junit-jupiter-engine-5.8.1.jar ├── junit-jupiter-params-5.8.1.jar ├── junit-platform-commons-1.8.1.jar └── junit-platform-engine-1.8.1.jar └── Aprendendo POO de uma vez por todas.iml /.gitignore: -------------------------------------------------------------------------------- 1 | # Project exclude paths 2 | /out/ -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /src/main/java/day04/CurrentAccount.java: -------------------------------------------------------------------------------- 1 | package main.java.day04; 2 | 3 | public class CurrentAccount { 4 | } 5 | -------------------------------------------------------------------------------- /lib/opentest4j-1.2.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/opentest4j-1.2.0.jar -------------------------------------------------------------------------------- /lib/junit-jupiter-5.8.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/junit-jupiter-5.8.1.jar -------------------------------------------------------------------------------- /src/main/java/day03/enums/Fruit.java: -------------------------------------------------------------------------------- 1 | package main.java.day03.enums; 2 | 3 | public enum Fruit { 4 | BANANA, ORANGE, APPLE; 5 | } 6 | -------------------------------------------------------------------------------- /lib/apiguardian-api-1.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/apiguardian-api-1.1.2.jar -------------------------------------------------------------------------------- /src/main/java/day05/bank/Taxable.java: -------------------------------------------------------------------------------- 1 | package main.java.day05.bank; 2 | 3 | public interface Taxable { 4 | double calculateTax(); 5 | } 6 | -------------------------------------------------------------------------------- /lib/junit-jupiter-api-5.8.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/junit-jupiter-api-5.8.1.jar -------------------------------------------------------------------------------- /lib/junit-jupiter-engine-5.8.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/junit-jupiter-engine-5.8.1.jar -------------------------------------------------------------------------------- /lib/junit-jupiter-params-5.8.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/junit-jupiter-params-5.8.1.jar -------------------------------------------------------------------------------- /lib/junit-platform-commons-1.8.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/junit-platform-commons-1.8.1.jar -------------------------------------------------------------------------------- /lib/junit-platform-engine-1.8.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/junit-platform-engine-1.8.1.jar -------------------------------------------------------------------------------- /src/main/java/day05/forms/CalculableArea.java: -------------------------------------------------------------------------------- 1 | package main.java.day05.forms; 2 | 3 | public interface CalculableArea { 4 | double calculateArea(); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/day03/enums/FuelType.java: -------------------------------------------------------------------------------- 1 | package main.java.day03.enums; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public enum FuelType { 6 | GASOLINE , ALCOOHOL; 7 | } 8 | -------------------------------------------------------------------------------- /src/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | System.out.println("Hello world!"); 4 | 5 | double i = 5d / 0d; 6 | System.out.println(i); 7 | } 8 | } -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/main/java/day05/forms/Square.java: -------------------------------------------------------------------------------- 1 | package main.java.day05.forms; 2 | 3 | public class Square extends Rectangle { 4 | public Square(double sideA, double sideB) { 5 | super(sideA, sideB); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/main/java/day05/forms/Circle.java: -------------------------------------------------------------------------------- 1 | package main.java.day05.forms; 2 | 3 | public class Circle implements CalculableArea { 4 | //attributes 5 | private double radius; 6 | 7 | public Circle(double radius) { 8 | this.radius = radius; 9 | } 10 | 11 | @Override 12 | public double calculateArea() { 13 | return Math.pow(this.radius, 2) * Math.PI; 14 | } 15 | 16 | public double getRadius() { 17 | return radius; 18 | } 19 | 20 | public void setRadius(double radius) { 21 | this.radius = radius; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/day05/SquareTest.java: -------------------------------------------------------------------------------- 1 | package test.java.day05; 2 | 3 | import main.java.day05.forms.Square; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | class SquareTest { 9 | private Square square; 10 | @BeforeEach 11 | void setUp() { 12 | square = new Square(4d, 4d); 13 | } 14 | 15 | @Test 16 | void shouldCalculateSquareArea_ThenReturnResult() { 17 | //given 18 | //when 19 | double actual = square.calculateArea(); 20 | //then 21 | double expected = 16d; 22 | Assertions.assertEquals(expected, actual); 23 | } 24 | } -------------------------------------------------------------------------------- /src/main/java/day02/Calculator.java: -------------------------------------------------------------------------------- 1 | package main.java.day02; 2 | 3 | public class Calculator { 4 | public static double calculate(double value1, double value2, char sign) { 5 | if (sign == '+') { 6 | return value1 + value2; 7 | } else if (sign == '-') { 8 | return value1 - value2; 9 | } else if (sign == '*') { 10 | return value1 * value2; 11 | } else if (sign == '/') { 12 | if (value2 == 0) { 13 | throw new ArithmeticException("Division impossible!"); 14 | } 15 | return value1 / value2; 16 | } else { 17 | throw new RuntimeException("This sign " + sign + " is invalid!"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/day05/RectangleTest.java: -------------------------------------------------------------------------------- 1 | package test.java.day05; 2 | 3 | import main.java.day05.forms.Rectangle; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | class RectangleTest { 9 | private Rectangle rectangle; 10 | @BeforeEach 11 | void setUp() { 12 | rectangle = new Rectangle(4d, 6d); 13 | } 14 | 15 | @Test 16 | void shouldCalculateRectangleArea_ThenReturnResult() { 17 | //given 18 | //when 19 | double actual = rectangle.calculateArea(); 20 | //then 21 | double expected = 24d; 22 | Assertions.assertEquals(expected, actual); 23 | } 24 | } -------------------------------------------------------------------------------- /src/test/java/day05/TrapezeTest.java: -------------------------------------------------------------------------------- 1 | package test.java.day05; 2 | 3 | import main.java.day05.forms.Trapeze; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | class TrapezeTest { 9 | //attributes 10 | private Trapeze trapeze; 11 | 12 | @BeforeEach 13 | void setUp() { 14 | trapeze = new Trapeze(12, 20, 15); 15 | } 16 | 17 | @Test 18 | void shouldCalculateTrapezeArea_ThenReturnResult() { 19 | //given 20 | //when 21 | double actual = trapeze.calculateArea(); 22 | //then 23 | double expected = 240d; 24 | Assertions.assertEquals(expected, actual); 25 | } 26 | } -------------------------------------------------------------------------------- /src/test/java/day01/InvoiceTest.java: -------------------------------------------------------------------------------- 1 | package test.java.day01; 2 | 3 | import main.java.day01.Invoice; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import java.math.BigDecimal; 9 | 10 | class InvoiceTest { 11 | private Invoice invoice; 12 | 13 | @BeforeEach 14 | void setup() { 15 | this.invoice = new Invoice(123L, "Description Item", 3, BigDecimal.TEN); 16 | } 17 | 18 | @Test 19 | void shouldReturnInvoiceAmount() { 20 | //given 21 | //when 22 | BigDecimal actual = this.invoice.getInvoiceAmount(); 23 | //then 24 | BigDecimal expected = BigDecimal.valueOf(30); 25 | Assertions.assertEquals(expected, actual); 26 | } 27 | } -------------------------------------------------------------------------------- /src/main/java/day05/forms/Rectangle.java: -------------------------------------------------------------------------------- 1 | package main.java.day05.forms; 2 | 3 | public class Rectangle implements CalculableArea { 4 | //attributes 5 | protected double sideA; 6 | protected double sideB; 7 | 8 | public Rectangle(double sideA, double sideB) { 9 | this.sideA = sideA; 10 | this.sideB = sideB; 11 | } 12 | 13 | @Override 14 | public double calculateArea() { 15 | return sideA * sideB; 16 | } 17 | 18 | public double getSideA() { 19 | return sideA; 20 | } 21 | 22 | public void setSideA(double sideA) { 23 | this.sideA = sideA; 24 | } 25 | 26 | public double getSideB() { 27 | return sideB; 28 | } 29 | 30 | public void setSideB(double sideB) { 31 | this.sideB = sideB; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/day01/ClientTest.java: -------------------------------------------------------------------------------- 1 | package test.java.day01; 2 | 3 | import main.java.day01.Client; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import java.time.LocalDate; 9 | import java.time.Month; 10 | 11 | class ClientTest { 12 | private Client client; 13 | 14 | @BeforeEach 15 | void setUp() { 16 | client = new Client(); 17 | } 18 | 19 | @Test 20 | void shouldReturnCurrentAge() { 21 | //given 22 | LocalDate birthDay = LocalDate.of(1994, Month.JANUARY, 13); 23 | client.setBirthDate(birthDay); 24 | //when 25 | int actual = client.calculateAge(); 26 | //then 27 | int expected = 28; 28 | Assertions.assertEquals(actual, expected); 29 | } 30 | } -------------------------------------------------------------------------------- /src/test/java/day02/EmployeeTest.java: -------------------------------------------------------------------------------- 1 | package test.java.day02; 2 | 3 | import main.java.day02.Employee; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import java.math.BigDecimal; 9 | 10 | import static org.junit.jupiter.api.Assertions.*; 11 | 12 | class EmployeeTest { 13 | private Employee employee; 14 | 15 | @BeforeEach 16 | void setUp() { 17 | this.employee = new Employee("Cami", BigDecimal.valueOf(100)); 18 | } 19 | 20 | @Test 21 | void shouldReturnSalaryWithIncrement() { 22 | //given 23 | double percentualIncrement = 10; 24 | //when 25 | BigDecimal actual = this.employee.incremetSalary(percentualIncrement); 26 | //then 27 | BigDecimal expected = BigDecimal.valueOf(110.0); 28 | Assertions.assertEquals(expected, actual); 29 | } 30 | } -------------------------------------------------------------------------------- /src/test/java/day05/CircleTest.java: -------------------------------------------------------------------------------- 1 | package test.java.day05; 2 | 3 | import main.java.day05.forms.Circle; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import java.text.DecimalFormat; 9 | 10 | class CircleTest { 11 | //attributes 12 | private Circle circle; 13 | 14 | @BeforeEach 15 | void setUp() { 16 | circle = new Circle(3d); 17 | } 18 | 19 | @Test 20 | void shouldCalculateCircleArea_ThenReturnResult() { 21 | //given 22 | DecimalFormat df = new DecimalFormat("#.00"); 23 | //when 24 | double actual = circle.calculateArea(); 25 | String actualFormat = df.format(actual); 26 | //then 27 | double expected = 28.27; 28 | String expectedFormat = df.format(expected); 29 | Assertions.assertEquals(expectedFormat, actualFormat); 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/day05/bank/Account.java: -------------------------------------------------------------------------------- 1 | package main.java.day05.bank; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class Account { 6 | //attributes 7 | private int number; 8 | private BigDecimal balance; 9 | 10 | public void toWithdraw(BigDecimal value) { 11 | if(value.compareTo(BigDecimal.ZERO) <= 0 || this.balance.compareTo(value) <= -1) { 12 | throw new IllegalArgumentException("Invalid value to withdraw"); 13 | } else { 14 | this.balance = this.balance.subtract(value); 15 | } 16 | } 17 | 18 | public void toDeposit(BigDecimal value) { 19 | if(value.compareTo(BigDecimal.ZERO) <= 0) { 20 | throw new IllegalArgumentException("Invalid value to deposit"); 21 | } else { 22 | this.balance = this.balance.add(value); 23 | } 24 | } 25 | 26 | public BigDecimal getBalance() { 27 | return balance; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/day02/Employee.java: -------------------------------------------------------------------------------- 1 | package main.java.day02; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class Employee { 6 | //attribute 7 | private String name; 8 | private BigDecimal salary; 9 | 10 | //constructor method 11 | public Employee(String name, BigDecimal salary) { 12 | this.name = name; 13 | this.salary = salary; 14 | } 15 | 16 | //methods 17 | public BigDecimal incremetSalary(double percentageIncrease) { 18 | BigDecimal percentagemIncreaseBigDecimal = BigDecimal.valueOf(1 + (percentageIncrease / 100)); 19 | return this.salary.multiply(percentagemIncreaseBigDecimal); 20 | } 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | public BigDecimal getSalary() { 30 | return salary; 31 | } 32 | 33 | public void setSalary(BigDecimal salary) { 34 | this.salary = salary; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/day04/BankAccount.java: -------------------------------------------------------------------------------- 1 | package main.java.day04; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public abstract class BankAccount { 6 | //attributes 7 | private String number; 8 | private String nameCustomer; 9 | private BigDecimal balance; 10 | 11 | //methods 12 | public abstract void toWithdraw(BigDecimal value); 13 | 14 | public abstract void toDeposit(BigDecimal value); 15 | 16 | public String getNumber() { 17 | return number; 18 | } 19 | 20 | protected void setNumber(String number) { 21 | this.number = number; 22 | } 23 | 24 | public String getNameCustomer() { 25 | return nameCustomer; 26 | } 27 | 28 | protected void setNameCustomer(String nameCustomer) { 29 | this.nameCustomer = nameCustomer; 30 | } 31 | 32 | public BigDecimal getBalance() { 33 | return balance; 34 | } 35 | 36 | protected void setBalance(BigDecimal balance) { 37 | this.balance = balance; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/day05/FormsTest.java: -------------------------------------------------------------------------------- 1 | package test.java.day05; 2 | 3 | import main.java.day05.forms.*; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | public class FormsTest { 9 | private Rectangle rectangle; 10 | private Square square; 11 | private Circle circle; 12 | private Trapeze trapeze; 13 | 14 | @BeforeEach 15 | void setUp() { 16 | rectangle = new Rectangle(4d, 6d); 17 | square = new Square(4d, 4d); 18 | circle = new Circle(3d); 19 | trapeze = new Trapeze(12d, 20d, 15d); 20 | } 21 | 22 | @Test 23 | void shouldCreateArrayWithAllForms() { 24 | //given 25 | //when 26 | CalculableArea[] forms = {this.rectangle, this.square, this.circle, this.trapeze}; 27 | CalculableArea actual = forms[2]; 28 | //then 29 | CalculableArea expected = this.circle; 30 | Assertions.assertEquals(expected, actual); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/day05/forms/Trapeze.java: -------------------------------------------------------------------------------- 1 | package main.java.day05.forms; 2 | 3 | public class Trapeze implements CalculableArea { 4 | //attributes 5 | private double baseA; 6 | private double baseB; 7 | private double height; 8 | 9 | public Trapeze(double baseA, double baseB, double height) { 10 | this.baseA = baseA; 11 | this.baseB = baseB; 12 | this.height = height; 13 | } 14 | 15 | @Override 16 | public double calculateArea() { 17 | return ((this.baseA + this.baseB)/2) * this.height; 18 | } 19 | 20 | public double getBaseA() { 21 | return baseA; 22 | } 23 | 24 | public void setBaseA(double baseA) { 25 | this.baseA = baseA; 26 | } 27 | 28 | public double getBaseB() { 29 | return baseB; 30 | } 31 | 32 | public void setBaseB(double baseB) { 33 | this.baseB = baseB; 34 | } 35 | 36 | public double getHeight() { 37 | return height; 38 | } 39 | 40 | public void setHeight(double height) { 41 | this.height = height; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/day02/Tv.java: -------------------------------------------------------------------------------- 1 | package main.java.day02; 2 | 3 | public class Tv { 4 | //attributes 5 | private int channelNumber; 6 | private int volume; 7 | 8 | //construct method 9 | public Tv(int channelNumber) { 10 | this.channelNumber = channelNumber; 11 | this.volume = 5; 12 | } 13 | 14 | //methods 15 | public void turnUpVolume() { 16 | this.volume++; 17 | if(this.volume > 10) { 18 | this.volume = 10; 19 | throw new RuntimeException("It's already at full volume"); 20 | } 21 | } 22 | 23 | public void turnDownVolume() { 24 | this.volume--; 25 | if(this.volume < 0) { 26 | this.volume = 0; 27 | throw new RuntimeException("It's already at minimum volume"); 28 | } 29 | } 30 | 31 | public int getChannelNumber() { 32 | return channelNumber; 33 | } 34 | 35 | public void setChannelNumber(int channelNumber) { 36 | this.channelNumber = channelNumber; 37 | } 38 | 39 | public int getVolume() { 40 | return volume; 41 | } 42 | 43 | public void setVolume(int volume) { 44 | this.volume = volume; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/day03/Monkey.java: -------------------------------------------------------------------------------- 1 | package main.java.day03; 2 | 3 | import main.java.day03.enums.Fruit; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class Monkey { 9 | //attributes 10 | private String name; 11 | private List stomach = new ArrayList<>(); 12 | 13 | //methods 14 | public void toEat(Object food) { 15 | if (food instanceof Fruit || food instanceof Monkey) { 16 | this.stomach.add(food); 17 | } else { 18 | throw new IllegalArgumentException("The Monkey doesn't eat this type of food!"); 19 | } 20 | } 21 | 22 | public void toDigest() { 23 | if (this.stomach.isEmpty()) { 24 | throw new RuntimeException("Stomach already empty!"); 25 | } else { 26 | //https://github.com/cami-la/mentoria_GFT_START_5_23052022/issues/5#issuecomment-1148802692 27 | this.stomach.remove(this.getStomach().get(0)); 28 | } 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public List getStomach() { 40 | return stomach; 41 | } 42 | 43 | public void setStomach(List stomach) { 44 | this.stomach = stomach; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Aprendendo POO de uma vez por todas.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/day04/SavingsAccount2.java: -------------------------------------------------------------------------------- 1 | package main.java.day04; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class SavingsAccount2 { 6 | //attributes 7 | private String number; 8 | private String nameCustomer; 9 | private BigDecimal balance; 10 | 11 | //constructor method 12 | public SavingsAccount2(String number, String nameCustomer) { 13 | this.number = number; 14 | this.nameCustomer = nameCustomer; 15 | this.balance = BigDecimal.valueOf(300d); 16 | } 17 | 18 | //methods 19 | public void toWithdraw(BigDecimal value) { 20 | if(value.compareTo(BigDecimal.ZERO) <= 0 || this.balance.compareTo(value) <= -1) { 21 | throw new IllegalArgumentException("Invalid value to withdraw"); 22 | } else { 23 | this.balance = this.balance.subtract(value); 24 | } 25 | } 26 | 27 | public void toDeposit(BigDecimal value) { 28 | if(value.compareTo(BigDecimal.ZERO) <= 0) { 29 | throw new IllegalArgumentException("Invalid value to deposit"); 30 | } else { 31 | this.balance = this.balance.add(value); 32 | } 33 | } 34 | 35 | public String getNumber() { 36 | return number; 37 | } 38 | 39 | public String getNameCustomer() { 40 | return nameCustomer; 41 | } 42 | 43 | public void setNameCustomer(String nameCustomer) { 44 | this.nameCustomer = nameCustomer; 45 | } 46 | 47 | public BigDecimal getBalance() { 48 | return balance; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/day03/Person.java: -------------------------------------------------------------------------------- 1 | package main.java.day03; 2 | 3 | import java.util.Objects; 4 | 5 | public class Person { 6 | //attributes 7 | private String name; 8 | private Person mother; 9 | private Person father; 10 | 11 | //constructor method 12 | 13 | public Person(String name) { 14 | this.name = name; 15 | } 16 | 17 | public Person(String name, Person mother, Person father) { 18 | this.name = name; 19 | this.mother = mother; 20 | this.father = father; 21 | } 22 | 23 | public Boolean isSiblings(Person person) { 24 | return this.mother.equals(person.mother) || this.father.equals(person.father); 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | public Person getMother() { 36 | return mother; 37 | } 38 | 39 | public void setMother(Person mother) { 40 | this.mother = mother; 41 | } 42 | 43 | public Person getFather() { 44 | return father; 45 | } 46 | 47 | public void setFather(Person father) { 48 | this.father = father; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object o) { 53 | if (this == o) return true; 54 | if (!(o instanceof Person person)) return false; 55 | return name.equals(person.name) && mother.equals(person.mother); 56 | } 57 | 58 | @Override 59 | public int hashCode() { 60 | return Objects.hash(name, mother); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/day01/Invoice.java: -------------------------------------------------------------------------------- 1 | package main.java.day01; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class Invoice { 6 | //attributes 7 | private Long idItem; 8 | private String descriptionItem; 9 | private int quantityItem; 10 | private BigDecimal itemPrice; 11 | 12 | //constructor method 13 | public Invoice(Long idItem, String descriptionItem, int quantityItem, BigDecimal itemPrice) { 14 | this.idItem = idItem; 15 | this.descriptionItem = descriptionItem; 16 | this.quantityItem = quantityItem; 17 | this.itemPrice = itemPrice; 18 | } 19 | 20 | //methods 21 | public BigDecimal getInvoiceAmount() { 22 | return this.getItemPrice().multiply(BigDecimal.valueOf(this.quantityItem)); 23 | } 24 | public Long getIdItem() { 25 | return idItem; 26 | } 27 | 28 | public void setIdItem(Long idItem) { 29 | this.idItem = idItem; 30 | } 31 | 32 | public String getDescriptionItem() { 33 | return descriptionItem; 34 | } 35 | 36 | public void setDescriptionItem(String descriptionItem) { 37 | this.descriptionItem = descriptionItem; 38 | } 39 | 40 | public int getQuantityItem() { 41 | return quantityItem; 42 | } 43 | 44 | public void setQuantityItem(int quantityItem) { 45 | this.quantityItem = quantityItem; 46 | } 47 | 48 | public BigDecimal getItemPrice() { 49 | return itemPrice; 50 | } 51 | 52 | public void setItemPrice(BigDecimal itemPrice) { 53 | this.itemPrice = itemPrice; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/day01/PhysicalAssessment.java: -------------------------------------------------------------------------------- 1 | package main.java.day01; 2 | 3 | public class PhysicalAssessment { 4 | //attributes 5 | private Long id; 6 | private Client client; 7 | private String professionalName; 8 | private double weight; 9 | private double height; 10 | private double imc; 11 | 12 | //methods 13 | public void calculateImc() { 14 | //imc = weight / (height)² 15 | this.imc = this.weight / Math.pow(this.height, 2); 16 | } 17 | 18 | public void addPhysicalAssessment() { 19 | this.client.getPhysicalAssessmentList().add(this); 20 | } 21 | 22 | public Long getId() { 23 | return id; 24 | } 25 | 26 | public void setId(Long id) { 27 | this.id = id; 28 | } 29 | 30 | public Client getClient() { 31 | return client; 32 | } 33 | 34 | public void setClient(Client client) { 35 | this.client = client; 36 | } 37 | 38 | public String getProfessionalName() { 39 | return professionalName; 40 | } 41 | 42 | public void setProfessionalName(String professionalName) { 43 | this.professionalName = professionalName; 44 | } 45 | 46 | public double getWeight() { 47 | return weight; 48 | } 49 | 50 | public void setWeight(double weight) { 51 | this.weight = weight; 52 | } 53 | 54 | public double getHeight() { 55 | return height; 56 | } 57 | 58 | public void setHeight(double height) { 59 | this.height = height; 60 | } 61 | 62 | public double getImc() { 63 | return imc; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/day01/Client.java: -------------------------------------------------------------------------------- 1 | package main.java.day01; 2 | 3 | import java.time.LocalDate; 4 | import java.time.Period; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class Client { 9 | //atributes 10 | private Long id; 11 | private LocalDate registerDate; 12 | private String name; 13 | private LocalDate birthDate; 14 | private String cep; 15 | private List physicalAssessmentList = new ArrayList<>(); 16 | 17 | //methods 18 | public int calculateAge() { 19 | //age = actualDate - bithDate; 20 | return Period.between(birthDate, LocalDate.now()).getYears(); 21 | } 22 | 23 | public Long getId() { 24 | return id; 25 | } 26 | 27 | public void setId(Long id) { 28 | this.id = id; 29 | } 30 | 31 | public LocalDate getRegisterDate() { 32 | return registerDate; 33 | } 34 | 35 | public void setRegisterDate(LocalDate registerDate) { 36 | this.registerDate = registerDate; 37 | } 38 | 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | public void setName(String name) { 44 | this.name = name; 45 | } 46 | 47 | public LocalDate getBirthDate() { 48 | return birthDate; 49 | } 50 | 51 | public void setBirthDate(LocalDate birthDate) { 52 | this.birthDate = birthDate; 53 | } 54 | 55 | public String getCep() { 56 | return cep; 57 | } 58 | 59 | public void setCep(String cep) { 60 | this.cep = cep; 61 | } 62 | 63 | public List getPhysicalAssessmentList() { 64 | return physicalAssessmentList; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/day01/PhysicalAssessmentTest.java: -------------------------------------------------------------------------------- 1 | package test.java.day01; 2 | 3 | import main.java.day01.Client; 4 | import main.java.day01.PhysicalAssessment; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.BeforeEach; 7 | import org.junit.jupiter.api.Test; 8 | 9 | import java.text.DecimalFormat; 10 | 11 | 12 | class PhysicalAssessmentTest { 13 | private PhysicalAssessment physicalAssessment; 14 | 15 | @BeforeEach 16 | void setUp() { 17 | this.physicalAssessment = new PhysicalAssessment(); 18 | } 19 | 20 | @Test 21 | void shouldCalculateCurrentImcValue() { 22 | //given 23 | double weight = 69d; 24 | double height = 1.71d; 25 | this.physicalAssessment.setWeight(weight); 26 | this.physicalAssessment.setHeight(height); 27 | DecimalFormat df = new DecimalFormat("#.0"); 28 | //when 29 | this.physicalAssessment.calculateImc(); 30 | double actual = physicalAssessment.getImc(); 31 | //then 32 | double expected = 23.6; 33 | 34 | String expectedFormat = df.format(expected); 35 | String actualFormat = df.format(actual); 36 | Assertions.assertEquals(expectedFormat, actualFormat); 37 | } 38 | 39 | @Test 40 | void shouldAddNewPhysicalAssessmentToClient() { 41 | //given 42 | Client client = new Client(); 43 | this.physicalAssessment.setClient(client); 44 | //when 45 | physicalAssessment.addPhysicalAssessment(); 46 | int actual = client.getPhysicalAssessmentList().size(); 47 | //then 48 | int expected = 1; 49 | Assertions.assertEquals(expected, actual); 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /src/test/java/day02/CalculatorTest.java: -------------------------------------------------------------------------------- 1 | package test.java.day02; 2 | 3 | import main.java.day02.Calculator; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.params.ParameterizedTest; 7 | import org.junit.jupiter.params.provider.CsvSource; 8 | 9 | import static org.junit.jupiter.api.Assertions.assertThrows; 10 | 11 | class CalculatorTest { 12 | private Calculator calculator; 13 | 14 | @ParameterizedTest 15 | @CsvSource({ 16 | "+, 4d", 17 | "-, 0d", 18 | "*, 4d", 19 | "/, 1d" 20 | }) 21 | void shouldReturnResultOperations(String sign, String result) { 22 | //given 23 | double value1 = 2d; 24 | double value2 = 2d; 25 | //when 26 | double actual = Calculator.calculate(value1, value2, sign.toCharArray()[0]); 27 | //then 28 | Assertions.assertEquals(actual, Double.valueOf(result)); 29 | } 30 | 31 | @Test 32 | void shouldThrowArithmeticException_WhenValueOfDivisionZero() { 33 | //given 34 | double value1 = 2d; 35 | double value2 = 0d; 36 | char sign = '/'; 37 | //when 38 | ArithmeticException actual = assertThrows(ArithmeticException.class, () -> { 39 | Calculator.calculate(value1, value2, sign); 40 | }); 41 | //then 42 | String expected = "Division impossible!"; 43 | Assertions.assertEquals(expected, actual.getMessage()); 44 | } 45 | 46 | @Test 47 | void shouldThrowRuntimeException_WhenValueOfOperatiorInvalid() { 48 | //given 49 | double value1 = 2d; 50 | double value2 = 0d; 51 | char sign = '%'; 52 | //when 53 | RuntimeException actual = assertThrows(RuntimeException.class, () -> { 54 | Calculator.calculate(value1, value2, sign); 55 | }); 56 | //then 57 | String expected = "This sign " + sign + " is invalid!"; 58 | Assertions.assertEquals(expected, actual.getMessage()); 59 | } 60 | } -------------------------------------------------------------------------------- /src/main/java/day03/GasStation.java: -------------------------------------------------------------------------------- 1 | package main.java.day03; 2 | 3 | import main.java.day03.enums.FuelType; 4 | 5 | import java.math.BigDecimal; 6 | 7 | public class GasStation { 8 | //atributes 9 | private FuelType fuelType; 10 | private BigDecimal priceFuel; 11 | private double quantityFuel; 12 | 13 | //constructor method 14 | public GasStation() { 15 | this.quantityFuel = 100; 16 | } 17 | 18 | //methods 19 | public double supply(BigDecimal value) { 20 | double quantityLiterSupply = value.divide(this.priceFuel).doubleValue(); 21 | if (quantityLiterSupply <= this.getQuantityFuel()) { 22 | double quantityFinalFuel = this.getQuantityFuel() - quantityLiterSupply; 23 | setQuantityFuel(quantityFinalFuel); 24 | return quantityFinalFuel; 25 | } else { 26 | throw new IllegalArgumentException( 27 | String.format("Impossible to supply this quantity %s of fuel!", value)); 28 | } 29 | } 30 | 31 | public BigDecimal supply(double quantityLiters) { 32 | if (quantityLiters <= this.getQuantityFuel()) { 33 | double quantityFinalFuel = getQuantityFuel() - quantityLiters; 34 | setQuantityFuel(quantityFinalFuel); 35 | return BigDecimal.valueOf(quantityLiters).multiply(getPriceFuel()); 36 | } else { 37 | throw new IllegalArgumentException( 38 | String.format("Impossible to supply this quantity %s of fuel!", quantityLiters)); 39 | } 40 | } 41 | 42 | public FuelType getFuelType() { 43 | return fuelType; 44 | } 45 | 46 | public void setFuelType(FuelType fuelType) { 47 | this.fuelType = fuelType; 48 | } 49 | 50 | public BigDecimal getPriceFuel() { 51 | return priceFuel; 52 | } 53 | 54 | public void setPriceFuel(BigDecimal priceFuel) { 55 | this.priceFuel = priceFuel; 56 | } 57 | 58 | public double getQuantityFuel() { 59 | return quantityFuel; 60 | } 61 | 62 | public void setQuantityFuel(double quantityFuel) { 63 | this.quantityFuel = quantityFuel; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/day02/TvTest.java: -------------------------------------------------------------------------------- 1 | package test.java.day02; 2 | 3 | import main.java.day02.Tv; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertThrows; 9 | 10 | class TvTest { 11 | private Tv tv; 12 | 13 | @BeforeEach 14 | void setUp() { 15 | this.tv = new Tv(10); 16 | } 17 | 18 | @Test 19 | void shouldTurnUpVolume() { 20 | //given 21 | //when 22 | this.tv.turnUpVolume(); 23 | this.tv.turnUpVolume(); 24 | this.tv.turnUpVolume(); 25 | int actual = this.tv.getVolume(); 26 | //then 27 | int expected = 8; 28 | Assertions.assertEquals(expected, actual); 29 | } 30 | 31 | @Test 32 | void shouldTurnDownVolume() { 33 | //given 34 | //when 35 | this.tv.turnDownVolume(); 36 | this.tv.turnDownVolume(); 37 | this.tv.turnDownVolume(); 38 | int actual = this.tv.getVolume(); 39 | //then 40 | int expected = 2; 41 | Assertions.assertEquals(expected, actual); 42 | } 43 | 44 | @Test 45 | void shouldThrowRuntimeException_WhenTryTurnUpVolumeUpZero() { 46 | //given 47 | this.tv.setVolume(10); 48 | //when 49 | RuntimeException actual = Assertions.assertThrows(RuntimeException.class, () -> { 50 | this.tv.turnUpVolume(); 51 | }); 52 | int actualVolume = this.tv.getVolume(); 53 | //then 54 | String expected = "It's already at full volume"; 55 | Assertions.assertEquals(actual.getMessage(), expected); 56 | 57 | int exectedVolume = 10; 58 | Assertions.assertEquals(exectedVolume, actualVolume); 59 | } 60 | 61 | @Test 62 | void shouldThrowRuntimeException_WhenTryTurnDownVolumeBelowZero() { 63 | //given 64 | this.tv.setVolume(0); 65 | //when 66 | RuntimeException actual = assertThrows(RuntimeException.class, () -> { 67 | this.tv.turnDownVolume(); 68 | }); 69 | int actualVolume = this.tv.getVolume(); 70 | //then 71 | String expected = "It's already at minimum volume"; 72 | Assertions.assertEquals(actual.getMessage(), expected); 73 | 74 | int exectedVolume = 0; 75 | Assertions.assertEquals(exectedVolume, actualVolume); 76 | } 77 | } -------------------------------------------------------------------------------- /src/test/java/day03/MonkeyTest.java: -------------------------------------------------------------------------------- 1 | package test.java.day03; 2 | 3 | import main.java.day03.Monkey; 4 | import main.java.day03.enums.Fruit; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.BeforeEach; 7 | import org.junit.jupiter.api.Test; 8 | import org.junit.jupiter.params.ParameterizedTest; 9 | import org.junit.jupiter.params.provider.EnumSource; 10 | 11 | import static org.junit.jupiter.api.Assertions.assertThrows; 12 | 13 | class MonkeyTest { 14 | private Monkey monkey; 15 | 16 | @BeforeEach 17 | void setUp() { 18 | monkey = new Monkey(); 19 | } 20 | 21 | @ParameterizedTest 22 | @EnumSource(Fruit.class) 23 | void shouldAddTheFoodOnStomach_WhenFoodIsStringOrMonkey(Fruit fruit) { 24 | //given 25 | Monkey food = new Monkey(); 26 | //when 27 | this.monkey.toEat(fruit); 28 | this.monkey.toEat(food); 29 | Monkey actualFood2 = (Monkey) this.monkey.getStomach().get(1); 30 | int actualSize = this.monkey.getStomach().size(); 31 | //then 32 | int expectedSize = 2; 33 | Assertions.assertEquals(food, actualFood2); 34 | Assertions.assertEquals(expectedSize, actualSize); 35 | } 36 | 37 | @Test 38 | void shouldThrowIllegalArgumentException_WhenFoodIsNotFruitOrMonkey() { 39 | //given 40 | int food = 10; 41 | //when 42 | IllegalArgumentException actual = assertThrows(IllegalArgumentException.class, () -> { 43 | this.monkey.toEat(food); 44 | }); 45 | //then 46 | String expected = "The Monkey doesn't eat this type of food!"; 47 | Assertions.assertEquals(expected, actual.getMessage()); 48 | } 49 | 50 | @Test 51 | void shouldRemoveTheFoodOnStomach_WhenStomochDoesntEmpty() { 52 | //given 53 | monkey.toEat(Fruit.APPLE); 54 | //when 55 | this.monkey.toDigest(); 56 | boolean actual = this.monkey.getStomach().isEmpty(); 57 | //then 58 | boolean expected = true; 59 | Assertions.assertEquals(expected, actual); 60 | } 61 | 62 | @Test 63 | void shouldThrowRuntimeException_WhenStomochtEmpty() { 64 | //given 65 | //when 66 | RuntimeException actual = assertThrows(RuntimeException.class, () -> { 67 | this.monkey.toDigest(); 68 | }); 69 | //then 70 | String expected = "Stomach already empty!"; 71 | Assertions.assertEquals(expected, actual.getMessage()); 72 | } 73 | } -------------------------------------------------------------------------------- /src/test/java/day03/PersonTest.java: -------------------------------------------------------------------------------- 1 | package test.java.day03; 2 | 3 | import main.java.day03.Person; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | class PersonTest { 11 | private Person person; 12 | @BeforeEach 13 | void setUp() { 14 | person = new Person("Cami"); 15 | } 16 | 17 | @Test 18 | void shouldVerifierIsSameObjectReturnTrue_WhenPersonIsSame() { 19 | //given 20 | Person mother = new Person("Mother"); 21 | 22 | person.setMother(mother); 23 | Person person2 = new Person("Cami"); 24 | person2.setMother(mother); 25 | //when 26 | boolean actual = person.equals(person2); 27 | //then 28 | Boolean expected = true; 29 | Assertions.assertEquals(expected, actual); 30 | } 31 | 32 | @Test 33 | void shouldVerifierIsSameObjectReturnFalse_WhenPersonDoesntSame() { 34 | //given 35 | Person mother = new Person("Mother"); 36 | Person mother2 = new Person("Mother 1"); 37 | 38 | person.setMother(mother); 39 | Person person2 = new Person("Cami"); 40 | person2.setMother(mother2); 41 | //when 42 | boolean actual = person.equals(person2); 43 | //then 44 | Boolean expected = false; 45 | Assertions.assertEquals(expected, actual); 46 | } 47 | 48 | @Test 49 | void shouldReturnTrue_WhenMotherIsSame() { 50 | //given 51 | Person mother = new Person("Mother"); 52 | 53 | person.setMother(mother); 54 | Person person2 = new Person("Cami 2"); 55 | person2.setMother(mother); 56 | //when 57 | boolean actual = person.isSiblings(person2); 58 | //then 59 | Boolean expected = true; 60 | Assertions.assertEquals(expected, actual); 61 | } 62 | 63 | @Test 64 | void shouldReturnTrue_WhenFatherDoesntSame() { 65 | //given 66 | Person mother = new Person("Mother"); 67 | Person mother2 = new Person("Mother 1"); 68 | 69 | Person father = new Person("Father"); 70 | Person father2 = new Person("Father 2"); 71 | 72 | person.setMother(mother); 73 | person.setFather(father); 74 | Person person2 = new Person("Cami 2"); 75 | person2.setMother(mother2); 76 | person2.setFather(father2); 77 | //when 78 | boolean actual = person.isSiblings(person2); 79 | //then 80 | Boolean expected = false; 81 | Assertions.assertEquals(expected, actual); 82 | } 83 | } -------------------------------------------------------------------------------- /src/test/java/day04/BankAccountTest.java: -------------------------------------------------------------------------------- 1 | package test.java.day04; 2 | 3 | import main.java.day04.SavingsAccount2; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.params.ParameterizedTest; 8 | import org.junit.jupiter.params.provider.CsvSource; 9 | import org.junit.jupiter.params.provider.MethodSource; 10 | 11 | import java.math.BigDecimal; 12 | import java.math.RoundingMode; 13 | import java.util.stream.Stream; 14 | 15 | import static org.junit.jupiter.api.Assertions.*; 16 | 17 | class BankAccountTest { 18 | private SavingsAccount2 bankAccount; 19 | 20 | @BeforeEach 21 | void setUp() { 22 | bankAccount = new SavingsAccount2("123456", "Cami"); 23 | } 24 | 25 | @ParameterizedTest 26 | @MethodSource("bigDecimalProviderToWithdraw") 27 | void shouldThrowIllegalArgumentException_WhenValuesIsZero(BigDecimal valuetoWithdraw) { 28 | //given 29 | //when 30 | IllegalArgumentException actual = assertThrows(IllegalArgumentException.class, () -> { 31 | bankAccount.toWithdraw(valuetoWithdraw); 32 | }); 33 | //then 34 | String expected = "Invalid value to withdraw"; 35 | Assertions.assertEquals(expected, actual.getMessage()); 36 | } 37 | 38 | @ParameterizedTest 39 | @CsvSource({ 40 | "300, 0", 41 | "100, 200" 42 | }) 43 | void shouldWithdrawValue_WhenValueIsSameAsBalance(String valueToWithdraw, String result) { 44 | //given 45 | //when 46 | bankAccount.toWithdraw(new BigDecimal(valueToWithdraw)); 47 | BigDecimal actual = bankAccount.getBalance(); 48 | actual = actual.setScale(2, RoundingMode.HALF_EVEN); 49 | //then 50 | BigDecimal expected = new BigDecimal(result); 51 | expected = expected.setScale(2, RoundingMode.HALF_EVEN); 52 | Assertions.assertEquals(expected, actual); 53 | } 54 | 55 | @ParameterizedTest 56 | @MethodSource("bigDecimalProviderToDeposit") 57 | void shouldThrowIllegalArgumentException_WhenTryToDepositValuesIsLessThan0(BigDecimal valuetoWithdraw) { 58 | //given 59 | //when 60 | IllegalArgumentException actual = assertThrows(IllegalArgumentException.class, () -> { 61 | bankAccount.toDeposit(valuetoWithdraw); 62 | }); 63 | //then 64 | String expected = "Invalid value to deposit"; 65 | Assertions.assertEquals(expected, actual.getMessage()); 66 | } 67 | 68 | @Test 69 | void shouldDepositValue() { 70 | //given 71 | BigDecimal valueToDeposit = BigDecimal.TEN; 72 | //when 73 | bankAccount.toDeposit(valueToDeposit); 74 | BigDecimal actual = bankAccount.getBalance(); 75 | //then 76 | BigDecimal expected = BigDecimal.TEN; 77 | Assertions.assertEquals(expected, actual); 78 | } 79 | 80 | static Stream bigDecimalProviderToWithdraw() { 81 | return Stream.of(BigDecimal.ZERO, BigDecimal.valueOf(-100), BigDecimal.valueOf(350)); 82 | } 83 | 84 | static Stream bigDecimalProviderToDeposit() { 85 | return Stream.of(BigDecimal.ZERO, BigDecimal.valueOf(-100)); 86 | } 87 | } -------------------------------------------------------------------------------- /src/test/java/day03/GasStationTest.java: -------------------------------------------------------------------------------- 1 | package test.java.day03; 2 | 3 | import main.java.day03.GasStation; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import java.math.BigDecimal; 9 | import java.math.RoundingMode; 10 | 11 | import static org.junit.jupiter.api.Assertions.*; 12 | 13 | class GasStationTest { 14 | //attributes 15 | private GasStation gasStation; 16 | 17 | @BeforeEach 18 | void setUp() { 19 | gasStation = new GasStation(); 20 | } 21 | 22 | @Test 23 | void shouldFuelVehicleReturnQuantityLiter_WhenSupplyByValue() { 24 | //given 25 | BigDecimal priceFuel = BigDecimal.valueOf(2d); 26 | BigDecimal valueSupply = BigDecimal.valueOf(100d); 27 | gasStation.setPriceFuel(priceFuel); 28 | //when 29 | double actual = gasStation.supply(valueSupply); 30 | //then 31 | double expectedQuantityLiterSupply = 50d; 32 | Assertions.assertEquals(actual, expectedQuantityLiterSupply); 33 | 34 | double actualLiterGasStation = gasStation.getQuantityFuel(); 35 | double expectedLiterGasStation = 50d; 36 | Assertions.assertEquals(actualLiterGasStation, expectedLiterGasStation); 37 | } 38 | 39 | @Test 40 | void shouldThrowIllegalArgumentException_WhenTryFuelVehicleByValueAndInsufficientFuelOnGasStation() { 41 | //given 42 | BigDecimal priceFuel = BigDecimal.valueOf(2d); 43 | BigDecimal valueSupply = BigDecimal.valueOf(500); 44 | gasStation.setPriceFuel(priceFuel); 45 | //when 46 | IllegalArgumentException actual = assertThrows(IllegalArgumentException.class, () -> { 47 | gasStation.supply(valueSupply); 48 | }); 49 | //then 50 | String expected = String.format("Impossible to supply this quantity %s of fuel!", valueSupply); 51 | Assertions.assertEquals(actual.getMessage(), expected); 52 | 53 | double actualLiterGasStation = gasStation.getQuantityFuel(); 54 | double expectedLiterGasStation = 100d; 55 | Assertions.assertEquals(actualLiterGasStation, expectedLiterGasStation); 56 | } 57 | 58 | @Test 59 | void shouldFuelVehicleReturnQuantityLiter_WhenSupplyByLiter() { 60 | //given 61 | BigDecimal priceFuel = BigDecimal.valueOf(4d); 62 | double quantityLiter = 50d; 63 | gasStation.setPriceFuel(priceFuel); 64 | //when 65 | BigDecimal actual = gasStation.supply(quantityLiter); 66 | actual = actual.setScale(2, RoundingMode.HALF_EVEN); 67 | //then 68 | BigDecimal expectedValueLitersSupply = BigDecimal.valueOf(200); 69 | expectedValueLitersSupply = expectedValueLitersSupply.setScale(2, RoundingMode.HALF_EVEN); 70 | Assertions.assertEquals(actual, expectedValueLitersSupply); 71 | 72 | double actualLiterGasStation = gasStation.getQuantityFuel(); 73 | double expectedLiterGasStation = 50d; 74 | Assertions.assertEquals(actualLiterGasStation, expectedLiterGasStation); 75 | } 76 | 77 | @Test 78 | void shouldThrowIllegalArgumentException_WhenTryFuelVehicleByLitersAndInsufficientFuelOnGasStation() { 79 | //given 80 | BigDecimal priceFuel = BigDecimal.valueOf(4d); 81 | double quantityLiter = 150d; 82 | gasStation.setPriceFuel(priceFuel); 83 | //when 84 | IllegalArgumentException actual = assertThrows(IllegalArgumentException.class, () -> { 85 | gasStation.supply(quantityLiter); 86 | }); 87 | //then 88 | String expected = String.format("Impossible to supply this quantity %s of fuel!", quantityLiter); 89 | Assertions.assertEquals(actual.getMessage(), expected); 90 | 91 | double actualLiterGasStation = gasStation.getQuantityFuel(); 92 | double expectedLiterGasStation = 100d; 93 | Assertions.assertEquals(actualLiterGasStation, expectedLiterGasStation); 94 | } 95 | } -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | --------------------------------------------------------------------------------