Skip to content

Instantly share code, notes, and snippets.

@hef
Created December 4, 2011 20:55
Show Gist options
  • Save hef/1431248 to your computer and use it in GitHub Desktop.
Save hef/1431248 to your computer and use it in GitHub Desktop.
public void setUp() {
//mock objects
Session mockSession = mock(Session.class);
GlowServer mockGlowServer = mock(GlowServer.class);
List<World> mockList = mock(List.class);
GlowWorld mockGlowWorld = mock(GlowWorld.class);
Logger mockLogger = mock(Logger.class);
EntityManager mockEntityManager = mock(EntityManager.class);
SimplePluginManager mockPluginManager = mock(SimplePluginManager.class);
PlayerListFile mockPlayerListFile = mock(PlayerListFile.class);
Environment mockEnvironment = mock(Environment.class);
GlowChunk mockGlowChunk = mock(GlowChunk.class);
Location mockLocation = mock(Location.class);
WorldMetadataService mockWorldMetadataService = mock(WorldMetadataService.class);
StorageQueue mockStorageQueue= mock(StorageQueue.class);
mockStatic(Bukkit.class);
//Session mocked methods
when(mockSession.getServer()).thenReturn(mockGlowServer);
when(mockSession.getState()).thenReturn(Session.State.GAME);
//Server mocked methods
when(mockGlowServer.getWorlds()).thenReturn(mockList);
when(mockGlowServer.getLogger()).thenReturn(mockLogger);
when(mockGlowServer.getPluginManager()).thenReturn(mockPluginManager);
when(mockGlowServer.getOpsList()).thenReturn(mockPlayerListFile);
when(mockGlowServer.getStorageQueue()).thenReturn(mockStorageQueue);
//MockWorkd mocked methods
when(mockGlowWorld.getEntityManager()).thenReturn(mockEntityManager);
when(mockGlowWorld.getEnvironment()).thenReturn(mockEnvironment);
when(mockGlowWorld.getChunkAt(anyInt(), anyInt())).thenReturn(mockGlowChunk);
when(mockGlowWorld.getSpawnLocation()).thenReturn(mockLocation);
when(mockGlowWorld.getMetadataService()).thenReturn(mockWorldMetadataService);
//mockWorldList mocked methods
when(mockList.get(0)).thenReturn(mockGlowWorld);
//mockGlowChunk mocked methods
when(mockGlowChunk.getTileEntities()).thenReturn(new GlowBlockState[0]);
//Bukkit mocked methods
when(Bukkit.getServer()).thenReturn(mockGlowServer);
//Actual Setup
glowPlayer = new GlowPlayer(mockSession,"Herobrine");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment