use of com.laytonsmith.abstraction.MCItemStack in project CommandHelper by EngineHub.
the class StaticTest method GetOnlinePlayer.
public static MCPlayer GetOnlinePlayer(String name, String worldName, MCServer s) {
MCPlayer p = mock(MCPlayer.class);
MCWorld w = mock(MCWorld.class);
MCLocation fakeLocation = StaticTest.GetFakeLocation(w, 0, 0, 0);
MCItemStack fakeItemStack = mock(MCItemStack.class);
when(w.getName()).thenReturn(worldName);
when(p.getWorld()).thenReturn(w);
when(p.isOnline()).thenReturn(true);
when(p.getName()).thenReturn(name);
when(p.getServer()).thenReturn(s);
when(p.isOp()).thenReturn(true);
if (s != null && s.getOnlinePlayers() != null) {
Collection<MCPlayer> online = s.getOnlinePlayers();
boolean alreadyOnline = false;
for (MCPlayer o : online) {
if (o.getName().equals(name)) {
alreadyOnline = true;
break;
}
}
if (!alreadyOnline) {
online.add(p);
when(s.getOnlinePlayers()).thenReturn(new HashSet<MCPlayer>());
}
}
// Plethora of fake data
when(p.getCompassTarget()).thenReturn(fakeLocation);
when(p.getItemAt((Integer) Mockito.any())).thenReturn(fakeItemStack);
return p;
}
Aggregations