Skip to content

Commit

Permalink
test: fix initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Ingrim4 authored Sep 22, 2024
1 parent 547b478 commit 54febaf
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/test/java/com/comphenix/protocol/BukkitInitialization.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ private void initialize() {
});
when(mockedServer.getRegistry(any())).thenAnswer(invocation -> {
Class<Keyed> registryType = invocation.getArgument(0);
return CraftRegistry.createRegistry(registryType, registryCustom);
Object registry = CraftRegistry.createRegistry(registryType, registryCustom);

// this is very temporary fix to the version mismatch between spigot-api (spigot-repo) and spigot (dmulloy2-repo)
// if you remove this fix please also remove the DummyRegistry class down below
if (registry == null)
return new DummyRegistry<>();

return registry;
});

when(mockedServer.getTag(any(), any(), any())).then(mock -> {
Expand Down Expand Up @@ -250,4 +257,23 @@ private void setPackage() {
MinecraftReflectionTestUtil.init();
}
}

class DummyRegistry<T extends Keyed> implements Registry<T> {

@Override
public Iterator<T> iterator() {
return Collections.emptyIterator();
}

@Override
public T get(NamespacedKey key) {
return null;
}

@Override
public Stream<T> stream() {
List<T> emtpy = Collections.emptyList();
return emtpy.stream();
}
}
}

0 comments on commit 54febaf

Please sign in to comment.