Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backend
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
idatt2106-v23-03
backend
Commits
8e46010d
Commit
8e46010d
authored
1 year ago
by
Birk Øvstetun Narvhus
Browse files
Options
Downloads
Patches
Plain Diff
added unit test for fridge repo
parent
f4432e21
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/ntnu/idatt2016/v233/SmartMat/repository/group/FridgeRepositoryTest.java
+72
-0
72 additions, 0 deletions
.../v233/SmartMat/repository/group/FridgeRepositoryTest.java
with
72 additions
and
0 deletions
src/test/java/ntnu/idatt2016/v233/SmartMat/repository/group/FridgeRepositoryTest.java
0 → 100644
+
72
−
0
View file @
8e46010d
package
ntnu.idatt2016.v233.SmartMat.repository.group
;
import
ntnu.idatt2016.v233.SmartMat.entity.group.Fridge
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
;
import
org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
@DataJpaTest
class
FridgeRepositoryTest
{
@Autowired
FridgeRepository
fridgeRepository
;
@Autowired
TestEntityManager
entityManager
;
Fridge
fridge
;
@BeforeEach
void
setUp
()
{
fridge
=
new
Fridge
();
fridge
.
setGroupId
(
1L
);
entityManager
.
persist
(
fridge
);
}
@Test
void
shouldFindByGroupId
()
{
assertEquals
(
fridge
,
fridgeRepository
.
findByGroupId
(
fridge
.
getGroupId
()).
get
());
}
@Test
void
shouldNotFindByGroupId
()
{
assertFalse
(
fridgeRepository
.
findByGroupId
(
2L
).
isPresent
());
}
@Test
void
shouldSave
()
{
Fridge
fridge2
=
new
Fridge
();
fridge2
.
setGroupId
(
2L
);
fridgeRepository
.
save
(
fridge2
);
assertEquals
(
fridge2
,
fridgeRepository
.
findByGroupId
(
fridge2
.
getGroupId
()).
get
());
}
@Test
void
shouldFindAll
()
{
assertEquals
(
1
,
fridgeRepository
.
findAll
().
size
());
}
@Test
void
shouldFindById
(){
assertEquals
(
fridge
,
fridgeRepository
.
findById
(
fridge
.
getFridgeId
()).
get
());
}
@Test
void
shouldNotFindById
(){
assertFalse
(
fridgeRepository
.
findById
(
2L
).
isPresent
());
}
@Test
void
shouldDeleteById
(){
fridgeRepository
.
deleteById
(
fridge
.
getFridgeId
());
assertFalse
(
fridgeRepository
.
findById
(
fridge
.
getFridgeId
()).
isPresent
());
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment