1313
1414import com .loohp .interactionvisualizer .utils .LegacyTextComponentCache ;
1515import net .kyori .adventure .text .Component ;
16- import org .bukkit .Location ;
17- import org .bukkit .World ;
1816import org .junit .jupiter .api .AfterEach ;
1917import org .junit .jupiter .api .BeforeEach ;
2018import org .junit .jupiter .api .Test ;
2119import org .junit .jupiter .api .parallel .ResourceLock ;
2220
23- import java .lang .reflect .Proxy ;
24- import java .util .UUID ;
25-
2621import static org .junit .jupiter .api .Assertions .assertEquals ;
2722import static org .junit .jupiter .api .Assertions .assertFalse ;
2823import static org .junit .jupiter .api .Assertions .assertNull ;
@@ -44,8 +39,9 @@ void tearDown() {
4439 }
4540
4641 @ Test
47- void itemSkipsEqualRawTextAndInvalidatesTheSentinelForComponentAndNullSetters () {
48- Item item = new Item (location ());
42+ void itemSkipsEqualRawTextAndInvalidatesTheSentinelForComponentAndNullSetters ()
43+ throws ReflectiveOperationException {
44+ Item item = EntityHolderTestFactory .allocate (Item .class );
4945 String raw = "§aReady" ;
5046
5147 assertTrue (item .updateCustomName (raw ));
@@ -67,8 +63,9 @@ void itemSkipsEqualRawTextAndInvalidatesTheSentinelForComponentAndNullSetters()
6763 }
6864
6965 @ Test
70- void displaySkipsEqualRawTextAndInvalidatesTheSentinelForComponentAndNullSetters () {
71- DisplayEntity display = new DisplayEntity (location ());
66+ void displaySkipsEqualRawTextAndInvalidatesTheSentinelForComponentAndNullSetters ()
67+ throws ReflectiveOperationException {
68+ DisplayEntity display = EntityHolderTestFactory .allocate (DisplayEntity .class );
7269 String raw = "§bWorking" ;
7370
7471 assertTrue (display .updateCustomName (raw , true ));
@@ -91,8 +88,9 @@ void displaySkipsEqualRawTextAndInvalidatesTheSentinelForComponentAndNullSetters
9188 }
9289
9390 @ Test
94- void displayTreatsEqualPlainTextWithDifferentLegacyColorsAsARealChange () {
95- DisplayEntity display = new DisplayEntity (location ());
91+ void displayTreatsEqualPlainTextWithDifferentLegacyColorsAsARealChange ()
92+ throws ReflectiveOperationException {
93+ DisplayEntity display = EntityHolderTestFactory .allocate (DisplayEntity .class );
9694 assertTrue (display .updateCustomName ("§a||||" , true ));
9795 int greenRevision = display .cacheCode ();
9896
@@ -101,27 +99,14 @@ void displayTreatsEqualPlainTextWithDifferentLegacyColorsAsARealChange() {
10199 }
102100
103101 @ Test
104- void displayTreatsEqualPlainTextWithDifferentFontsAsARealChange () {
105- DisplayEntity display = new DisplayEntity (location ());
102+ void displayTreatsEqualPlainTextWithDifferentFontsAsARealChange ()
103+ throws ReflectiveOperationException {
104+ DisplayEntity display = EntityHolderTestFactory .allocate (DisplayEntity .class );
106105 assertTrue (display .updateCustomName ("[font=minecraft:default]same" , true ));
107106 int defaultFontRevision = display .cacheCode ();
108107
109108 assertTrue (display .updateCustomName ("[font=minecraft:uniform]same" , true ));
110109 assertEquals (defaultFontRevision + 1 , display .cacheCode ());
111110 }
112111
113- private static Location location () {
114- UUID id = UUID .randomUUID ();
115- World world = (World ) Proxy .newProxyInstance (
116- World .class .getClassLoader (), new Class <?>[]{World .class }, (proxy , method , arguments ) -> {
117- return switch (method .getName ()) {
118- case "getUID" -> id ;
119- case "toString" -> "World[" + id + "]" ;
120- case "hashCode" -> System .identityHashCode (proxy );
121- case "equals" -> proxy == arguments [0 ];
122- default -> throw new UnsupportedOperationException (method .getName ());
123- };
124- });
125- return new Location (world , 0.0D , 64.0D , 0.0D );
126- }
127112}
0 commit comments