### Question:
XBeePacketsQueue { public XBeePacket getFirstPacket(int timeout) { if (timeout > 0) { XBeePacket xbeePacket = getFirstPacket(0); Long deadLine = System.currentTimeMillis() + timeout; while (xbeePacket == null && deadLine > System.currentTimeMillis()) { sleep(100); xbeePacket = getFirstPacket(0); } return xbeePacket; } synchronized (lock) { if (!packetsList.isEmpty()) return packetsList.pop(); } return null; } XBeePacketsQueue();  XBeePacketsQueue(int maxLength); void addPacket(XBeePacket xbeePacket); void clearQueue(); XBeePacket getFirstPacket(int timeout); XBeePacket getFirstPacketFrom(RemoteXBeeDevice remoteXBeeDevice, int timeout); XBeePacket getFirstDataPacket(int timeout); XBeePacket getFirstDataPacketFrom(RemoteXBeeDevice remoteXBeeDevice, int timeout); XBeePacket getFirstExplicitDataPacket(int timeout); XBeePacket getFirstExplicitDataPacketFrom(RemoteXBeeDevice remoteXBeeDevice, int timeout); XBeePacket getFirstIPDataPacket(int timeout); XBeePacket getFirstIPv6DataPacket(int timeout); XBeePacket getFirstIPDataPacketFrom(Inet4Address ipAddress, int timeout); XBeePacket getFirstIPv6DataPacketFrom(Inet6Address ipv6Address, int timeout); int getMaxSize(); int getCurrentSize(); static final int DEFAULT_MAX_LENGTH; }### Answer:
@Test public void testGetFirstPacketTimeout() throws Exception { XBeePacketsQueue xbeePacketsQueue = PowerMockito.spy(new XBeePacketsQueue(5)); currentMillis = System.currentTimeMillis(); PowerMockito.mockStatic(System.class); PowerMockito.when(System.currentTimeMillis()).thenReturn(currentMillis); PowerMockito.doAnswer(new Answer<Object>() { public Object answer(InvocationOnMock invocation) throws Exception { Object[] args = invocation.getArguments(); int sleepTime = (Integer)args[0]; changeMillisToReturn(sleepTime); return null; } }).when(xbeePacketsQueue, METHOD_SLEEP, Mockito.anyInt()); XBeePacket xbeePacket = xbeePacketsQueue.getFirstPacket(5000); PowerMockito.verifyPrivate(xbeePacketsQueue, Mockito.times(50)).invoke(METHOD_SLEEP, 100); assertNull(xbeePacket); }