I have a Oracle DB with type of DATE my Entiy class have LocalDate parameter as shown in here
@Entity
@Table(name = "CONTRACT")
public class ContractEntity {
private Long id;
private LocalDate contractStartDate;
private LocalDate contractEndDate;
...
For the testing I created derived query to find Entity by contractStartDate
public interface ContractRepository extends JpaRepository<ContractEntity, Long>, JpaSpecificationExecutor<ContractEntity> {
ContractEntity getContractEntityByContractStartDateIs(LocalDate date)
}
Then I created Two Tests as follows;
@DisplayName("Should get Exact Date Entity")
@Test
void test1(){
LocalDate date=LocalDate.of(2021,03,9);
ContractEntity entity= searchService.getByDate(date); // getByDate is mapped to getContractEntityByContractStartDateIs() in service layer
assertEquals(date,entity.getContractStartDate());
}
@DisplayName("Should match ID:1 Entity's Date with Local Date")
@Test
void test2(){
ContractEntity entity=searchService.getById(1l).get();
assertEquals(1l,entity.getId());
LocalDate date=LocalDate.of(2021,03,9);
assertEquals(date,entity.getContractStartDate());
}
}
My problem is test1 fails with null error which means equality condition fails to give existence of that Entity even though test2 passed which date is equal to id:1 entity's Start-date
p.s: I have set Contract Table's ID:1 Contract Start Date value to 2021,03,9 as shown in image here

So what would be the reason for this Why test1 fails to get equal entity and why test2 pass that assert equity of date is true