Commits
DerFrZocker authored and md_5 committed 4a1df30e43a
1 1 | package org.bukkit; |
2 2 | |
3 - | import static org.bukkit.support.MatcherAssert.*; |
4 - | import static org.hamcrest.Matchers.*; |
5 3 | import static org.junit.jupiter.api.Assertions.*; |
6 - | import com.google.common.collect.Lists; |
7 - | import java.util.Collections; |
8 - | import java.util.HashMap; |
9 - | import java.util.List; |
10 - | import java.util.Map; |
11 - | import net.minecraft.core.Holder; |
12 - | import net.minecraft.core.registries.Registries; |
13 - | import net.minecraft.resources.ResourceKey; |
14 - | import net.minecraft.world.entity.decoration.PaintingVariant; |
15 - | import org.bukkit.craftbukkit.CraftArt; |
16 - | import org.bukkit.craftbukkit.CraftRegistry; |
17 - | import org.bukkit.support.environment.AllFeatures; |
18 - | import org.junit.jupiter.api.Test; |
4 + | import java.util.stream.Stream; |
5 + | import org.bukkit.support.environment.VanillaFeature; |
6 + | import org.junit.jupiter.params.ParameterizedTest; |
7 + | import org.junit.jupiter.params.provider.Arguments; |
8 + | import org.junit.jupiter.params.provider.MethodSource; |
19 9 | |
20 - | |
10 + | |
21 11 | public class ArtTest { |
22 12 | |
23 - | |
24 - | public void verifyMapping() { |
25 - | List<Art> arts = Lists.newArrayList(Art.values()); |
26 - | |
27 - | for (ResourceKey<PaintingVariant> key : CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT).registryKeySet()) { |
28 - | Holder<PaintingVariant> enumArt = CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT).getOrThrow(key); |
29 - | String name = key.location().getPath(); |
30 - | int width = enumArt.value().width(); |
31 - | int height = enumArt.value().height(); |
32 - | |
33 - | Art subject = CraftArt.minecraftHolderToBukkit(enumArt); |
34 - | |
35 - | String message = String.format("org.bukkit.Art is missing '%s'", name); |
36 - | assertNotNull(subject, message); |
37 - | |
38 - | assertThat(Art.getByName(name), is(subject)); |
39 - | assertThat(subject.getBlockWidth(), is(width), "Art." + subject + "'s width"); |
40 - | assertThat(subject.getBlockHeight(), is(height), "Art." + subject + "'s height"); |
41 - | |
42 - | arts.remove(subject); |
43 - | } |
13 + | public static Stream<Arguments> widthData() { |
14 + | return Stream.of(Arguments.of(Art.KEBAB, 1), |
15 + | Arguments.of(Art.WANDERER, 1), |
16 + | Arguments.of(Art.POOL, 2), |
17 + | Arguments.of(Art.MATCH, 2), |
18 + | Arguments.of(Art.BOUQUET, 3), |
19 + | Arguments.of(Art.BACKYARD, 3), |
20 + | Arguments.of(Art.FIGHTERS, 4), |
21 + | Arguments.of(Art.SKELETON, 4), |
22 + | Arguments.of(Art.POINTER, 4)); |
23 + | } |
44 24 | |
45 - | assertThat(arts, is(Collections.EMPTY_LIST), "org.bukkit.Art has too many arts"); |
25 + | public static Stream<Arguments> heightData() { |
26 + | return Stream.of(Arguments.of(Art.KEBAB, 1), |
27 + | Arguments.of(Art.WANDERER, 2), |
28 + | Arguments.of(Art.POOL, 1), |
29 + | Arguments.of(Art.MATCH, 2), |
30 + | Arguments.of(Art.BOUQUET, 3), |
31 + | Arguments.of(Art.BACKYARD, 4), |
32 + | Arguments.of(Art.FIGHTERS, 2), |
33 + | Arguments.of(Art.SKELETON, 3), |
34 + | Arguments.of(Art.POINTER, 4)); |
46 35 | } |
47 36 | |
48 - | |
49 - | public void testCraftArtToNotch() { |
50 - | Map<Holder<PaintingVariant>, Art> cache = new HashMap<>(); |
51 - | for (Art art : Art.values()) { |
52 - | Holder<PaintingVariant> enumArt = CraftArt.bukkitToMinecraftHolder(art); |
53 - | assertNotNull(enumArt, art.name()); |
54 - | assertThat(cache.put(enumArt, art), is(nullValue()), art.name()); |
55 - | } |
37 + | |
38 + | "widthData") ( |
39 + | public void testWidth(Art art, int expected) { |
40 + | assertEquals(expected, art.getBlockWidth(), """ |
41 + | Art '%s' does not have the correct width. |
42 + | This can be caused by either a change in the Implementation. |
43 + | Or the width for this specific art was changed in which case the test needs to be updated. |
44 + | """.formatted(art.getKey())); |
56 45 | } |
57 46 | |
58 - | |
59 - | public void testCraftArtToBukkit() { |
60 - | Map<Art, Holder<PaintingVariant>> cache = new HashMap<>(); |
61 - | for (Holder<PaintingVariant> enumArt : CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT).asHolderIdMap()) { |
62 - | Art art = CraftArt.minecraftHolderToBukkit(enumArt); |
63 - | assertNotNull(art, "Could not CraftArt.NotchToBukkit " + enumArt); |
64 - | assertThat(cache.put(art, enumArt), is(nullValue()), "Duplicate artwork " + enumArt); |
65 - | } |
47 + | |
48 + | "heightData") ( |
49 + | public void testHeight(Art art, int expected) { |
50 + | assertEquals(expected, art.getBlockHeight(), """ |
51 + | Art '%s' does not have the correct height. |
52 + | This can be caused by either a change in the Implementation. |
53 + | Or the height for this specific art was changed in which case the test needs to be updated. |
54 + | """.formatted(art.getKey())); |
66 55 | } |
67 56 | } |