diff --git a/README.md b/README.md index 4cf21bd8..62721d77 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# OpenPojo [![Build Status](https://travis-ci.org/OpenPojo/openpojo.svg?branch=master)](https://travis-ci.org/OpenPojo/openpojo) [![Coverage Status](https://coveralls.io/repos/OpenPojo/openpojo/badge.svg?branch=master)](https://coveralls.io/r/OpenPojo/openpojo?branch=master) [![Maven Central](https://img.shields.io/maven-metadata/v/http/central.maven.org/maven2/com/openpojo/openpojo/maven-metadata.xml.svg?style=flat&colorB=007ec6)](http://search.maven.org/#search|ga|1|g%3Acom.openpojo%20a%3Aopenpojo) +# OpenPojo [![Build Status](https://travis-ci.org/OpenPojo/openpojo.svg?branch=master)](https://travis-ci.org/OpenPojo/openpojo) [![Coverage Status](https://coveralls.io/repos/OpenPojo/openpojo/badge.svg?branch=master)](https://coveralls.io/r/OpenPojo/openpojo?branch=master) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.openpojo/openpojo/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.openpojo/openpojo) POJO Testing & Identity Management Made Trivial Maven Group Plugin | Latest Version diff --git a/pom.xml b/pom.xml index 56f836e2..1a726f81 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ com.openpojo openpojo - 0.8.14-SNAPSHOT + 0.9.0-SNAPSHOT ${project.artifactId} This project was born out of a need to validate all POJOs (Plain Old Java Object) are behaving correctly. @@ -90,7 +90,7 @@ 0.8.4 UTF-8 1.5 - 4.12 + 4.13.1 1.2.17 ${jdk.target} ${jdk.target} diff --git a/src/main/java/com/openpojo/reflection/impl/PojoFieldFactory.java b/src/main/java/com/openpojo/reflection/impl/PojoFieldFactory.java index 99636ced..d4bb8a93 100644 --- a/src/main/java/com/openpojo/reflection/impl/PojoFieldFactory.java +++ b/src/main/java/com/openpojo/reflection/impl/PojoFieldFactory.java @@ -19,7 +19,9 @@ package com.openpojo.reflection.impl; import java.lang.reflect.Field; +import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.LinkedList; import java.util.List; @@ -40,7 +42,14 @@ public final class PojoFieldFactory { */ public static List getPojoFields(final Class clazz) { final List pojoFields = new LinkedList(); - for (final Field field : clazz.getDeclaredFields()) { + Field[] declaredFields = clazz.getDeclaredFields(); + Arrays.sort(declaredFields, new Comparator() { + @Override + public int compare(Object a, Object b) { + return a.toString().compareTo(b.toString()); + } + }); + for (final Field field : declaredFields) { pojoFields.add(new PojoFieldImpl(field)); } return Collections.unmodifiableList(pojoFields); diff --git a/src/main/java/com/openpojo/reflection/java/bytecode/asm/ASMDetector.java b/src/main/java/com/openpojo/reflection/java/bytecode/asm/ASMDetector.java index 814e340b..7532c270 100644 --- a/src/main/java/com/openpojo/reflection/java/bytecode/asm/ASMDetector.java +++ b/src/main/java/com/openpojo/reflection/java/bytecode/asm/ASMDetector.java @@ -55,16 +55,17 @@ public Version getVersion() { } public Version getBundleVersion(Class clazz) { - PojoClass pojoClass = PojoClassFactory.getPojoClass(clazz); - String sourcePath = pojoClass.getSourcePath(); - - Version bundleVersion = null; + Version bundleVersion; try { + PojoClass pojoClass = PojoClassFactory.getPojoClass(clazz); + String sourcePath = pojoClass.getSourcePath(); String jarFilePath = JarFileReader.getJarFileNameFromURLPath(sourcePath); String bundleVersionManifestEntry = JarFileReader.getInstance(jarFilePath).getManifestEntry(VERSION_MANIFEST_KEY_FALLBACK); bundleVersion = VersionFactory.getVersion(bundleVersionManifestEntry); - } catch (Exception ignored) { } + } catch (Exception ignored) { + bundleVersion = VersionFactory.getVersion(null); + } return bundleVersion; } diff --git a/src/main/java/com/openpojo/validation/PojoValidator.java b/src/main/java/com/openpojo/validation/PojoValidator.java deleted file mode 100644 index 923deff1..00000000 --- a/src/main/java/com/openpojo/validation/PojoValidator.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2010-2018 Osman Shoukry - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.openpojo.validation; - -import java.util.LinkedList; -import java.util.List; - -import com.openpojo.log.Logger; -import com.openpojo.log.LoggerFactory; -import com.openpojo.reflection.PojoClass; -import com.openpojo.validation.rule.Rule; -import com.openpojo.validation.test.Tester; -import com.openpojo.validation.utils.ValidationHelper; - -/** - * @author oshoukry - * @deprecated This class is deprecated, please use {@link ValidatorBuilder} instead. - */ -public class PojoValidator { - private final List rules = new LinkedList(); - private final List testers = new LinkedList(); - - public PojoValidator() { - DeprecationWarning.getInstance(); - } - - /** - * Add Rule to use for validation. - * - * @param rule - * The rule to Add. - */ - public void addRule(final Rule rule) { - rules.add(rule); - } - - /** - * Add Tester to use for validation. - * - * @param tester - * The Tester to Add. - */ - public void addTester(final Tester tester) { - testers.add(tester); - } - - /** - * Run the validation, this will invoke all the rule.evaluate as well as tester.run. - * - * @param pojoClass - * The PojoClass to validate. - */ - public void runValidation(final PojoClass pojoClass) { - ValidationHelper.runValidation(pojoClass, rules, testers); - } - - - private static class DeprecationWarning { - private static final DeprecationWarning INSTANCE = new DeprecationWarning(); - - private DeprecationWarning() { - Logger logger = LoggerFactory.getLogger(PojoValidator.class); - logger.warn("This class is deprecated, please use " + ValidatorBuilder.class.getName() + " instead."); - } - - private static DeprecationWarning getInstance() { - return INSTANCE; - } - } -} diff --git a/src/test/java/com/openpojo/business/BusinessIdentityTest.java b/src/test/java/com/openpojo/business/BusinessIdentityTest.java index e44d918d..ed1ba02c 100644 --- a/src/test/java/com/openpojo/business/BusinessIdentityTest.java +++ b/src/test/java/com/openpojo/business/BusinessIdentityTest.java @@ -142,7 +142,7 @@ public void testToString() { final String toString = BusinessIdentity.toString(toStringTestData); Assert.assertTrue(String.format("BusinessIdentity.toString() failed!! recieved[%s]", toString), toString.startsWith("com.openpojo.business.BusinessIdentityTest$ToStringTestData [@") - && toString.endsWith(": instance_name=Instance Name, static_name=Static Name, STATIC_FINAL_NAME=Static Final Name]")); + && toString.endsWith(": instance_name=Instance Name, STATIC_FINAL_NAME=Static Final Name, static_name=Static Name]")); } @Test diff --git a/src/test/java/com/openpojo/reflection/java/bytecode/asm/ASMDetectorTest.java b/src/test/java/com/openpojo/reflection/java/bytecode/asm/ASMDetectorTest.java index 9ed3e549..82d713a2 100644 --- a/src/test/java/com/openpojo/reflection/java/bytecode/asm/ASMDetectorTest.java +++ b/src/test/java/com/openpojo/reflection/java/bytecode/asm/ASMDetectorTest.java @@ -50,6 +50,12 @@ public void canGetBundleVersion() { assertLesserOrEqualToMaxExpected(currentVersion); } + @Test + public void shouldNotThrowNullPointerExceptionIfClassIsNotLoaded() { + Version version = asmDetector.getBundleVersion(null); + assertThat(version, notNullValue()); + } + private void assertGreaterOrEqualToMinimumExpected(Version version) { assertThat(version.compareTo(ByteCodeFactory.ASM_MIN_VERSION), greaterThanOrEqualTo(0)); }