@Test @SuppressWarnings("unchecked") public void testInit() { Command callback = mock(Command.class); Consumer<CanvasControl<AbstractCanvas>> canvasControlConsumer = mock(Consumer.class); Consumer<CanvasControl<AbstractCanvasHandler>> canvasHandlerControlConsumer = mock(Consumer.class); tested.registerCanvasControl(SomeTestControl.class) .registerCanvasHandlerControl(SomeTestControl.class) .onCanvasControlRegistered(canvasControlConsumer) .onCanvasHandlerControlRegistered(canvasHandlerControlConsumer) .init(metadata, callback); assertEquals(canvas, tested.getCanvas()); assertEquals(canvasHandler, tested.getCanvasHandler()); assertEquals(canvasControl, tested.getCanvasControls().get(0)); assertEquals(canvasHandlerControl, tested.getCanvasHandlerControls().get(0)); verify(sessionLoader, times(1)).load(eq(metadata), any(ParameterizedCommand.class), any(ParameterizedCommand.class)); verify(canvasInstances, times(1)).select(eq(qualifier)); verify(canvasHandlerInstances, times(1)).select(eq(qualifier)); verify(canvasControlInstances, times(1)).select(eq(SomeTestControl.class), eq(qualifier)); verify(canvasHandlerControlInstances, times(1)).select(eq(SomeTestControl.class), eq(qualifier)); verify(canvasControlConsumer, times(1)).accept(eq(canvasControl)); verify(canvasHandlerControlConsumer, times(1)).accept(eq(canvasHandlerControl)); verify(callback, times(1)).execute(); }
@Override public void init(final Metadata metadata, final Command callback) { if (null != canvas) { throw new IllegalStateException("Session is already loaded!"); } sessionLoader.load(metadata, prefs -> { final Annotation qualifier = definitionUtils.getQualifier(metadata.getDefinitionSetId()); canvas = lookup(canvasInstances, qualifier); canvasHandler = lookup(canvasHandlerInstances, qualifier); canvasControlRegistrationEntries .forEach(entry -> registerCanvasControlEntry(entry, qualifier)); canvasHandlerControlRegistrationEntries .forEach(entry -> registerCanvasHandlerControlEntry(entry, qualifier)); callback.execute(); }, throwable -> { if (LogConfiguration.loggingIsEnabled()) { LOGGER.log(Level.SEVERE, "An error was produced during StunnerPreferences initialization.", throwable); } throw new RuntimeException(throwable); }); }
ManagedSession extends AbstractSession<AbstractCanvas, AbstractCanvasHandler> { @Override public void init(final Metadata metadata, final Command callback) { if (null != canvas) { throw new IllegalStateException("Session is already loaded!"); } sessionLoader.load(metadata, prefs -> { final Annotation qualifier = definitionUtils.getQualifier(metadata.getDefinitionSetId()); canvas = lookup(canvasInstances, qualifier); canvasHandler = lookup(canvasHandlerInstances, qualifier); canvasControlRegistrationEntries .forEach(entry -> registerCanvasControlEntry(entry, qualifier)); canvasHandlerControlRegistrationEntries .forEach(entry -> registerCanvasHandlerControlEntry(entry, qualifier)); callback.execute(); }, throwable -> { if (LogConfiguration.loggingIsEnabled()) { LOGGER.log(Level.SEVERE, "An error was produced during StunnerPreferences initialization.", throwable); } throw new RuntimeException(throwable); }); } }
ManagedSession extends AbstractSession<AbstractCanvas, AbstractCanvasHandler> { @Override public void init(final Metadata metadata, final Command callback) { if (null != canvas) { throw new IllegalStateException("Session is already loaded!"); } sessionLoader.load(metadata, prefs -> { final Annotation qualifier = definitionUtils.getQualifier(metadata.getDefinitionSetId()); canvas = lookup(canvasInstances, qualifier); canvasHandler = lookup(canvasHandlerInstances, qualifier); canvasControlRegistrationEntries .forEach(entry -> registerCanvasControlEntry(entry, qualifier)); canvasHandlerControlRegistrationEntries .forEach(entry -> registerCanvasHandlerControlEntry(entry, qualifier)); callback.execute(); }, throwable -> { if (LogConfiguration.loggingIsEnabled()) { LOGGER.log(Level.SEVERE, "An error was produced during StunnerPreferences initialization.", throwable); } throw new RuntimeException(throwable); }); } @Inject  ManagedSession(final DefinitionUtils definitionUtils,
                          final SessionLoader sessionLoader,
                          final @Any ManagedInstance<AbstractCanvas> canvasInstances,
                          final @Any ManagedInstance<AbstractCanvasHandler> canvasHandlerInstances,
                          final @Any ManagedInstance<CanvasControl<AbstractCanvas>> canvasControlInstances,
                          final @Any ManagedInstance<CanvasControl<AbstractCanvasHandler>> canvasHandlerControlInstances); }
