JmsPropertyReader { public <T> T get(final String propertyName, final Class<T> targetType) { LOGGER.debug("Trying to find property {}.{}", this.propertyPrefix, propertyName); final String fullPropertyName = this.propertyPrefix + "." + propertyName; T property = this.environment.getProperty(fullPropertyName, targetType); if (property == null) { LOGGER.debug("Property {} not found, trying default property.", fullPropertyName); property = this.getDefault(propertyName, targetType); LOGGER.debug("Found default value {} for property {}", property, propertyName); } else { LOGGER.debug("Found value {} for property {}.{}", property, this.propertyPrefix, propertyName); } return property; } JmsPropertyReader(final Environment environment, final String propertyPrefix,
            final JmsConfiguration defaultJmsConfiguration); T get(final String propertyName, final Class<T> targetType);  }
@Test public void testGetCustomQueueValueWhenCustomPropertyExists() { final String property = "queue"; final String propertyName = PROPERTY_PREFIX + "." + property; when(this.environment.getProperty(propertyName, String.class)).thenReturn(CUSTOM_QUEUE); final String actual = this.jmsPropertyReader.get(property, String.class); verify(this.environment).getProperty(propertyName, String.class); verify(this.defaultJmsConfiguration, never()).getQueue(); assertThat(actual).isEqualTo(CUSTOM_QUEUE); }
@Test public void testGetDefaultQueueValueWhenCustomPropertyDoesNotExist() { final String property = "queue"; final String propertyName = PROPERTY_PREFIX + "." + property; when(this.environment.getProperty(propertyName, String.class)).thenReturn(null); final String actual = this.jmsPropertyReader.get(property, String.class); verify(this.environment).getProperty(propertyName, String.class); verify(this.defaultJmsConfiguration).getQueue(); assertThat(actual).isEqualTo(DEFAULT_QUEUE); }
@Test public void testGetCustomBooleanValueWhenCustomPropertyExists() { final String property = "use.exponential.back.off"; final String propertyName = PROPERTY_PREFIX + "." + property; when(this.environment.getProperty(propertyName, boolean.class)).thenReturn(CUSTOM_USE_BACKOFF); final boolean actual = this.jmsPropertyReader.get(property, boolean.class); verify(this.environment).getProperty(propertyName, boolean.class); verify(this.defaultJmsConfiguration, never()).isUseExponentialBackOff(); assertThat(actual).isEqualTo(CUSTOM_USE_BACKOFF); }
@Test public void testGetDefaultBooleanValueWhenCustomPropertyDoesNotExist() { final String property = "use.exponential.back.off"; final String propertyName = PROPERTY_PREFIX + "." + property; when(this.environment.getProperty(propertyName, boolean.class)).thenReturn(null); final boolean actual = this.jmsPropertyReader.get(property, boolean.class); verify(this.environment).getProperty(propertyName, boolean.class); verify(this.defaultJmsConfiguration).isUseExponentialBackOff(); assertThat(actual).isEqualTo(DEFAULT_USE_BACKOFF); }