Skip to content

Commit

Permalink
Merge 18610c8 into 5838a87
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot[bot] committed Jun 4, 2023
2 parents 5838a87 + 18610c8 commit 3f68310
Show file tree
Hide file tree
Showing 43 changed files with 236 additions and 116 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

plugins {
id 'org.springframework.boot' version '3.0.6'
id 'org.springframework.boot' version '3.1.0'
id "com.install4j.gradle" version "10.0.5"
id "de.undercouch.download" version "5.4.0"
id 'jacoco'
Expand Down Expand Up @@ -321,7 +321,6 @@ dependencies {
implementation("com.github.jasminb:jsonapi-converter:0.12")
implementation("javax.annotation:javax.annotation-api:1.3.2")
implementation("com.github.ben-manes.caffeine:caffeine")
implementation("org.apache.httpcomponents:httpclient")
implementation("io.github.micheljung:fxstage:0.8.3")
implementation("io.github.micheljung:jfx-waitomo-theme:0.3.0")
implementation("org.kitteh.irc:client-lib:8.0.0")
Expand Down
31 changes: 19 additions & 12 deletions src/test/java/com/faforever/client/api/TokenServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import com.google.common.eventbus.EventBus;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
Expand All @@ -21,8 +19,11 @@
import reactor.test.StepVerifier;

import java.net.URI;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -81,11 +82,14 @@ public void testLoginWithCode() throws Exception {
prepareTokenResponse(tokenProperties);

StepVerifier.create(instance.loginWithAuthorizationCode("abc", VERIFIER, REDIRECT_URI)).verifyComplete();
Map<String, String> requestParams = URLEncodedUtils.parse(mockApi.takeRequest()
.getBody()
.readString(StandardCharsets.UTF_8), StandardCharsets.UTF_8)
.stream()
.collect(Collectors.toMap(NameValuePair::getName, NameValuePair::getValue));
String request = URLDecoder.decode(mockApi.takeRequest()
.getBody()
.readString(StandardCharsets.UTF_8), StandardCharsets.UTF_8);

Map<String, String> requestParams = Arrays.stream(request.split("&"))
.map(param -> param.split("="))
.map(keyValue -> Map.entry(keyValue[0], keyValue[1]))
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));

assertEquals("abc", requestParams.get("code"));
assertEquals("authorization_code", requestParams.get("grant_type"));
Expand All @@ -105,11 +109,14 @@ public void testLoginWithRefresh() throws Exception {
prepareTokenResponse(tokenProperties);

StepVerifier.create(instance.loginWithRefreshToken()).verifyComplete();
Map<String, String> requestParams = URLEncodedUtils.parse(mockApi.takeRequest()
.getBody()
.readString(StandardCharsets.UTF_8), StandardCharsets.UTF_8)
.stream()
.collect(Collectors.toMap(NameValuePair::getName, NameValuePair::getValue));
String request = URLDecoder.decode(mockApi.takeRequest()
.getBody()
.readString(StandardCharsets.UTF_8), StandardCharsets.UTF_8);

Map<String, String> requestParams = Arrays.stream(request.split("&"))
.map(param -> param.split("="))
.map(keyValue -> Map.entry(keyValue[0], keyValue[1]))
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));

instance.loginWithAuthorizationCode("abc", VERIFIER, REDIRECT_URI).block();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.mockito.Mock;
import org.mockito.Spy;

import java.io.InputStream;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -191,8 +192,8 @@ public void testCheckChatUserGameListener() {
MapVersionBean mapVersion = MapVersionBeanBuilder.create().defaultValues().get();
defaultUser.setPlayer(player);

when(uiService.getThemeImage(UiService.CHAT_LIST_STATUS_HOSTING)).thenReturn(mock(Image.class));
when(mapService.loadPreview(game.getMapFolderName(), PreviewSize.SMALL)).thenReturn(mock(Image.class));
when(uiService.getThemeImage(UiService.CHAT_LIST_STATUS_HOSTING)).thenReturn(new Image(InputStream.nullInputStream()));
when(mapService.loadPreview(game.getMapFolderName(), PreviewSize.SMALL)).thenReturn(new Image(InputStream.nullInputStream()));
when(mapService.getMapLocallyFromName(mapFolderName)).thenReturn(Optional.of(mapVersion));
when(mapService.convertMapFolderNameToHumanNameIfPossible(mapFolderName)).thenReturn("map name");
when(i18n.get(eq("game.onMapFormat"), anyString())).thenReturn(mapVersion.getMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
import javafx.scene.image.Image;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.testfx.util.WaitForAsyncUtils;

import java.io.InputStream;
import java.net.URL;
import java.time.Instant;
import java.util.Optional;
Expand All @@ -49,7 +49,6 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -96,14 +95,15 @@ public class PrivateChatTabControllerTest extends UITest {
@Spy
private NotificationPrefs notificationPrefs;

@InjectMocks
private PrivateChatTabController instance;

private String playerName;
private PlayerBean player;

@BeforeEach
public void setUp() throws Exception {
instance = new PrivateChatTabController(userService, null, playerService, timeService, i18n, notificationService, uiService, eventBus, audioService, chatService, webViewConfigurer, countryFlagService, emoticonService, avatarService, chatPrefs, notificationPrefs, fxApplicationThreadExecutor);

player = PlayerBeanBuilder.create().defaultValues().get();
playerName = player.getUsername();

Expand All @@ -114,7 +114,7 @@ public void setUp() throws Exception {
when(uiService.getThemeFileUrl(any())).then(invocation -> getThemeFileUrl(invocation.getArgument(0)));
when(emoticonService.getEmoticonShortcodeDetectorPattern()).thenReturn(Pattern.compile(".*"));
when(privatePlayerInfoController.chatUserProperty()).thenReturn(new SimpleObjectProperty<>());
when(avatarService.loadAvatar(player.getAvatar())).thenReturn(mock(Image.class));
when(avatarService.loadAvatar(player.getAvatar())).thenReturn(new Image(InputStream.nullInputStream()));
when(uiService.createShowingProperty(any())).thenReturn(new SimpleBooleanProperty(true));

loadFxml("theme/chat/private_chat_tab.fxml", clazz -> {
Expand Down Expand Up @@ -187,7 +187,7 @@ public void checkSetDefaultIconForTabIfPlayerHasNoAvatar() {
public void checkPlayerAvatarListener() throws Exception {
assertNotNull(instance.avatarImageView.getImage());

Image newAvatar = mock(Image.class);
Image newAvatar = new Image(InputStream.nullInputStream());
AvatarBean avatarBean = AvatarBeanBuilder.create().defaultValues().url(new URL("https://test11.com")).get();
when(avatarService.loadAvatar(avatarBean)).thenReturn(newAvatar);
runOnFxThreadAndWait(() -> player.setAvatar(avatarBean));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -33,9 +33,13 @@ public class AddEditPlayerNoteMenuItemTest extends UITest {
@Mock
private I18n i18n;

@InjectMocks
private AddEditPlayerNoteMenuItem instance;

@BeforeEach
public void setUp() throws Exception {
instance = new AddEditPlayerNoteMenuItem(uiService, playerService, i18n);
}

@Override
protected Pane getRoot() {
return new StackPane();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import com.faforever.client.player.PlayerService;
import com.faforever.client.player.SocialStatus;
import com.faforever.client.test.UITest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -21,9 +21,14 @@ public class AddFoeMenuItemTest extends UITest {
private PlayerService playerService;
@Mock
private I18n i18n;
@InjectMocks

private AddFoeMenuItem instance;

@BeforeEach
public void setUp() throws Exception {
instance = new AddFoeMenuItem(playerService, i18n);
}

@Test
public void testAddFoeIfPlayerIsFriend() {
PlayerBean player = PlayerBeanBuilder.create().defaultValues().socialStatus(SocialStatus.FRIEND).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import com.faforever.client.player.PlayerService;
import com.faforever.client.player.SocialStatus;
import com.faforever.client.test.UITest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -21,9 +21,14 @@ public class AddFriendMenuItemTest extends UITest {
private PlayerService playerService;
@Mock
private I18n i18n;
@InjectMocks

private AddFriendMenuItem instance;

@BeforeEach
public void setUp() throws Exception {
instance = new AddFriendMenuItem(playerService, i18n);
}

@Test
public void testAddFriendIfPlayerIsFor() {
PlayerBean player = PlayerBeanBuilder.create().defaultValues().socialStatus(SocialStatus.FOE).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.faforever.client.moderator.ModeratorService;
import com.faforever.client.test.UITest;
import com.faforever.commons.api.dto.GroupPermission;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import java.util.Collections;
Expand All @@ -22,9 +22,14 @@ public class BroadcastMessageMenuItemTest extends UITest {
private I18n i18n;
@Mock
private ModeratorService moderatorService;
@InjectMocks

private BroadcastMessageMenuItem instance;

@BeforeEach
public void setUp() throws Exception {
instance = new BroadcastMessageMenuItem(i18n, moderatorService);
}

@Test
public void testVisibleItem() {
when(moderatorService.getPermissions()).thenReturn(Set.of(GroupPermission.ROLE_WRITE_MESSAGE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import com.faforever.client.domain.GameBean;
import com.faforever.client.i18n.I18n;
import com.faforever.client.replay.LiveReplayService;
import com.faforever.client.replay.TrackingLiveReplayAction;
import com.faforever.client.replay.TrackingLiveReplay;
import com.faforever.client.replay.TrackingLiveReplayAction;
import com.faforever.client.test.UITest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import java.util.Optional;
Expand All @@ -25,9 +25,14 @@ public class CancelActionNotifyMeMenuItemTest extends UITest {
@Mock
private LiveReplayService liveReplayService;

@InjectMocks

private CancelActionNotifyMeMenuItem instance;

@BeforeEach
public void setUp() throws Exception {
instance = new CancelActionNotifyMeMenuItem(i18n, liveReplayService);
}

@Test
public void testOnClickedCancelActionNotifyMe() {
instance.onClicked();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
import com.faforever.client.domain.GameBean;
import com.faforever.client.i18n.I18n;
import com.faforever.client.replay.LiveReplayService;
import com.faforever.client.replay.TrackingLiveReplayAction;
import com.faforever.client.replay.TrackingLiveReplay;
import com.faforever.client.replay.TrackingLiveReplayAction;
import com.faforever.client.test.UITest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -26,9 +25,14 @@ public class CancelActionRunReplayImmediatelyMenuItemTest extends UITest {
@Mock
private LiveReplayService liveReplayService;

@InjectMocks

private CancelActionRunReplayImmediatelyMenuItem instance;

@BeforeEach
public void setUp() throws Exception {
instance = new CancelActionRunReplayImmediatelyMenuItem(i18n, liveReplayService);
}

@Test
public void testOnClickedCancelActionRunReplayImmediately() {
instance.setObject(GameBeanBuilder.create().get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import javafx.scene.control.Label;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;

Expand All @@ -35,11 +34,11 @@ public class ChangeUsernameColorMenuItemTest extends UITest {
@Spy
private ChatPrefs chatPrefs;

@InjectMocks
private ChangeUsernameColorMenuItem instance;

@BeforeEach
public void setUp() throws Exception {
instance = new ChangeUsernameColorMenuItem(uiService, i18n, contextMenuBuilder, chatPrefs);
chatPrefs.setChatColorMode(ChatColorMode.DEFAULT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.faforever.client.teammatchmaking.TeamMatchmakingService;
import com.faforever.client.test.UITest;
import com.faforever.commons.lobby.GameStatus;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;

Expand All @@ -21,9 +21,14 @@ public class InvitePlayerMenuItemTest extends UITest {
private TeamMatchmakingService teamMatchmakingService;
@Mock
private I18n i18n;
@InjectMocks

private InvitePlayerMenuItem instance;

@BeforeEach
public void setUp() throws Exception {
instance = new InvitePlayerMenuItem(i18n, teamMatchmakingService);
}

@Test
public void testInvitePlayer() {
PlayerBean player = PlayerBeanBuilder.create().defaultValues().get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.faforever.client.i18n.I18n;
import com.faforever.client.test.UITest;
import com.faforever.commons.lobby.GameStatus;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -21,9 +21,14 @@ public class JoinGameMenuItemTest extends UITest {
private I18n i18n;
@Mock
private JoinGameHelper joinGameHelper;
@InjectMocks

private JoinGameMenuItem instance;

@BeforeEach
public void setUp() throws Exception {
instance = new JoinGameMenuItem(i18n, joinGameHelper);
}

@Test
public void testJoinGame() {
PlayerBean player = PlayerBeanBuilder.create().defaultValues().username("junit")
Expand Down
Loading

0 comments on commit 3f68310

Please sign in to comment.