ManagedSession extends AbstractSession<AbstractCanvas, AbstractCanvasHandler> { @Override public void init(final Metadata metadata, final Command callback) { if (null != canvas) { throw new IllegalStateException("Session is already loaded!"); } sessionLoader.load(metadata, prefs -> { final Annotation qualifier = definitionUtils.getQualifier(metadata.getDefinitionSetId()); canvas = lookup(canvasInstances, qualifier); canvasHandler = lookup(canvasHandlerInstances, qualifier); canvasControlRegistrationEntries .forEach(entry -> registerCanvasControlEntry(entry, qualifier)); canvasHandlerControlRegistrationEntries .forEach(entry -> registerCanvasHandlerControlEntry(entry, qualifier)); callback.execute(); }, throwable -> { if (LogConfiguration.loggingIsEnabled()) { LOGGER.log(Level.SEVERE, "An error was produced during StunnerPreferences initialization.", throwable); } throw new RuntimeException(throwable); }); } @Inject  ManagedSession(final DefinitionUtils definitionUtils,
                          final SessionLoader sessionLoader,
                          final @Any ManagedInstance<AbstractCanvas> canvasInstances,
                          final @Any ManagedInstance<AbstractCanvasHandler> canvasHandlerInstances,
                          final @Any ManagedInstance<CanvasControl<AbstractCanvas>> canvasControlInstances,
                          final @Any ManagedInstance<CanvasControl<AbstractCanvasHandler>> canvasHandlerControlInstances); @SuppressWarnings("unchecked") ManagedSession registerCanvasControl(final Class<? extends CanvasControl> type); @SuppressWarnings("unchecked") ManagedSession registerCanvasControl(final Class<? extends CanvasControl> type,
                                                final Class<? extends Annotation> qualifier); @SuppressWarnings("unchecked") ManagedSession registerCanvasHandlerControl(final Class<? extends CanvasControl> type); @SuppressWarnings("unchecked") ManagedSession registerCanvasHandlerControl(final Class<? extends CanvasControl> type,
                                                       final Class<? extends Annotation> qualifier); ManagedSession isControlActive(final Predicate<Class<? extends CanvasControl>> predicate); ManagedSession onCanvasControlRegistered(final Consumer<CanvasControl<AbstractCanvas>> c); ManagedSession onCanvasControlDestroyed(final Consumer<CanvasControl<AbstractCanvas>> c); ManagedSession onCanvasHandlerControlRegistered(final Consumer<CanvasControl<AbstractCanvasHandler>> c); ManagedSession onCanvasHandlerControlDestroyed(final Consumer<CanvasControl<AbstractCanvasHandler>> c); @Override void init(final Metadata metadata,
                     final Command callback); @Override void open(); @Override void destroy(); @Override String getSessionUUID(); @Override AbstractCanvas getCanvas(); @Override AbstractCanvasHandler getCanvasHandler(); CanvasControl<AbstractCanvas> getCanvasControl(final Class<? extends CanvasControl> type); CanvasControl<AbstractCanvasHandler> getCanvasHandlerControl(final Class<? extends CanvasControl> type); static Annotation buildQualifier(final Class<? extends Annotation> type); }
ManagedSession extends AbstractSession<AbstractCanvas, AbstractCanvasHandler> { @Override public void init(final Metadata metadata, final Command callback) { if (null != canvas) { throw new IllegalStateException("Session is already loaded!"); } sessionLoader.load(metadata, prefs -> { final Annotation qualifier = definitionUtils.getQualifier(metadata.getDefinitionSetId()); canvas = lookup(canvasInstances, qualifier); canvasHandler = lookup(canvasHandlerInstances, qualifier); canvasControlRegistrationEntries .forEach(entry -> registerCanvasControlEntry(entry, qualifier)); canvasHandlerControlRegistrationEntries .forEach(entry -> registerCanvasHandlerControlEntry(entry, qualifier)); callback.execute(); }, throwable -> { if (LogConfiguration.loggingIsEnabled()) { LOGGER.log(Level.SEVERE, "An error was produced during StunnerPreferences initialization.", throwable); } throw new RuntimeException(throwable); }); } @Inject  ManagedSession(final DefinitionUtils definitionUtils,
                          final SessionLoader sessionLoader,
                          final @Any ManagedInstance<AbstractCanvas> canvasInstances,
                          final @Any ManagedInstance<AbstractCanvasHandler> canvasHandlerInstances,
                          final @Any ManagedInstance<CanvasControl<AbstractCanvas>> canvasControlInstances,
                          final @Any ManagedInstance<CanvasControl<AbstractCanvasHandler>> canvasHandlerControlInstances); @SuppressWarnings("unchecked") ManagedSession registerCanvasControl(final Class<? extends CanvasControl> type); @SuppressWarnings("unchecked") ManagedSession registerCanvasControl(final Class<? extends CanvasControl> type,
                                                final Class<? extends Annotation> qualifier); @SuppressWarnings("unchecked") ManagedSession registerCanvasHandlerControl(final Class<? extends CanvasControl> type); @SuppressWarnings("unchecked") ManagedSession registerCanvasHandlerControl(final Class<? extends CanvasControl> type,
                                                       final Class<? extends Annotation> qualifier); ManagedSession isControlActive(final Predicate<Class<? extends CanvasControl>> predicate); ManagedSession onCanvasControlRegistered(final Consumer<CanvasControl<AbstractCanvas>> c); ManagedSession onCanvasControlDestroyed(final Consumer<CanvasControl<AbstractCanvas>> c); ManagedSession onCanvasHandlerControlRegistered(final Consumer<CanvasControl<AbstractCanvasHandler>> c); ManagedSession onCanvasHandlerControlDestroyed(final Consumer<CanvasControl<AbstractCanvasHandler>> c); @Override void init(final Metadata metadata,
                     final Command callback); @Override void open(); @Override void destroy(); @Override String getSessionUUID(); @Override AbstractCanvas getCanvas(); @Override AbstractCanvasHandler getCanvasHandler(); CanvasControl<AbstractCanvas> getCanvasControl(final Class<? extends CanvasControl> type); CanvasControl<AbstractCanvasHandler> getCanvasHandlerControl(final Class<? extends CanvasControl> type); static Annotation buildQualifier(final Class<? extends Annotation> type);  }