DebugSessionManager { @NotNull public DebugSession startDebugSession(@NotNull MessageReceiver messageReceiver) throws IllegalStateException { if (closed) { throw new IllegalStateException("This debug session manager is closed. A new one must be created."); } if (debugSessions.containsKey(messageReceiver)) { throw new IllegalStateException("DebugSession already exists for this messageReceiver"); } DebugSubscription debugSubscription = new DebugSubscription(messageReceiver); DebugSession debugSession = startSession(debugSubscription); debugSessions.put(messageReceiver, debugSession); 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 testStartDebugSession() { DebugSession debugSession = debugSessionManager.startDebugSession(messageReceiver); assertNotNull(debugSession); assertFalse(plugin.getMessager().subscribeToDebugBroadcast(debugSession.getDebugSubscription())); assertFalse(plugin.getLog().subscribeToDebugBroadcast(debugSession.getDebugSubscription())); assertFalse(debugSession.isClosed()); }
@Test public void testStartDebugSessionWhenOneExists() { debugSessionManager.debugSessions.put(messageReceiver, new DebugSession(new DebugSubscription(messageReceiver), null)); try { debugSessionManager.startDebugSession(messageReceiver); fail(); } catch (IllegalStateException e) { assertTrue(e.getMessage().equals("DebugSession already exists for this messageReceiver")); } }