DebugSessionManager { @NotNull public DebugSession stopDebugSession(@NotNull MessageReceiver messageReceiver) throws IllegalArgumentException { if (closed) { throw new IllegalStateException("This debug session manager is closed. A new one must be created."); } DebugSession debugSession = getDebugSession(messageReceiver); if (debugSession == null) { throw new IllegalArgumentException("There is no DebugSession to stop for this messageReceiver"); } stopSession(debugSession); debugSessions.remove(messageReceiver); return debugSession; } DebugSessionManager(@NotNull Messaging messagingPlugin); @Nullable DebugSession getDebugSession(@NotNull MessageReceiver messageReceiver); boolean hasDebugSession(@NotNull MessageReceiver messageReceiver); @NotNull DebugSession startDebugSession(@NotNull MessageReceiver messageReceiver); @NotNull DebugSession stopDebugSession(@NotNull MessageReceiver messageReceiver); void shutdown(); boolean hasActiveDebugSessions(); static final Message DEBUG_SESSION_REMINDER; }
@Test public void testStopNonExistentDebugSession() { try { debugSessionManager.stopDebugSession(messageReceiver); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().equals("There is no DebugSession to stop for this messageReceiver")); } }
@Test public void testStopDebugSession() { DebugSession expectedDebugSession = debugSessionManager.startDebugSession(messageReceiver); assertFalse(expectedDebugSession.isClosed()); debugSessionManager.debugSessions.put(messageReceiver, expectedDebugSession); assertTrue(debugSessionManager.hasDebugSession(messageReceiver)); DebugSession actualDebugSession = debugSessionManager.stopDebugSession(messageReceiver); assertFalse(debugSessionManager.hasDebugSession(messageReceiver)); assertSame(expectedDebugSession, actualDebugSession); assertFalse(plugin.getMessager().unsubscribeFromDebugBroadcast(actualDebugSession.getDebugSubscription())); assertFalse(plugin.getLog().unsubscribeFromDebugBroadcast(actualDebugSession.getDebugSubscription())); assertTrue(actualDebugSession.isClosed()); }