Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
dev/codeforces/test Удалил лишние импорты
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderGarifullin committed Dec 17, 2024
1 parent be1df51 commit 80538c5
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import com.cf.cfteam.services.codeforces.GroupService;
import com.cf.cfteam.transfer.payloads.codeforces.GroupPayload;
import com.cf.cfteam.transfer.responses.codeforces.GroupResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ActiveProfiles;

import java.util.List;
Expand All @@ -18,6 +19,7 @@


@ActiveProfiles("test")
@ExtendWith(MockitoExtension.class)
class GroupControllerTest {

@InjectMocks
Expand All @@ -26,19 +28,11 @@ class GroupControllerTest {
@Mock
private GroupService groupService;

private GroupPayload groupPayload;
private GroupResponse groupResponse;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);

// group = Group.builder()
// .name("Test Group")
// .description("Test description")
// .user(null)
// .build();
private static GroupPayload groupPayload;
private static GroupResponse groupResponse;

@BeforeAll
static void setUp() {
groupPayload = GroupPayload.builder()
.name("Test Group")
.description("Test description")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package com.cf.cfteam.controllers.codeforces;

import com.cf.cfteam.services.codeforces.TeamService;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ActiveProfiles;

import static org.junit.jupiter.api.Assertions.*;

@ActiveProfiles("test")
@ExtendWith(MockitoExtension.class)
class TeamControllerTest {

@InjectMocks
private TeamController teamController;

@Mock
private TeamService teamService;




}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import com.cf.cfteam.transfer.responses.security.JwtAuthenticationResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.security.core.Authentication;

Expand All @@ -19,6 +21,7 @@
import static org.mockito.Mockito.when;

@ActiveProfiles("test")
@ExtendWith(MockitoExtension.class)
class UserControllerTest {

@InjectMocks
Expand All @@ -30,11 +33,6 @@ class UserControllerTest {
@Mock
private Authentication authentication;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}

@Test
void testRegister_success() {
RegistrationPayload registrationPayload = getRegistrationPayload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import com.cf.cfteam.utils.codeforces.mappers.GroupMapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ActiveProfiles;

import java.util.List;
Expand All @@ -27,6 +29,7 @@
import static org.mockito.Mockito.*;

@ActiveProfiles("test")
@ExtendWith(MockitoExtension.class)
class GroupServiceTest {

@InjectMocks
Expand All @@ -48,7 +51,6 @@ class GroupServiceTest {

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);

user = User.builder()
.name("User name")
Expand Down Expand Up @@ -164,8 +166,6 @@ void updateGroup_ShouldThrowGroupNotFoundException_WhenGroupDoesNotExist() {

@Test
void deleteGroup_ShouldDeleteGroup_WhenGroupExists() {
when(groupRepository.findById(1L)).thenReturn(Optional.of(group));

groupService.deleteGroup(1L);

verify(groupRepository, times(1)).deleteById(1L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import com.cf.cfteam.transfer.payloads.security.ChangePasswordPayload;
import com.cf.cfteam.transfer.payloads.security.RegistrationPayload;
import com.cf.cfteam.transfer.responses.security.JwtAuthenticationResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.crypto.password.PasswordEncoder;
Expand All @@ -29,6 +29,7 @@
import static org.mockito.Mockito.*;

@ActiveProfiles("test")
@ExtendWith(MockitoExtension.class)
class AuthenticationServiceTest {

@InjectMocks
Expand All @@ -55,11 +56,6 @@ class AuthenticationServiceTest {
@Mock
private UserDetails userDetails;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}

@Test
void register_shouldThrowException_WhenUserAlreadyRegistered() {
String login = "testLogin";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.cf.cfteam.models.entities.security.User;
import com.cf.cfteam.repositories.jpa.security.UserRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.test.context.ActiveProfiles;
Expand All @@ -18,6 +18,7 @@
import static org.mockito.Mockito.when;

@ActiveProfiles("test")
@ExtendWith(MockitoExtension.class)
class MyUserDetailsServiceTest {

@Mock
Expand All @@ -26,11 +27,6 @@ class MyUserDetailsServiceTest {
@InjectMocks
private MyUserDetailsService userDetailsService;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}

@Test
void loadUserByUsername_shouldLoadUserByUsername_WhenUserExists() {
String login = "testLogin";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import com.cf.cfteam.exceptions.security.TokenNotFoundException;
import com.cf.cfteam.models.entities.security.Token;
import com.cf.cfteam.repositories.jpa.security.TokenRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ActiveProfiles;

import java.util.Optional;
Expand All @@ -18,6 +18,7 @@
import static org.mockito.Mockito.*;

@ActiveProfiles("test")
@ExtendWith(MockitoExtension.class)
class TokenServiceTest {

@InjectMocks
Expand All @@ -26,11 +27,6 @@ class TokenServiceTest {
@Mock
private TokenRepository tokenRepository;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}

@Test
void isTokenRevoked_shouldReturnTrue_whenTokenIsRevoked() {
String tokenValue = "valid-token";
Expand Down

0 comments on commit 80538c5

Please sign in to comment.