Commit 84f7c90e authored by Norbert Komiňák's avatar Norbert Komiňák
Browse files

Removed findCheaperLocations() functionality from MarketLocation

parent 897d9e0c
...@@ -28,12 +28,4 @@ public class MarketLocationDao extends DomainDaoImpl<MarketLocation, QMarketLoca ...@@ -28,12 +28,4 @@ public class MarketLocationDao extends DomainDaoImpl<MarketLocation, QMarketLoca
.where(qEntity.address.eq(address)) .where(qEntity.address.eq(address))
.singleResult(qEntity); .singleResult(qEntity);
} }
public List<MarketLocation> findCheaperLocations(@NonNull Long priceInCents) {
JPAQuery query = new JPAQuery(entityManager);
return query
.from(qEntity)
.where(qEntity.priceInCents.lt(priceInCents))
.list(qEntity);
}
} }
...@@ -162,31 +162,6 @@ public class MarketLocationDaoTest { ...@@ -162,31 +162,6 @@ public class MarketLocationDaoTest {
assertThrows(NullPointerException.class, () -> marketLocationDao.findByAddress(null)); assertThrows(NullPointerException.class, () -> marketLocationDao.findByAddress(null));
} }
@Test
@Transactional
public void findCheaperLocations(){
MarketLocation moreExpensiveMarketLocation = new MarketLocation();
moreExpensiveMarketLocation.setName(faker.rickAndMorty().location());
moreExpensiveMarketLocation.setPriceInCents(30000L);
moreExpensiveMarketLocation.setAddress(faker.address().fullAddress());
entityManager.persist(moreExpensiveMarketLocation);
List<MarketLocation> cheaperLocations = marketLocationDao.findCheaperLocations(20000L);
Assertions.assertEquals(cheaperLocations.size(), 1);
SoftAssertions.assertSoftly(softAssertions -> softAssertions.assertThat(cheaperLocations.get(0)).isEqualTo(marketLocation).usingRecursiveComparison());
Assertions.assertFalse(cheaperLocations.contains(moreExpensiveMarketLocation));
}
@Test
@Transactional
public void findCheaperLocationsByNullPrice(){
assertThrows(NullPointerException.class, () -> marketLocationDao.findCheaperLocations(null));
}
private void initializeData() { private void initializeData() {
LocalDate startDate = LocalDate.parse("2022-03-03", dateFormatter); LocalDate startDate = LocalDate.parse("2022-03-03", dateFormatter);
......
...@@ -55,19 +55,6 @@ public class MarketLocationService extends DomainServiceImpl<MarketLocation> { ...@@ -55,19 +55,6 @@ public class MarketLocationService extends DomainServiceImpl<MarketLocation> {
} }
} }
public List<MarketLocation> findCheaperLocations(Long priceInCents) {
if (priceInCents < 0) {
throw new IllegalArgumentException("Price cannot be negative.");
}
try {
return locationDao.findCheaperLocations(priceInCents);
} catch (Exception e){
throw new DaoException(e.getMessage(), e);
}
}
public MarketLocation constructLocationFromDTO(@NonNull MarketLocationCreateDTO dto){ public MarketLocation constructLocationFromDTO(@NonNull MarketLocationCreateDTO dto){
MarketLocation location = new MarketLocation(); MarketLocation location = new MarketLocation();
location.setAddress(dto.getAddress()); location.setAddress(dto.getAddress());
......
...@@ -147,31 +147,6 @@ public class MarketLocationServiceTest { ...@@ -147,31 +147,6 @@ public class MarketLocationServiceTest {
Assertions.assertThatThrownBy(() -> locationService.findByAddress(null)).isInstanceOf(NullPointerException.class); Assertions.assertThatThrownBy(() -> locationService.findByAddress(null)).isInstanceOf(NullPointerException.class);
} }
@Test
@Transactional
public void findCheaperLocations(){
MarketLocation location1 = createLocationWithPrice(30000L);
MarketLocation location2 = createLocationWithPrice(50000L);
when(locationDao.findCheaperLocations(any())).thenReturn(List.of(location1));
locationService.create(location1);
locationService.create(location2);
List<MarketLocation> cheaperLocations = locationService.findCheaperLocations(40000L);
assertEquals(cheaperLocations.size(), 1);
SoftAssertions.assertSoftly(softAssertions -> softAssertions.assertThat(cheaperLocations.get(0)).isEqualTo(location1).usingRecursiveComparison());
assertFalse(cheaperLocations.contains(location2));
}
@Test
@Transactional
public void findCheaperLocationsNegativePrice(){
Assertions.assertThatThrownBy(() -> locationService.findCheaperLocations(-30000L)).isInstanceOf(IllegalArgumentException.class);
}
private MarketLocation createLocationWithPrice(Long price) { private MarketLocation createLocationWithPrice(Long price) {
MarketLocation location = new MarketLocation(); MarketLocation location = new MarketLocation();
location.setPriceInCents(price); location.setPriceInCents(price);
......
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