Skip to content

Commit

Permalink
Fix NPEs when running tests.
Browse files Browse the repository at this point in the history
Note that there are still test failures, but these are assertions and
not errors.
  • Loading branch information
tastybento committed Apr 16, 2022
1 parent f851a96 commit 2263dae
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -76,7 +77,7 @@
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, Util.class, Utils.class})
@PrepareForTest({Bukkit.class, BentoBox.class, Util.class, Utils.class, ChatColor.class})
public class TryToCompleteTest {

// Constants
Expand Down Expand Up @@ -204,8 +205,9 @@ public void setUp() throws Exception {
when(user.getPlayer()).thenReturn(player);
UUID uniqueId = UUID.randomUUID();
when(user.getUniqueId()).thenReturn(uniqueId);
when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(user.getTranslationOrNothing(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(user.getTranslation(anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(user.getTranslation(anyString(), anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(user.getTranslationOrNothing(anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(user.getName()).thenReturn("tastybento");
@Nullable
Location userLoc = mock(Location.class);
Expand Down Expand Up @@ -256,6 +258,10 @@ public void setUp() throws Exception {
// ItemFactory
ItemFactory itemFactory = mock(ItemFactory.class);
when(Bukkit.getItemFactory()).thenReturn(itemFactory);

// ChatColor
PowerMockito.mockStatic(ChatColor.class, Mockito.RETURNS_MOCKS);
when(ChatColor.stripColor(anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
}

/**
Expand Down

0 comments on commit 2263dae

Please sign in to comment.