{"id":21274198,"url":"https://github.com/eduardob-programador/junit-learning","last_synced_at":"2025-08-31T22:10:47.560Z","repository":{"id":263197900,"uuid":"889617389","full_name":"EduardoB-Programador/JUnit-Learning","owner":"EduardoB-Programador","description":"simple project using JUnit5 test cases to tests certains modules","archived":false,"fork":false,"pushed_at":"2024-11-16T21:51:20.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-22T03:13:09.683Z","etag":null,"topics":["core-java","java","junit5","oop"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EduardoB-Programador.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-16T19:28:36.000Z","updated_at":"2024-11-16T21:51:23.000Z","dependencies_parsed_at":"2024-11-16T22:38:46.081Z","dependency_job_id":null,"html_url":"https://github.com/EduardoB-Programador/JUnit-Learning","commit_stats":null,"previous_names":["eduardob-programador/junit-learning"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EduardoB-Programador%2FJUnit-Learning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EduardoB-Programador%2FJUnit-Learning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EduardoB-Programador%2FJUnit-Learning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EduardoB-Programador%2FJUnit-Learning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EduardoB-Programador","download_url":"https://codeload.github.com/EduardoB-Programador/JUnit-Learning/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243732252,"owners_count":20338831,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["core-java","java","junit5","oop"],"created_at":"2024-11-21T09:19:19.159Z","updated_at":"2025-03-15T12:43:40.800Z","avatar_url":"https://github.com/EduardoB-Programador.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Português\n\nNesse repositório, eu realizo testes utilizando `JUnit5`, por mais que realizar testes tenha sido o foco principal, obviamente é necessário algo pra testar.\n\nEntão eu fiz 2 records, `Category` e `Customer`:\n\n`Customer`: Seria um **cliente** desse sistema, possuindo os seguintes atributos e métodos não padrões:\n```.java\nint id;\nString name;\nString phoneNumber;\nString email;\nCategory category;\n\npublic Customer(int id, String name, String phoneNumber, String email, Category category) //pode lançar IllegalArgumentException(\"id deve ser maior que 0\")\n\n//retorna o atributo discount de Category\npublic int getThisCustomerDiscount()\n\n//retorna o valor inserido com desconto em porcentagem (referente a discount de Category)\npublic double applyDiscountPrice(double price) //pode lançar ArithmeticException(\"preço deve ser maior que 0\") (divisão por 0)\n```\n\n\n`Category`: Seria equivalente a **categoria** de um cliente, possui os seguintes atributos e métodos:\n```.java\nint id;\nString categoryName;\nint discount;\n\npublic Category(int id, String categoryName, int discount) //pode lançar IllegalArgumentException(\"discount deve ser maior que -1 e menor que 101\")\n```\n\nAlém das classes dentro do `/model` temos a classe dentro de `/repository`, `ObjectInstances`. Essa classe é responsável apenas por providenciar objetos dos tipos `Customer` e `Category` para as classes de teste, e já que ela possui seus próprios métodos, eles precisaram também de testes, mas antes, abaixo está a classe com seus atributos e métodos:\n\n```.java\nprivate static int CUSTOMERS_ID; //usado para colocar o id nos clientes mais facilmente\nprivate static int CATEGORIES_ID; //usado para colocar o id nas categorias mais facilmente\n\nprivate final static List\u003cCategory\u003e CATEGORIES; //lista de categorias\nprivate final static List\u003cCustomer\u003e CUSTOMERS; //lista de clientes\nprivate final static Random GENERATOR = new Random(); //gerador de números aleatórios para pegar uma categoria ou um cliente aleatório\n\nstatic {} //setup das listas\n\npublic static Customer fetchRandomCustomer() //pega um cliente aleatório na lista\npublic static Category fetchRandomCategory() //pega uma categoria aleatória na lista\npublic static int getRandomNumber(List\u003c?\u003e l) //é usado nos métodos anteriores para gerar o número aleatório\n```\n\nJá as classes de teste, o foco desse repositório possuem:\n\n```.java\n@TestInstance(TestInstance.Lifecycle.PER_CLASS)\npublic class CustomerTest {\n\n   Customer customer;\n   static Category CATEGORY;\n\n   @BeforeAll\n   static void getRandomCategory() //cria uma categoria antes de todos os testes através do fetchRandomCategory() de ObjectInstances e insere na variável de classe estática CATEGORY\n\n   @AfterEach\n   void closeCustomerInstance() //define this.customer como nulo\n\n   @Test\n   void instaceSuccessTest() //testa a instância de um Customer com os dados passados corretamente tentando não mandar nenhuma exception\n\n   @Test\n   void instanceFailTest() //testa a instância de um Customer tentando lançar a IllegalArgumentException dentro do contrutor\n\n   @Test\n   void applyDiscountPriceSuccessTest() //testa o método que aplica desconto em customer\n\n   @Test\n   void applyDiscountPriceFailTest() //testa o método que aplica desconto em customer, com o objetivo que lançar a ArithmeticException\n\n   static Customer instanceOfCustomer() //instancia um customer para os métodos que não testam a instãncia de um\n}\n```\n\n```.java\npublic class CategoryTest {\n\n    Category category;\n    static int id = 0; //usado para colocar o id nas categorias (não é necessariamente mais eficiente)\n\n    @Test\n    void instaceSuccessTest() //testa a instância de uma Category com os dados passados corretamente tentando não mandar nenhuma exception\n\n    @Test\n    void instanceFailTest() //testa a instância de um Category tentando lançar a IllegalArgumentException dentro do contrutor\n\n}\n```\n\n```.java\n@TestInstance(TestInstance.Lifecycle.PER_CLASS)\npublic class ObjectInstancesTest {\n\n    Customer randomCus; //gera um customer aleatório\n    Category randomCat; //gera uma category aleatoria\n\n    @BeforeAll\n    void beforeTests() //cria os randomCus e randomCat\n\n    @AfterAll\n    void afterTests() //torna os randomCus e randomCat nulo\n\n    @Test\n    public void fetchRandomCustomerTest() //verifica se o valor do customer não é nulo\n\n    @Test\n    public void checkCustomerInfo() //verifica se as informações de customer não são nulas e printa elas\n\n    @Test\n    public void fetchRandomCategoryTest() //verifica se o valor de category não é nulo\n\n    @Test\n    public void checkCategoryInfo() //verifica se as informações de category não são nulas e printa elas\n\n}\n```\n\nAlgumas coisas que foram feitas dentro dos testes tiveram apenas a intenção de praticar, ou achar uma outra forma de realizar a mesma operação e no fim de tudo aprender.\n\n# English\n\nIn this repository, I create test cases using `Junit5`, although tests were the main focus, I obviously need something to test.\n\nSo I created 2 records named `Category` and `Customer`:\n\n`Customer`: Would represent a generic **customer**, having the following fields and non-default methods:\n```.java\nint id;\nString name;\nString phoneNumber;\nString email;\nCategory category;\n\npublic Customer(int id, String name, String phoneNumber, String email, Category category) //may throw IllegalArgumentException(\"id must be greater than 0\")\n\n//returns field discount from category\npublic int getThisCustomerDiscount()\n\n//returns the entered value with a percentage discount (related to the category discount)\npublic double applyDiscountPrice(double price) //may throw ArithmeticException(\"price must be greater than 0\") (division by 0)\n```\n\n\n`Category`: Would represent the customer's **category**, it has the following fields and methods:\n```.java\nint id;\nString categoryName;\nint discount;\n\npublic Category(int id, String categoryName, int discount) //may throw IllegalArgumentException(\"discount must be greater than -1 and lesser than 101\")\n```\n\nBesides the classes inside `/model` there is a class inside `/repository`, called `ObjectInstances`. It is reponsible for providing the objects `Customer` and `Category` for the test classes, and since it also has its own methods, they must be tested as well. Thus, below is the ObjectInstances class with its fields and methods:\n\n```.java\nprivate static int CUSTOMERS_ID; //used for inserting the customers id more easily\nprivate static int CATEGORIES_ID; //used for inserting the categories id more easily\n\nprivate final static List\u003cCategory\u003e CATEGORIES;\nprivate final static List\u003cCustomer\u003e CUSTOMERS;\nprivate final static Random GENERATOR = new Random(); //RNG to get a category or customer randomly\n\nstatic {} //Lists setup\n\npublic static Customer fetchRandomCustomer() //returns a random customer from the list\npublic static Category fetchRandomCategory() //returns a random category from the list\npublic static int getRandomNumber(List\u003c?\u003e l) //used for the previous methods to generate a random number\n```\n\nAnd the test classes, this repo's focus, are as shown below:\n\n```.java\n@TestInstance(TestInstance.Lifecycle.PER_CLASS)\npublic class CustomerTest {\n\n   Customer customer;\n   static Category CATEGORY;\n\n   @BeforeAll\n   static void getRandomCategory() //gets a category from fetchRandomCategory() of ObjectInstances and inserts it in the static field CATEGORY\n\n   @AfterEach\n   void closeCustomerInstance() //makes this.customer null\n\n   @Test\n   void instaceSuccessTest() //tests a Customer's instance passing the right values, not trying to trigger any exception\n\n   @Test\n   void instanceFailTest() //tests a Customer's instance, trying to trigger an exception\n\n   @Test\n   void applyDiscountPriceSuccessTest() //tests the method which applies the discount\n\n   @Test\n   void applyDiscountPriceFailTest() //tests the method which applies the discount, trying to trigger ArithmeticException\n\n   static Customer instanceOfCustomer() //creates a customer for the methods which don't test instance\n}\n```\n\n```.java\npublic class CategoryTest {\n\n    Category category;\n    static int id = 0; //used for inserting the id in the categories\n\n    @Test\n    void instaceSuccessTest() //tests a Category's instance passing the right values, not trying to trigger any exception\n\n    @Test\n    void instanceFailTest() //tests a Customer's instance, trying to trigger an exception\n}\n```\n\n```.java\n@TestInstance(TestInstance.Lifecycle.PER_CLASS)\npublic class ObjectInstancesTest {\n\n    Customer randomCus; //generates a random customer\n    Category randomCat; //generates a random category\n\n    @BeforeAll\n    void beforeTests() //creates the randomCus and randomCat\n\n    @AfterAll\n    void afterTests() //makes randomCus and randomCat null\n\n    @Test\n    public void fetchRandomCustomerTest() //check if the customer's values are not null\n\n    @Test\n    public void checkCustomerInfo() //check if the customer's info are not null, then print them\n\n    @Test\n    public void fetchRandomCategoryTest() //check if the category's values are not null\n\n    @Test\n    public void checkCategoryInfo() //check if the category's info are not null, then print them\n\n}\n```\n\nSome thing that were made inside the tests seems unreasonable, but their objectives were to practice and understand better, or even try to find another way to make the same thing, but at the end, the objective was to learn.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feduardob-programador%2Fjunit-learning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feduardob-programador%2Fjunit-learning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feduardob-programador%2Fjunit-learning/lists"}