Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix test compilation after IndexedObjectSet change #655

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {

// this version of annotations is verified by runelite
compileOnly(group = "org.jetbrains", name = "annotations", version = "23.0.0")
testCompileOnly(group = "org.jetbrains", name = "annotations", version = "23.0.0")

val runeLiteVersion = "latest." + if (project.hasProperty("use.snapshot")) "integration" else "release"
compileOnly(group = "net.runelite", name = "client", version = runeLiteVersion)
Expand Down
11 changes: 2 additions & 9 deletions src/test/java/dinkplugin/notifiers/LootNotifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
import dinkplugin.notifiers.data.RareItemStack;
import dinkplugin.util.ItemUtils;
import dinkplugin.util.KillCountService;
import net.runelite.api.IndexedObjectSet;
import net.runelite.api.ItemID;
import net.runelite.api.NPC;
import net.runelite.api.NpcID;
import net.runelite.api.Player;
import net.runelite.api.WorldView;
import net.runelite.api.coords.WorldPoint;
import net.runelite.client.events.NpcLootReceived;
import net.runelite.client.events.PlayerLootReceived;
Expand All @@ -35,7 +33,6 @@
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.stream.IntStream;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
Expand Down Expand Up @@ -88,12 +85,8 @@ protected void setUp() {
mockItem(ItemID.TUNA, TUNA_PRICE, "Tuna");
}

@SuppressWarnings({ "rawtypes", "unchecked" })
private void mockWorldNpcs(NPC... npcs) {
WorldView worldView = Mockito.mock(WorldView.class);
when(client.getTopLevelWorldView()).thenReturn(worldView);
IndexedObjectSet ios = new IndexedObjectSet<>(npcs, IntStream.range(0, npcs.length).toArray(), npcs.length);
when(worldView.npcs()).thenReturn(ios);
private void mockWorldNpcs(NPC npc) {
mockNpcs(new NPC[] { npc });
}

@Test
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/dinkplugin/notifiers/MockedNotifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import dinkplugin.message.templating.Template;
import dinkplugin.util.BlockingClientThread;
import dinkplugin.util.BlockingExecutor;
import dinkplugin.util.IndexedArray;
import dinkplugin.util.TestImageUtil;
import dinkplugin.util.Utils;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -47,7 +48,6 @@
import java.util.EnumSet;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Consumer;
import java.util.stream.IntStream;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
Expand Down Expand Up @@ -166,12 +166,12 @@ protected void mockItem(int id, int price, String name) {

protected void mockNpcs(NPC[] npcs) {
Mockito.<IndexedObjectSet<? extends NPC>>when(worldView.npcs())
.thenReturn(new IndexedObjectSet<>(npcs, IntStream.range(0, npcs.length).toArray(), npcs.length));
.thenReturn(new IndexedArray<>(npcs));
}

protected void mockPlayers(Player[] players) {
Mockito.<IndexedObjectSet<? extends Player>>when(worldView.players())
.thenReturn(new IndexedObjectSet<>(players, IntStream.range(0, players.length).toArray(), players.length));
.thenReturn(new IndexedArray<>(players));
}

@SneakyThrows
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/dinkplugin/util/IndexedArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dinkplugin.util;

import com.google.common.collect.Iterators;
import lombok.RequiredArgsConstructor;
import net.runelite.api.IndexedObjectSet;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.Iterator;
import java.util.Spliterator;

@RequiredArgsConstructor
public final class IndexedArray<T> implements IndexedObjectSet<T> {
private final T[] array;

@Override
public T byIndex(int index) {
return array[index];
}

@NotNull
@Override
public Iterator<T> iterator() {
return Iterators.forArray(array);
}

@Override
public Spliterator<T> spliterator() {
return Arrays.spliterator(array);
}
}
Loading