Commit 897d9e0c authored by Norbert Komiňák's avatar Norbert Komiňák
Browse files

Removed findLocationsInPriceRange() functionality from MarketLocation

parent 722a7c2b
......@@ -36,12 +36,4 @@ public class MarketLocationDao extends DomainDaoImpl<MarketLocation, QMarketLoca
.where(qEntity.priceInCents.lt(priceInCents))
.list(qEntity);
}
public List<MarketLocation> findLocationsInPriceRange(Long from, Long to) {
JPAQuery query = new JPAQuery(entityManager);
return query
.from(qEntity)
.where(qEntity.priceInCents.between(from, to))
.list(qEntity);
}
}
......@@ -187,24 +187,6 @@ public class MarketLocationDaoTest {
assertThrows(NullPointerException.class, () -> marketLocationDao.findCheaperLocations(null));
}
@Test
@Transactional
public void findLocationsInPriceRange(){
MarketLocation location2 = new MarketLocation();
location2.setName(faker.rickAndMorty().location());
location2.setPriceInCents(40000L);
location2.setAddress(faker.address().fullAddress());
entityManager.persist(location2);
List<MarketLocation> locationsInPriceRange = marketLocationDao.findLocationsInPriceRange(20000L, 50000L);
Assertions.assertEquals(locationsInPriceRange.size(), 1);
SoftAssertions.assertSoftly(softAssertions -> softAssertions.assertThat(locationsInPriceRange.get(0)).isEqualTo(location2).usingRecursiveComparison());
Assertions.assertFalse(locationsInPriceRange.contains(marketLocation));
}
private void initializeData() {
LocalDate startDate = LocalDate.parse("2022-03-03", dateFormatter);
......
......@@ -87,21 +87,4 @@ public class MarketLocationService extends DomainServiceImpl<MarketLocation> {
return location;
}
public List<MarketLocation> findLocationsInPriceRange(@NonNull Long from, @NonNull Long to) {
if (from < 0 || to < 0) {
throw new IllegalArgumentException("Invalid range.");
}
if (from > to) {
throw new IllegalArgumentException("Range cannot contain negative value.");
}
try {
return locationDao.findLocationsInPriceRange(from, to);
} catch (Exception e){
throw new DaoException(e.getMessage(), e);
}
}
}
......@@ -147,43 +147,6 @@ public class MarketLocationServiceTest {
Assertions.assertThatThrownBy(() -> locationService.findByAddress(null)).isInstanceOf(NullPointerException.class);
}
@Test
@Transactional
public void findLocationsInPriceRange() {
Long from = 100000L;
Long to = 400000L;
MarketLocation inRange = createLocationWithPrice(100001L);
MarketLocation notInRange = createLocationWithPrice(400001L);
when(locationDao.create(inRange)).thenReturn(inRange);
when(locationDao.create(notInRange)).thenReturn(notInRange);
when(locationDao.findLocationsInPriceRange(from, to)).thenReturn(List.of(inRange));
locationService.create(inRange);
locationService.create(notInRange);
List<MarketLocation> locationsInRange = locationService.findLocationsInPriceRange(from, to);
assertEquals(locationsInRange.size(), 1);
SoftAssertions.assertSoftly(softAssertions -> softAssertions.assertThat(locationsInRange.get(0)).isEqualTo(inRange).usingRecursiveComparison());
assertFalse(locationsInRange.contains(notInRange));
}
@Test
@Transactional
public void findByInvalidPriceRange(){
Assertions.assertThatThrownBy(() -> locationService.findLocationsInPriceRange(9000L, 6000L)).isInstanceOf(IllegalArgumentException.class);
}
@Test
@Transactional
public void findByInvalidPriceRangeNegative(){
Assertions.assertThatThrownBy(() -> locationService.findLocationsInPriceRange(-3L, 60000L)).isInstanceOf(IllegalArgumentException.class);
}
@Test
@Transactional
public void findCheaperLocations(){
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment