Skip to content

Commit

Permalink
FAForever#2420 - Do not create a game with empty title (FAForever#2424)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan <v23620@gmail.com>
  • Loading branch information
2 people authored and Chris Haggan committed Apr 15, 2022
1 parent 9a4008c commit 18226e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import javafx.stage.PopupWindow.AnchorLocation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
Expand Down Expand Up @@ -218,7 +219,7 @@ private void setCreateGameButtonState() {
case DISCONNECTED -> "game.create.disconnected";
case CONNECTING -> "game.create.connecting";
case CONNECTED -> {
if (Strings.isNullOrEmpty(title)) {
if (StringUtils.isBlank(title)) {
yield "game.create.titleMissing";
} else if (!StandardCharsets.US_ASCII.newEncoder().canEncode(title)) {
yield "game.create.titleNotAscii";
Expand Down Expand Up @@ -250,7 +251,7 @@ private void initMapFilterPopup() {
}

private void validateTitle(String gameTitle) {
titleTextField.pseudoClassStateChanged(PSEUDO_CLASS_INVALID, Strings.isNullOrEmpty(gameTitle)
titleTextField.pseudoClassStateChanged(PSEUDO_CLASS_INVALID, StringUtils.isBlank(gameTitle)
|| !StandardCharsets.US_ASCII.newEncoder().canEncode(gameTitle));
}

Expand Down Expand Up @@ -484,7 +485,7 @@ private void hostGame(MapVersionBean mapVersion, Set<String> mods) {
enforceRating = enforceRankingCheckBox.isSelected();

NewGameInfo newGameInfo = new NewGameInfo(
titleTextField.getText(),
titleTextField.getText().trim(),
Strings.emptyToNull(passwordTextField.getText()),
featuredModListView.getSelectionModel().getSelectedItem(),
mapVersion.getFolderName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,19 @@ public void testButtonBindingIfFeaturedModNotSet() {

@Test
public void testButtonBindingIfTitleNotSet() {

when(i18n.get("game.create.titleMissing")).thenReturn("title missing");
WaitForAsyncUtils.asyncFx(() -> instance.initialize());
WaitForAsyncUtils.waitForFxEvents();

String message = "title missing";
when(i18n.get("game.create.titleMissing")).thenReturn(message);
runOnFxThreadAndWait(() -> instance.initialize());
assertThat(instance.titleTextField.getText(), is(""));
assertThat(instance.createGameButton.getText(), is("title missing"));
assertThat(instance.createGameButton.getText(), is(message));

runOnFxThreadAndWait(() -> instance.titleTextField.setText(" "));
assertThat(instance.titleTextField.getText(), is(" "));
assertThat(instance.createGameButton.getText(), is(message));
}

@Test
public void testButtonBindingIfTitleNotAscii() {

when(i18n.get("game.create.titleNotAscii")).thenReturn("title not ascii");
instance.titleTextField.setText("ты");
WaitForAsyncUtils.asyncFx(() -> instance.initialize());
Expand Down

0 comments on commit 18226e0

Please sign in to comment.