Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
student-tournament-hub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Schneider Stefan
student-tournament-hub
Commits
5f7c28dd
Commit
5f7c28dd
authored
1 year ago
by
Schneider Stefan
Browse files
Options
Downloads
Patches
Plain Diff
14.01.2024 - trying the test for assignTeamToMatch
#27
parent
f96d536f
No related branches found
No related tags found
1 merge request
!7
Dev in Main Merge
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sth-backend/src/test/java/hdm/mi/sthbackend/t1.java
+88
-0
88 additions, 0 deletions
sth-backend/src/test/java/hdm/mi/sthbackend/t1.java
with
88 additions
and
0 deletions
sth-backend/src/test/java/hdm/mi/sthbackend/t1.java
0 → 100644
+
88
−
0
View file @
5f7c28dd
package
hdm.mi.sthbackend
;
import
hdm.mi.sthbackend.controller.TournamentController
;
import
hdm.mi.sthbackend.dto.MatchDTO
;
import
hdm.mi.sthbackend.exeptions.MatchIdNotFoundException
;
import
hdm.mi.sthbackend.mapper.ModelToDTOMapper
;
import
hdm.mi.sthbackend.model.Match
;
import
hdm.mi.sthbackend.repository.IMatchRepository
;
import
hdm.mi.sthbackend.repository.IPlayerRepository
;
import
hdm.mi.sthbackend.repository.ITeamRepository
;
import
hdm.mi.sthbackend.repository.ITournamentRepository
;
import
hdm.mi.sthbackend.service.TournamentService
;
import
hdm.mi.sthbackend.types.TeamMatchScore
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.ResultActions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.util.HashMap
;
import
java.util.Optional
;
import
java.util.UUID
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
Mockito
.*;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
patch
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultHandlers
.
print
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
jsonPath
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
@AutoConfigureMockMvc
@RunWith
(
MockitoJUnitRunner
.
class
)
@SpringBootTest
public
class
t1
{
@Mock
private
IMatchRepository
matchRepository
;
@Mock
private
ITeamRepository
teamRepository
;
@Mock
private
IPlayerRepository
playerRepository
;
@Mock
private
ITournamentRepository
tournamentRepository
;
@Mock
private
ModelToDTOMapper
mapper
;
@InjectMocks
private
TournamentController
tournamentController
;
@Autowired
private
MockMvc
mockMvc
;
@Test
public
void
assignTeamToMatch
()
throws
Exception
{
UUID
matchId
=
UUID
.
randomUUID
();
MatchDTO
testMatch
=
new
MatchDTO
();
testMatch
.
setTeamScores
(
new
HashMap
<>());
testMatch
.
setComment
(
"Sample comment"
);
// Erstelle ein gültiges Match-Objekt für die Mock-Antwort
Match
mockMatch
=
new
Match
(
matchId
,
new
HashMap
<>(),
UUID
.
randomUUID
(),
"Some comment"
,
UUID
.
randomUUID
());
when
(
matchRepository
.
findById
(
matchId
)).
thenReturn
(
Optional
.
of
(
mockMatch
));
when
(
mapper
.
mapToMatchDTO
(
any
())).
thenReturn
(
testMatch
);
verify
(
matchRepository
,
times
(
1
)).
findById
(
matchId
);
verify
(
matchRepository
,
times
(
1
)).
save
(
any
());
verify
(
mapper
,
times
(
1
)).
mapToMatchDTO
(
any
());
}
}
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