test: characterize the package objects

Each holds one member, a logger alias for its proxy's logger. Everything goes
through reflection because 'package' is a Java keyword and cannot appear as a
type name in Java source, which is also why these two classes have no Java
form at all.

The plain-JVM half pins the shape and that the alias reads the proxy's var
rather than holding anything, so it reports null before preInit. The Forge
server half pins the part that matters for what comes next: after preInit each
alias returns the very instance its proxy holds, adding nothing.

123 plain-JVM tests, 23 Forge server tests.
This commit is contained in:
Algent committed 2026-08-15 20:02:42 +02:00
1 parent a2797c986b
commit d6bba7ff46
2 files changed
+92

No files matched your search

@@ -0,0 +1,37 @@
package codechicken.multipart.test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import org.junit.jupiter.api.Test;
import codechicken.microblock.handler.MicroblockProxy;
import codechicken.multipart.handler.MultipartProxy;
/**
* Both proxies publish a logger during preInit, and code across both packages logs through them. A plain JVM test only
* ever sees the uninitialised null, so this is the one place the real instances are observable.
*/
class ProxyLoggerFunctionalTest {
@Test
void bothProxiesPublishALoggerDuringPreInit() {
assertNotNull(MultipartProxy.logger(), "MultipartProxy.logger is set in preInit");
assertNotNull(MicroblockProxy.logger(), "MicroblockProxy.logger is set in preInit");
}
/**
* The package objects are pure aliases: each returns the very instance its proxy holds, adding nothing. That is
* what makes them safe to remove in favour of naming the proxy directly.
*/
@Test
void thePackageObjectAliasesAreTheProxyLoggersThemselves() throws Exception {
assertSame(MultipartProxy.logger(), invokeLogger("codechicken.multipart.package"));
assertSame(MicroblockProxy.logger(), invokeLogger("codechicken.microblock.package"));
}
/** Reflective because {@code package} is a Java keyword and cannot appear as a type name in Java source. */
private static Object invokeLogger(String name) throws Exception {
return Class.forName(name).getDeclaredMethod("logger").invoke(null);
}
}