LDAP-295: DefaultObjectDirectoryMapper null check SpringVersion.getVersion()
This commit is contained in:
@@ -27,7 +27,6 @@ dependencies {
|
||||
"gsbase:gsbase:$gsbaseVersion",
|
||||
"org.mockito:mockito-core:$mockitoVersion",
|
||||
"org.slf4j:slf4j-log4j12:$slf4jVersion",
|
||||
"org.springframework:spring-test:$springVersion"
|
||||
|
||||
}
|
||||
|
||||
"org.springframework:spring-test:$springVersion",
|
||||
powerMockDependencies
|
||||
}
|
||||
@@ -38,6 +38,7 @@ import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.Attribute;
|
||||
import javax.naming.directory.Attributes;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -68,16 +69,19 @@ public class DefaultObjectDirectoryMapper implements ObjectDirectoryMapper {
|
||||
|
||||
|
||||
public DefaultObjectDirectoryMapper() {
|
||||
if(isAtLeast30()) {
|
||||
this.converterManager = new ConversionServiceConverterManager();
|
||||
} else {
|
||||
this.converterManager = new ConverterManagerImpl();
|
||||
}
|
||||
|
||||
this.converterManager = createDefaultConverterManager();
|
||||
}
|
||||
|
||||
private boolean isAtLeast30() {
|
||||
return SpringVersion.getVersion().compareTo("3.0") > 0;
|
||||
private static ConverterManager createDefaultConverterManager() {
|
||||
String springVersion = SpringVersion.getVersion();
|
||||
if(springVersion == null) {
|
||||
LOG.debug("Could not default convertManager, please ensure to explicitly set it");
|
||||
return null;
|
||||
} else if(springVersion.compareTo("3.0") > 0) {
|
||||
return new ConversionServiceConverterManager();
|
||||
} else {
|
||||
return new ConversionServiceConverterManager();
|
||||
}
|
||||
}
|
||||
|
||||
public void setConverterManager(ConverterManager converterManager) {
|
||||
|
||||
@@ -1,25 +1,34 @@
|
||||
package org.springframework.ldap.odm.core.impl;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.matchers.JUnitMatchers;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.naming.Name;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.powermock.api.mockito.PowerMockito.spy;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import static org.springframework.ldap.query.LdapQueryBuilder.query;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import javax.naming.Name;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.matchers.JUnitMatchers;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.springframework.core.SpringVersion;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(SpringVersion.class)
|
||||
public class DefaultObjectDirectoryMapperTest {
|
||||
|
||||
private DefaultObjectDirectoryMapper tested;
|
||||
@@ -29,6 +38,15 @@ public class DefaultObjectDirectoryMapperTest {
|
||||
tested = new DefaultObjectDirectoryMapper();
|
||||
}
|
||||
|
||||
// LDAP-295
|
||||
@Test
|
||||
public void springVersionIsNull() {
|
||||
spy(SpringVersion.class);
|
||||
when(SpringVersion.getVersion()).thenReturn(null);
|
||||
|
||||
new DefaultObjectDirectoryMapper();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping() {
|
||||
tested.manageClass(UnitTestPerson.class);
|
||||
|
||||
@@ -16,6 +16,16 @@ ext.log4jVersion = '1.2.15'
|
||||
ext.mockitoVersion = '1.9.5'
|
||||
ext.queryDslVersion = '3.2.4'
|
||||
ext.slf4jVersion = '1.7.5'
|
||||
ext.powerMockVersion = '1.5.1'
|
||||
|
||||
ext.powerMockDependencies = [
|
||||
"org.powermock:powermock-core:$powerMockVersion",
|
||||
"org.powermock:powermock-api-support:$powerMockVersion",
|
||||
"org.powermock:powermock-module-junit4-common:$powerMockVersion",
|
||||
"org.powermock:powermock-module-junit4:$powerMockVersion",
|
||||
"org.powermock:powermock-api-mockito:$powerMockVersion",
|
||||
"org.powermock:powermock-reflect:$powerMockVersion"
|
||||
]
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
Reference in New Issue
Block a user