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
84f7c90e
Commit
84f7c90e
authored
May 18, 2022
by
Norbert Komiňák
Browse files
Removed findCheaperLocations() functionality from MarketLocation
parent
897d9e0c
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 @
84f7c90e
...
@@ -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
);
}
}
}
backend/flea-market-manager-persistence/src/test/java/cz/fi/muni/pa165/flea/market/manager/MarketLocationDaoTest.java
View file @
84f7c90e
...
@@ -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
);
...
...
backend/flea-market-manager-service/src/main/java/cz/fi/muni/pa165/flea/market/manager/service/MarketLocationService.java
View file @
84f7c90e
...
@@ -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
());
...
...
backend/flea-market-manager-service/src/test/java/cz/fi/muni/pa165/flea/market/manager/MarketLocationServiceTest.java
View file @
84f7c90e
...
@@ -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
);
...
...
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