Skip to content

Commit

Permalink
test: ajustando teste service e controller de empresas
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo LB. Barreto committed Apr 25, 2024
1 parent e578d00 commit 0a7c787
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ void setUp() {

when(companyService.createNewCompany(any(CompanyPostRequestBody.class))).thenReturn(company);
when(companyService.updateCompany(anyString(), any(CompanyPutRequestBody.class))).thenReturn(company);
when(companyService.findCompanyByIdJ(anyString())).thenReturn(company);
when(companyService.findCompanyById(anyString())).thenReturn(company);
when(companyService.findCompanyByCNPJ(anyString())).thenReturn(company);
//doNothing().when(companyService).deleteExistingCompany(anyString());

MockitoAnnotations.openMocks(this);
}
Expand Down Expand Up @@ -81,21 +80,10 @@ void testPostNewCompany() {
@DisplayName("Should be able to put and update a company")
void testPutUpdateCompany() {
var companyPutRequestBody = new CompanyPutRequestBody("Company test",
"company@test.com",
"12345");
"company@test.com");
var companyResponse = companyController.putUpdateCompany("12.123.123/0001-12", companyPutRequestBody);

assertNotNull(companyResponse.getBody());
assertEquals(HttpStatus.OK, companyResponse.getStatusCode());
}

@Test
@DisplayName("Should be able to delete a company")
void testDeleteCompany() {
// var companyResponse = companyController.deleteCompany("12.123.123/0001-12");
//
// assertDoesNotThrow(() -> companyController.deleteCompany("12.123.123/0001-12"));
// assertEquals(HttpStatus.NO_CONTENT, companyResponse.getStatusCode());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.barreto.stockmanagement.infra.DTOs.company.CompanyPutRequestBody;
import com.barreto.stockmanagement.infra.database.repository.CompanyRepository;
import com.barreto.stockmanagement.infra.exceptions.BadRequestException;
import com.barreto.stockmanagement.useCases.user.UserUseCase;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -24,6 +25,9 @@ public class CompanyServiceTest {
@Mock
private CompanyRepository repository;

@Mock
private UserUseCase userService;

@InjectMocks
private CompanyService companyService;

Expand Down Expand Up @@ -98,8 +102,7 @@ void testDoesNotCreateCompanyWithUsedEmail() {
void testUpdateCompanyData() {
var companyPutRequestBody = new CompanyPutRequestBody(
"Company test 2",
"company@test.com",
"12345"
"company@test.com"
);

var company = companyService.updateCompany("12.123.123/0001-12", companyPutRequestBody);
Expand All @@ -115,8 +118,7 @@ void testUpdateNotExistingCompanyData() {

var companyPutRequestBody = new CompanyPutRequestBody(
"Company test 2",
"company@test.com",
"12345"
"company@test.com"
);

assertThrows(
Expand All @@ -125,8 +127,20 @@ void testUpdateNotExistingCompanyData() {
}

@Test
@DisplayName("Should be able to delete a company")
void testDeleteCompany() {
assertDoesNotThrow(() -> companyService.deleteExistingCompany("12.123.123/0001-12"));
@DisplayName("Should be able to find a company by your Id")
void testFindCompanyById() {
var company = companyService.findCompanyById("companyId");

assertNotNull(company);
assertEquals("companyId", company.getId());
}

@Test
@DisplayName("Should be able to find a company by your CNPJ")
void testFindCompanyByCNPJ() {
var company = companyService.findCompanyByCNPJ("12.123.123/0001-12");

assertNotNull(company);
assertEquals("12.123.123/0001-12", company.getCnpj());
}
}

0 comments on commit 0a7c787

Please sign in to comment.