@Test public void testModifyExistingComponentState() { String componentId = "componentId"; ComponentType componentType = ComponentType.EXTENSION; int componentStateId = 100; ComponentState existingComponentState = new ComponentState(componentId, componentType, false); existingComponentState.setId(componentStateId); Criteria mockCriteria = mock(Criteria.class); DbSession mockSession = mock(DbSession.class); when(sessionFactory.getCurrentSession()).thenReturn(mockSession); when(mockSession.createCriteria(ComponentState.class)).thenReturn(mockCriteria); when(mockCriteria.uniqueResult()).thenReturn(existingComponentState); allComponentsState.setComponentState(componentId, componentType, true); ArgumentCaptor<ComponentState> componentStateArgumentCaptor = ArgumentCaptor.forClass(ComponentState.class); verify(mockSession).saveOrUpdate(componentStateArgumentCaptor.capture()); assertEquals(componentStateId, (int) componentStateArgumentCaptor.getValue().getId()); assertEquals(true, (boolean)componentStateArgumentCaptor.getValue().getEnabled()); }
@Transactional public void setComponentState(String componentId, ComponentType type, boolean enabled) { log.debug("Setting Component State : componentId = " + componentId + " type = " + type + " enabled " + enabled); ComponentState componentState; synchronized (lockObject) { componentState = getComponentState(componentId, type); if (componentState == null) { componentState = new ComponentState(componentId, type, enabled); } else { componentState.setEnabled(enabled); } sessionFactory.getCurrentSession().saveOrUpdate(componentState); } }
AllComponentsState { @Transactional public void setComponentState(String componentId, ComponentType type, boolean enabled) { log.debug("Setting Component State : componentId = " + componentId + " type = " + type + " enabled " + enabled); ComponentState componentState; synchronized (lockObject) { componentState = getComponentState(componentId, type); if (componentState == null) { componentState = new ComponentState(componentId, type, enabled); } else { componentState.setEnabled(enabled); } sessionFactory.getCurrentSession().saveOrUpdate(componentState); } } }
AllComponentsState { @Transactional public void setComponentState(String componentId, ComponentType type, boolean enabled) { log.debug("Setting Component State : componentId = " + componentId + " type = " + type + " enabled " + enabled); ComponentState componentState; synchronized (lockObject) { componentState = getComponentState(componentId, type); if (componentState == null) { componentState = new ComponentState(componentId, type, enabled); } else { componentState.setEnabled(enabled); } sessionFactory.getCurrentSession().saveOrUpdate(componentState); } }  }
AllComponentsState { @Transactional public void setComponentState(String componentId, ComponentType type, boolean enabled) { log.debug("Setting Component State : componentId = " + componentId + " type = " + type + " enabled " + enabled); ComponentState componentState; synchronized (lockObject) { componentState = getComponentState(componentId, type); if (componentState == null) { componentState = new ComponentState(componentId, type, enabled); } else { componentState.setEnabled(enabled); } sessionFactory.getCurrentSession().saveOrUpdate(componentState); } }  void setSessionFactory(DbSessionFactory sessionFactory); @Transactional void setComponentState(String componentId, ComponentType type, boolean enabled); ComponentState getComponentState(String componentId, ComponentType type); }
AllComponentsState { @Transactional public void setComponentState(String componentId, ComponentType type, boolean enabled) { log.debug("Setting Component State : componentId = " + componentId + " type = " + type + " enabled " + enabled); ComponentState componentState; synchronized (lockObject) { componentState = getComponentState(componentId, type); if (componentState == null) { componentState = new ComponentState(componentId, type, enabled); } else { componentState.setEnabled(enabled); } sessionFactory.getCurrentSession().saveOrUpdate(componentState); } }  void setSessionFactory(DbSessionFactory sessionFactory); @Transactional void setComponentState(String componentId, ComponentType type, boolean enabled); ComponentState getComponentState(String componentId, ComponentType type);  }