From 743dea6ad8c95c9a45031c967143e01b569dfb05 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 28 Jan 2023 11:36:12 -0800 Subject: [PATCH] fix fake data service creating invalid projects --- .../java/io/papermc/hangar/model/common/projects/Category.java | 2 ++ .../io/papermc/hangar/service/internal/FakeDataService.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/io/papermc/hangar/model/common/projects/Category.java b/backend/src/main/java/io/papermc/hangar/model/common/projects/Category.java index 9e869b3fa..e45f30a68 100644 --- a/backend/src/main/java/io/papermc/hangar/model/common/projects/Category.java +++ b/backend/src/main/java/io/papermc/hangar/model/common/projects/Category.java @@ -26,6 +26,8 @@ public enum Category { MISC(9, "mdi-asterisk", "misc"), UNDEFINED(10, "", "undefined", false); + public static final List VALID_CATEGORIES = Arrays.stream(Category.values()).filter(c -> c != UNDEFINED).toList(); + private final int value; private final String icon; private final boolean isVisible; diff --git a/backend/src/main/java/io/papermc/hangar/service/internal/FakeDataService.java b/backend/src/main/java/io/papermc/hangar/service/internal/FakeDataService.java index 653a5f559..19ef0bdd9 100644 --- a/backend/src/main/java/io/papermc/hangar/service/internal/FakeDataService.java +++ b/backend/src/main/java/io/papermc/hangar/service/internal/FakeDataService.java @@ -101,7 +101,7 @@ public class FakeDataService extends HangarComponent { final String projectName = this.normalize(this.faker.funnyName().name() + "_" + this.faker.minecraft().animalName()); final String quote = this.faker.theItCrowd().quotes(); final NewProjectForm newProject = new NewProjectForm(settings, - Category.values()[this.faker.random().nextInt(Category.values().length)], + Category.VALID_CATEGORIES.get(this.faker.random().nextInt(Category.VALID_CATEGORIES.size())), quote.substring(0, Math.min(quote.length(), 254)), ownerId, projectName.substring(0, Math.min(projectName.length(), 24)),