Skip to content

Commit

Permalink
Fix Github actions & unit tests (#3244)
Browse files Browse the repository at this point in the history
* chore: update github actions

* test: fix initialization

* test: add missing imports for test initialization
  • Loading branch information
Ingrim4 authored Sep 23, 2024
1 parent fb08567 commit 7338183
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
Expand All @@ -22,7 +22,7 @@ jobs:
run: ./gradlew build shadowJar --no-daemon

- name: Upload plugin file
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: ProtocolLib
path: build/libs/ProtocolLib.jar
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'gradle'

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: 'java'

- name: Run gradle build lifecycle
run: ./gradlew build -x test --no-daemon

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
32 changes: 31 additions & 1 deletion src/test/java/com/comphenix/protocol/BukkitInitialization.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.comphenix.protocol;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import com.comphenix.protocol.reflect.accessors.Accessors;
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
Expand Down Expand Up @@ -41,6 +44,7 @@
import org.bukkit.Bukkit;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_21_R1.CraftLootTable;
import org.bukkit.craftbukkit.v1_21_R1.CraftRegistry;
Expand Down Expand Up @@ -162,7 +166,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 +261,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 7338183

Please sign in to comment.