From 1f1366c940b9d9c725835a942c7573ca9e7cf973 Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Tue, 8 Jan 2008 22:01:26 +0000 Subject: [PATCH] fix: a bug in the detection of missing mandatory properties change: unit test to detect this kind of problem SVN: 3365 --- .../common/parser/AbstractParserObjectFactory.java | 2 +- .../systemsx/cisd/common/utilities/ClassUtils.java | 12 ++++++++++-- .../parser/AbstractParserObjectFactoryTest.java | 12 ++++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/common/source/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactory.java b/common/source/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactory.java index ad1565b5350..fbe1a80ba6c 100644 --- a/common/source/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactory.java +++ b/common/source/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactory.java @@ -59,7 +59,7 @@ public abstract class AbstractParserObjectFactory<E> implements IParserObjectFac assert beanClass != null : "Given bean class can not be null."; assert propertyMapper != null : "Given property mapper can not be null."; propertyDescriptors = BeanUtils.getPropertyDescriptors(beanClass); - mandatoryFields = ClassUtils.getMandatoryFields(beanClass); + mandatoryFields = ClassUtils.getMandatoryFields(beanClass, true); checkPropertyMapper(beanClass, propertyMapper); this.propertyMapper = propertyMapper; converterPool = createConverterPool(); diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/ClassUtils.java b/common/source/java/ch/systemsx/cisd/common/utilities/ClassUtils.java index aa03989529c..0f8d7067333 100644 --- a/common/source/java/ch/systemsx/cisd/common/utilities/ClassUtils.java +++ b/common/source/java/ch/systemsx/cisd/common/utilities/ClassUtils.java @@ -46,14 +46,22 @@ public final class ClassUtils * <p> * Never returns <code>null</code> but could return an empty set. * </p> + * @param clazz The class to return the mandatory fields for. + * @param convertToLowerCase If <code>true</code>, all field names are converted to lower case in the set returned. */ - public final static Set<String> getMandatoryFields(Class<?> clazz) + public final static Set<String> getMandatoryFields(Class<?> clazz, boolean convertToLowerCase) { final Set<String> set = new HashSet<String>(); final List<Field> fields = ClassUtils.getMandatoryFieldsList(clazz); for (final Field field : fields) { - set.add(field.getName()); + if (convertToLowerCase) + { + set.add(field.getName().toLowerCase()); + } else + { + set.add(field.getName()); + } } return set; } diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactoryTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactoryTest.java index 86d20a129d1..d0196406ce4 100644 --- a/common/sourceTest/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactoryTest.java +++ b/common/sourceTest/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactoryTest.java @@ -46,7 +46,7 @@ public final class AbstractParserObjectFactoryTest private final void checkBean(Bean bean) { - assertEquals("Bean Name", bean.name); + assertEquals("Bean Name", bean.nAme); assertEquals("Bean Description", bean.description); assertEquals(1, bean.number); } @@ -151,20 +151,20 @@ public final class AbstractParserObjectFactoryTest public final static class Bean { @Mandatory - private String name; + private String nAme; private String description; private int number; - public final String getName() + public final String getNAme() { - return name; + return nAme; } - public final void setName(String name) + public final void setNAme(String name) { - this.name = name; + this.nAme = name; } public final int getNumber() -- GitLab