Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort fields in PojoFieldFactory for deterministic order #137

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<groupId>com.openpojo</groupId>
<artifactId>openpojo</artifactId>
<version>0.8.14-SNAPSHOT</version>
<version>0.9.0-SNAPSHOT</version>
<name>${project.artifactId}</name>

<description>This project was born out of a need to validate all POJOs (Plain Old Java Object) are behaving correctly.
Expand Down Expand Up @@ -90,7 +90,7 @@
<jacoco-maven-plugin.version>0.8.4</jacoco-maven-plugin.version>
<jdk.sourceEncoding>UTF-8</jdk.sourceEncoding>
<jdk.target>1.5</jdk.target>
<junit.version>4.12</junit.version>
<junit.version>4.13.1</junit.version>
<log4j.version>1.2.17</log4j.version>
<maven.compiler.source>${jdk.target}</maven.compiler.source>
<maven.compiler.target>${jdk.target}</maven.compiler.target>
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/openpojo/reflection/impl/PojoFieldFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -40,7 +42,14 @@ public final class PojoFieldFactory {
*/
public static List<PojoField> getPojoFields(final Class<?> clazz) {
final List<PojoField> pojoFields = new LinkedList<PojoField>();
for (final Field field : clazz.getDeclaredFields()) {
Field[] declaredFields = clazz.getDeclaredFields();
Arrays.sort(declaredFields, new Comparator<Object>() {
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
86 changes: 0 additions & 86 deletions src/main/java/com/openpojo/validation/PojoValidator.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down