Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Michal Čížek
flea-market-manager
Commits
897d9e0c
Commit
897d9e0c
authored
May 18, 2022
by
Norbert Komiňák
Browse files
Removed findLocationsInPriceRange() functionality from MarketLocation
parent
722a7c2b
Changes
4
Hide whitespace changes
Inline
Side-by-side
backend/flea-market-manager-persistence/src/main/java/cz/fi/muni/pa165/flea/market/manager/dao/MarketLocationDao.java
View file @
897d9e0c
...
...
@@ -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
);
}
}
backend/flea-market-manager-persistence/src/test/java/cz/fi/muni/pa165/flea/market/manager/MarketLocationDaoTest.java
View file @
897d9e0c
...
...
@@ -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
);
...
...
backend/flea-market-manager-service/src/main/java/cz/fi/muni/pa165/flea/market/manager/service/MarketLocationService.java
View file @
897d9e0c
...
...
@@ -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
);
}
}
}
backend/flea-market-manager-service/src/test/java/cz/fi/muni/pa165/flea/market/manager/MarketLocationServiceTest.java
View file @
897d9e0c
...
...
@@ -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
(){
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment