Skip to content

Commit

Permalink
Fixed unit test for some entities, services and controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
CihatAltiparmak committed Jan 2, 2024
1 parent 2683d13 commit daef454
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.Month;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
Expand Down Expand Up @@ -61,6 +64,9 @@ public void setUp() {
public void onEachTestStart() {
testCreateOrUpdateScheduleDTO = new CreateOrUpdateScheduleDTO();
testCreateOrUpdateMedicationDTO = new CreateOrUpdateMedicationDTO("elma", 1, testCreateOrUpdateScheduleDTO, 1);
testCreateOrUpdateMedicationDTO.getScheduleID().setBeginningDate(LocalDate.of(2034, Month.JANUARY, 1));
testCreateOrUpdateMedicationDTO.getScheduleID().setDoseCount(54);
testCreateOrUpdateMedicationDTO.getScheduleID().setDoseFrequency(100);
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.sql.Date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.List;

@SpringBootTest
Expand All @@ -30,13 +31,13 @@ void createEntity() {

Appointment test_appointment = new Appointment();
test_appointment.setAppointmentID(1773);
test_appointment.setAppointmentDate(LocalDateTime.now());
test_appointment.setAppointmentDate(LocalDateTime.of(2034, Month.JANUARY, 4, 9, 5));
test_appointment.setPetID(test_pet);
test_appointment.setVetID(test_veterinarian);
test_appointment.setPetOwnerID(test_pet_owner);

assertThat(test_appointment.getAppointmentID()).isEqualTo(1773);
assertThat(test_appointment.getAppointmentDate()).isEqualTo(LocalDate.now());
assertThat(test_appointment.getAppointmentDate()).isEqualTo(LocalDateTime.of(2034, Month.JANUARY, 4, 9, 5));
assertThat(test_appointment.getPetID().getAppointments().size()).isEqualTo(4);
assertThat(test_appointment.getVetID().getAppointments().size()).isEqualTo(2);
assertThat(test_appointment.getPetOwnerID().getAppointments().size()).isEqualTo(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;

Expand All @@ -17,13 +18,13 @@ void createEntity() {
Schedule test_schedule = new Schedule();
test_schedule.setDoseCount(15);
test_schedule.setScheduleID(1915);
// test_schedule.setBeginningDate(new Date(3451));
test_schedule.setBeginningDate(LocalDate.ofEpochDay(3451));
test_schedule.setMedications(List.of(new Medication()));
test_schedule.setDoseFrequency(20);

assertThat(test_schedule.getDoseCount()).isEqualTo(15);
assertThat(test_schedule.getScheduleID()).isEqualTo(1915);
assertThat(test_schedule.getBeginningDate()).isEqualTo(new Date(3451));
assertThat(test_schedule.getBeginningDate()).isEqualTo(LocalDate.ofEpochDay(3451));
assertThat(test_schedule.getDoseFrequency()).isEqualTo(20);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -136,6 +137,7 @@ public void testServiceUpdatePetOwner() {
public void testServiceUpdateAssignedVeterinarian() {
testPetOwner.setVet(new Veterinarian());
testPetOwner.getVet().setClinic("sun of the run");
testPetOwner.setAppointments(List.of());
PetOwner returnedPetOwner = testPetOwnerRepository.save(testPetOwner);

Veterinarian otherVeterinarian = new Veterinarian();
Expand Down

0 comments on commit daef454

Please sign in to comment.