ConfigurationDaoHelper { @SuppressWarnings("unchecked") public <T> T getXmlClobPropertyAndUnmarshallToObject(Class<T> classType, String configurationKey) { String xml = getClobProperty(configurationKey); if (StringUtils.isNotBlank(xml)) { try { return xmlHelper.unmarshallXmlToObject(classType, xml); } catch (JAXBException e) { throw new IllegalStateException(String.format("Failed to unmarshall \"%s\" configuration value to %s.", configurationKey, classType.getName()), e); } } else { return null; } }  void checkNotAllowedMethod(String methodName); String getClobProperty(String configurationKey); @SuppressWarnings("unchecked") T getXmlClobPropertyAndUnmarshallToObject(Class<T> classType, String configurationKey);  }
@Test public void testGetXmlClobPropertyAndUnmarshallToObject() throws JAXBException { ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(CONFIGURATION_VALUE); when(configurationDao.getConfigurationByKey(CONFIGURATION_KEY)).thenReturn(configurationEntity); when(xmlHelper.unmarshallXmlToObject(String.class, CONFIGURATION_VALUE)).thenReturn(STRING_VALUE); String result = configurationDaoHelper.getXmlClobPropertyAndUnmarshallToObject(String.class, CONFIGURATION_KEY); verify(configurationDao).getConfigurationByKey(CONFIGURATION_KEY); verify(xmlHelper).unmarshallXmlToObject(String.class, CONFIGURATION_VALUE); verifyNoMoreInteractionsHelper(); assertEquals(STRING_VALUE, result); }
@Test public void testGetXmlClobPropertyAndUnmarshallToObjectConfigurationValueIsBlank() { ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(BLANK_TEXT); when(configurationDao.getConfigurationByKey(CONFIGURATION_KEY)).thenReturn(configurationEntity); String result = configurationDaoHelper.getXmlClobPropertyAndUnmarshallToObject(String.class, CONFIGURATION_KEY); verify(configurationDao).getConfigurationByKey(CONFIGURATION_KEY); verifyNoMoreInteractionsHelper(); assertNull(result); }
@Test public void testGetXmlClobPropertyAndUnmarshallToObjectJAXBException() throws JAXBException { ConfigurationEntity configurationEntity = mock(ConfigurationEntity.class); when(configurationEntity.getValueClob()).thenReturn(CONFIGURATION_VALUE); when(configurationDao.getConfigurationByKey(CONFIGURATION_KEY)).thenReturn(configurationEntity); when(xmlHelper.unmarshallXmlToObject(String.class, CONFIGURATION_VALUE)).thenThrow(new JAXBException(ERROR_MESSAGE)); try { configurationDaoHelper.getXmlClobPropertyAndUnmarshallToObject(String.class, CONFIGURATION_KEY); } catch (IllegalStateException e) { assertEquals(String.format("Failed to unmarshall \"%s\" configuration value to %s.", CONFIGURATION_KEY, String.class.getName()), e.getMessage()); } verify(configurationDao).getConfigurationByKey(CONFIGURATION_KEY); verify(xmlHelper).unmarshallXmlToObject(String.class, CONFIGURATION_VALUE); verifyNoMoreInteractionsHelper(); }