@Test void getExistingInstance() throws Exception { String hint = "existingInstance"; when(this.contextComponentManager.hasComponent(RatingsManager.class, hint)).thenReturn(true); when(this.contextComponentManager.getInstance(RatingsManager.class, hint)).thenReturn(ratingsManager); assertSame(ratingsManager, this.factory.getRatingsManager(hint)); verify(this.currentComponentManager, never()).registerComponent(any(), any()); }
@Override public RatingsManager getRatingsManager(String managerName) throws RatingsException { try { RatingsManager result; if (!this.contextComponentManager.hasComponent(RatingsManager.class, managerName)) { RatingsConfiguration ratingsConfiguration = this.getRatingConfiguration(managerName); ComponentDescriptor<RatingsManager> componentDescriptor = this.contextComponentManager .getComponentDescriptor(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result = this.contextComponentManager.getInstance(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result.setRatingConfiguration(ratingsConfiguration); result.setIdentifer(managerName); DefaultComponentDescriptor<RatingsManager> componentDescriptorCopy = new DefaultComponentDescriptor<>(componentDescriptor); componentDescriptorCopy.setRoleHint(managerName); componentDescriptorCopy.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); this.currentComponentManager.registerComponent(componentDescriptorCopy, result); } else { result = this.contextComponentManager.getInstance(RatingsManager.class, managerName); } return result; } catch (ComponentLookupException | ComponentRepositoryException e) { throw new RatingsException("Error when trying to get a RatingManager", e); } }
DefaultRatingsManagerFactory implements RatingsManagerFactory { @Override public RatingsManager getRatingsManager(String managerName) throws RatingsException { try { RatingsManager result; if (!this.contextComponentManager.hasComponent(RatingsManager.class, managerName)) { RatingsConfiguration ratingsConfiguration = this.getRatingConfiguration(managerName); ComponentDescriptor<RatingsManager> componentDescriptor = this.contextComponentManager .getComponentDescriptor(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result = this.contextComponentManager.getInstance(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result.setRatingConfiguration(ratingsConfiguration); result.setIdentifer(managerName); DefaultComponentDescriptor<RatingsManager> componentDescriptorCopy = new DefaultComponentDescriptor<>(componentDescriptor); componentDescriptorCopy.setRoleHint(managerName); componentDescriptorCopy.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); this.currentComponentManager.registerComponent(componentDescriptorCopy, result); } else { result = this.contextComponentManager.getInstance(RatingsManager.class, managerName); } return result; } catch (ComponentLookupException | ComponentRepositoryException e) { throw new RatingsException("Error when trying to get a RatingManager", e); } } }
DefaultRatingsManagerFactory implements RatingsManagerFactory { @Override public RatingsManager getRatingsManager(String managerName) throws RatingsException { try { RatingsManager result; if (!this.contextComponentManager.hasComponent(RatingsManager.class, managerName)) { RatingsConfiguration ratingsConfiguration = this.getRatingConfiguration(managerName); ComponentDescriptor<RatingsManager> componentDescriptor = this.contextComponentManager .getComponentDescriptor(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result = this.contextComponentManager.getInstance(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result.setRatingConfiguration(ratingsConfiguration); result.setIdentifer(managerName); DefaultComponentDescriptor<RatingsManager> componentDescriptorCopy = new DefaultComponentDescriptor<>(componentDescriptor); componentDescriptorCopy.setRoleHint(managerName); componentDescriptorCopy.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); this.currentComponentManager.registerComponent(componentDescriptorCopy, result); } else { result = this.contextComponentManager.getInstance(RatingsManager.class, managerName); } return result; } catch (ComponentLookupException | ComponentRepositoryException e) { throw new RatingsException("Error when trying to get a RatingManager", e); } }  }
DefaultRatingsManagerFactory implements RatingsManagerFactory { @Override public RatingsManager getRatingsManager(String managerName) throws RatingsException { try { RatingsManager result; if (!this.contextComponentManager.hasComponent(RatingsManager.class, managerName)) { RatingsConfiguration ratingsConfiguration = this.getRatingConfiguration(managerName); ComponentDescriptor<RatingsManager> componentDescriptor = this.contextComponentManager .getComponentDescriptor(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result = this.contextComponentManager.getInstance(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result.setRatingConfiguration(ratingsConfiguration); result.setIdentifer(managerName); DefaultComponentDescriptor<RatingsManager> componentDescriptorCopy = new DefaultComponentDescriptor<>(componentDescriptor); componentDescriptorCopy.setRoleHint(managerName); componentDescriptorCopy.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); this.currentComponentManager.registerComponent(componentDescriptorCopy, result); } else { result = this.contextComponentManager.getInstance(RatingsManager.class, managerName); } return result; } catch (ComponentLookupException | ComponentRepositoryException e) { throw new RatingsException("Error when trying to get a RatingManager", e); } }  @Override RatingsManager getRatingsManager(String managerName); }
DefaultRatingsManagerFactory implements RatingsManagerFactory { @Override public RatingsManager getRatingsManager(String managerName) throws RatingsException { try { RatingsManager result; if (!this.contextComponentManager.hasComponent(RatingsManager.class, managerName)) { RatingsConfiguration ratingsConfiguration = this.getRatingConfiguration(managerName); ComponentDescriptor<RatingsManager> componentDescriptor = this.contextComponentManager .getComponentDescriptor(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result = this.contextComponentManager.getInstance(RatingsManager.class, ratingsConfiguration.getRatingsStorageHint()); result.setRatingConfiguration(ratingsConfiguration); result.setIdentifer(managerName); DefaultComponentDescriptor<RatingsManager> componentDescriptorCopy = new DefaultComponentDescriptor<>(componentDescriptor); componentDescriptorCopy.setRoleHint(managerName); componentDescriptorCopy.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); this.currentComponentManager.registerComponent(componentDescriptorCopy, result); } else { result = this.contextComponentManager.getInstance(RatingsManager.class, managerName); } return result; } catch (ComponentLookupException | ComponentRepositoryException e) { throw new RatingsException("Error when trying to get a RatingManager", e); } }  @Override RatingsManager getRatingsManager(String managerName);  }