clues: Fix three step cryptic clue getLocations NPE
Prior to this commit, ThreeStepCrypticClue simply returned a concatenation of the active step locations without filtering the mapped locations in any way. This could lead to NPEs in the plugin as some cryptic clues have null locations for steps which have no specific location or have a variable location. This commit addresses this by making CrypticClue's location field `@Nullable`, filtering null locations from ThreeStepCrypticClue's getLocations stream, and by adding a test to ensure ThreeStepCrypticClue's getLocations method cannot yield any null entries in its return value.
This commit is contained in:
@@ -24,6 +24,10 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.cluescrolls.clues;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import net.runelite.api.coords.WorldPoint;
|
||||
import net.runelite.client.util.Text;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -34,4 +38,17 @@ public class ThreeStepCrypticClueTest
|
||||
{
|
||||
assertNull(ThreeStepCrypticClue.forText("", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonNullLocations()
|
||||
{
|
||||
final String clueText = Joiner.on("<br><br>").join(CrypticClue.CLUES.stream().map(CrypticClue::getText).toArray());
|
||||
final ThreeStepCrypticClue clue = ThreeStepCrypticClue.forText(Text.sanitizeMultilineText(clueText).toLowerCase(), clueText);
|
||||
|
||||
assertNotNull(clue);
|
||||
for (final WorldPoint location : clue.getLocations())
|
||||
{
|
||||
assertNotNull(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user