You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(12) |
Nov
(2) |
Dec
(15) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(7) |
Feb
(2) |
Mar
|
Apr
(22) |
May
|
Jun
|
Jul
(1) |
Aug
(29) |
Sep
(17) |
Oct
(4) |
Nov
|
Dec
(19) |
2010 |
Jan
|
Feb
(9) |
Mar
(2) |
Apr
(34) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(25) |
Nov
(22) |
Dec
(3) |
2014 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <iro...@us...> - 2010-04-16 05:04:40
|
Revision: 214 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=214&view=rev Author: iroberts Date: 2010-04-16 05:04:34 +0000 (Fri, 16 Apr 2010) Log Message: ----------- typo Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java 2010-04-16 04:47:06 UTC (rev 213) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java 2010-04-16 05:04:34 UTC (rev 214) @@ -16,7 +16,7 @@ /** * A provider of the three standard {@code Object} methods, * {@link Object#equals(Object)}, {@link Object#hashCode()} and {@link Object#toString()}, as - * well as a usefull method to aid in debugging, {@link #doDiff(Object, Object)}}. + * well as a usefull method to aid in debugging, {@link #doDiff(Object, Object)}. * * @param <T> the class this {@code Pojomator} is generated for. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-04-16 04:47:12
|
Revision: 213 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=213&view=rev Author: iroberts Date: 2010-04-16 04:47:06 +0000 (Fri, 16 Apr 2010) Log Message: ----------- spelling Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java 2010-04-16 04:36:09 UTC (rev 212) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/EqualsInheritanceTest.java 2010-04-16 04:47:06 UTC (rev 213) @@ -38,7 +38,7 @@ assertFalse(child.equals(PARENT)); assertFalse(PARENT_POJOMATOR.doEquals(PARENT, child)); assertFalse(childPojomator.doEquals(child, PARENT)); - // If we expicitely use a PARENT_POJOMATOR to compare child to parent, we'll miss the additional + // If we explicitly use a PARENT_POJOMATOR to compare child to parent, we'll miss the additional //child property. //TODO - document this a as a danger of creating your own Pojomators. assertTrue(PARENT_POJOMATOR.doEquals(child, PARENT)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-04-16 04:36:16
|
Revision: 212 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=212&view=rev Author: iroberts Date: 2010-04-16 04:36:09 +0000 (Fri, 16 Apr 2010) Log Message: ----------- More docs Modified Paths: -------------- trunk/PojomaticAll/PojomaticTestUtils/pom.xml Added Paths: ----------- trunk/PojomaticAll/PojomaticTestUtils/src/site/ trunk/PojomaticAll/PojomaticTestUtils/src/site/site.xml trunk/PojomaticAll/PojomaticTestUtils/src/site/xdoc/ trunk/PojomaticAll/PojomaticTestUtils/src/site/xdoc/changes.xml trunk/PojomaticAll/PojomaticTestUtils/src/site/xdoc/index.xml Modified: trunk/PojomaticAll/PojomaticTestUtils/pom.xml =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/pom.xml 2010-04-16 04:29:40 UTC (rev 211) +++ trunk/PojomaticAll/PojomaticTestUtils/pom.xml 2010-04-16 04:36:09 UTC (rev 212) @@ -11,7 +11,7 @@ <name>PojomaticTestUtils</name> <description> Utilities to help with writing tests for, or using, classes which use Pojomatic. - For example, this library includes classes with JUnit and TestNG style + This library includes classes with JUnit and TestNG style assertEquals methods which include differences (via Pojomatic.diff(Object, Object)) in the error message if the assertion fails. </description> Added: trunk/PojomaticAll/PojomaticTestUtils/src/site/site.xml =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/site/site.xml (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/src/site/site.xml 2010-04-16 04:36:09 UTC (rev 212) @@ -0,0 +1,10 @@ +<project> + <body> + <menu name="Overview"> + <item name="Introduction" href="index.html"/> + <item name="Javadocs" href="apidocs/index.html"/> + <item name="Changes" href="changes.html"/> + </menu> + <menu ref="reports"/> + </body> +</project> Property changes on: trunk/PojomaticAll/PojomaticTestUtils/src/site/site.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/PojomaticAll/PojomaticTestUtils/src/site/xdoc/changes.xml =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/site/xdoc/changes.xml (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/src/site/xdoc/changes.xml 2010-04-16 04:36:09 UTC (rev 212) @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<document xmlns="http://maven.apache.org/XDOC/2.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd"> + <properties> + <title>Changes in Pojomatic Test Utils</title> + </properties> + <body> + <section name="Changes in Pojomatic Test Utils"> + <subsection name="Version 1.0, released 2010-04-16"> + <ul> + <li> + Initial Release. + </li> + </ul> + </subsection> + </section> + </body> +</document> \ No newline at end of file Property changes on: trunk/PojomaticAll/PojomaticTestUtils/src/site/xdoc/changes.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/PojomaticAll/PojomaticTestUtils/src/site/xdoc/index.xml =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/site/xdoc/index.xml (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/src/site/xdoc/index.xml 2010-04-16 04:36:09 UTC (rev 212) @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<document xmlns="http://maven.apache.org/XDOC/2.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd"> + <properties> + <title>Pojomatic Test Utils</title> + </properties> + <head> + <style type="text/css"> + .ln { color: rgb(0,0,0); font-weight: normal; font-style: normal; } + .s0 { color: rgb(0,0,128); font-weight: bold; } + .s1 { } + </style> + </head> + <body> + <p> + Pojomatic Test Utils provides utilities to help with writing tests for, or using, classes which + use Pojomatic. This library includes classes with JUnit and TestNG style + assertEquals methods which include differences (via Pojomatic.diff(Object, Object)) + in the error message if the assertion fails. + </p> + + <p>For more information and examples, see the <a href="apidocs/index.html">JavaDocs</a>.</p> + </body> +</document> Property changes on: trunk/PojomaticAll/PojomaticTestUtils/src/site/xdoc/index.xml ___________________________________________________________________ Added: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-04-16 04:29:46
|
Revision: 211 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=211&view=rev Author: iroberts Date: 2010-04-16 04:29:40 +0000 (Fri, 16 Apr 2010) Log Message: ----------- Truth be told, there is more than one javadoc. Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/site/site.xml Modified: trunk/PojomaticAll/Pojomatic/src/site/site.xml =================================================================== --- trunk/PojomaticAll/Pojomatic/src/site/site.xml 2010-04-16 04:28:51 UTC (rev 210) +++ trunk/PojomaticAll/Pojomatic/src/site/site.xml 2010-04-16 04:29:40 UTC (rev 211) @@ -2,7 +2,7 @@ <body> <menu name="Overview"> <item name="Introduction" href="index.html"/> - <item name="Javadoc" href="apidocs/index.html"/> + <item name="Javadocs" href="apidocs/index.html"/> <item name="Changes" href="changes.html"/> <item name="Eclipse" href="eclipse.html"/> </menu> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-04-16 04:28:57
|
Revision: 210 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=210&view=rev Author: iroberts Date: 2010-04-16 04:28:51 +0000 (Fri, 16 Apr 2010) Log Message: ----------- Convert site over to xdoc format; add links where appropriate Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/site/site.xml trunk/PojomaticAll/Pojomatic/src/site/xdoc/index.xml Added Paths: ----------- trunk/PojomaticAll/Pojomatic/src/site/xdoc/changes.xml trunk/PojomaticAll/Pojomatic/src/site/xdoc/eclipse.xml Removed Paths: ------------- trunk/PojomaticAll/Pojomatic/src/site/apt/ Modified: trunk/PojomaticAll/Pojomatic/src/site/site.xml =================================================================== --- trunk/PojomaticAll/Pojomatic/src/site/site.xml 2010-04-16 00:40:12 UTC (rev 209) +++ trunk/PojomaticAll/Pojomatic/src/site/site.xml 2010-04-16 04:28:51 UTC (rev 210) @@ -2,6 +2,7 @@ <body> <menu name="Overview"> <item name="Introduction" href="index.html"/> + <item name="Javadoc" href="apidocs/index.html"/> <item name="Changes" href="changes.html"/> <item name="Eclipse" href="eclipse.html"/> </menu> Added: trunk/PojomaticAll/Pojomatic/src/site/xdoc/changes.xml =================================================================== --- trunk/PojomaticAll/Pojomatic/src/site/xdoc/changes.xml (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/site/xdoc/changes.xml 2010-04-16 04:28:51 UTC (rev 210) @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<document xmlns="http://maven.apache.org/XDOC/2.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd"> + <properties> + <title>Changes in Pojomatic</title> + </properties> + <body> + <section name="Changes in Pojomatic"> + <subsection name="Release 1.0-RC3 (2009-12-06)"> + <ul> + <li> + <code><a href="apidocs/org/pojomatic/Pojomatic.html#equals%28T,%20java.lang.Object%29">Pojomatic.equals()</a></code> + now properly handles inheritance, including comparing instances of two separate child + classes of a parent class + (<a class="externalLink" href="https://sourceforge.net/tracker/?func=detail&aid=2845939&group_id=239113&atid=1108645">bug 2845939</a>). + </li> + <li>A <code>Pojomator</code> can now be created for an interface.</li> + <li> + New annotations, + <code><a href="apidocs/index.html?org/pojomatic/annotations/OverridesEquals.html">OverridesEquals</a></code> + and + <code><a href="apidocs/index.html?org/pojomatic/annotations/SubclassCannotOverrideEquals.html">SubclassCannotOverrideEquals</a></code> + <code>SubclassCannotOverrideEquals</code> help control how inheritance is handled. + </li> + <li> + Properties from the parent class now come before those of the child in + <code>equals</code> calculations and in the <code>toString()</code> representation. + </li> + <li> + Pojomatic will no longer add a method property multiple times if it is overridden + (even if the overridden method is explicitely annotated). + </li> + <li> + <code><a href="apidocs/org/pojomatic/Pojomatic.html#diff%28T,%20S%29">Pojomatic.diff</a></code> + no longer requires a non-null first argument. + </li> + </ul> + </subsection> + <subsection name="Release 1.0-RC2 (2009-04-07)"> + <ul> + <li> + A new method, <code><a href="apidocs/org/pojomatic/Pojomatic.html#diff%28T,%20S%29">Pojomatic.diff</a></code>, + will show top-level differences between two instances of a pojomated class. + </li> + <li> + The property name derived from a method such as getFoo() is now "foo" instead + of "getFoo" in the default <code>toString()</code> representation. + </li> + <li> + Names of properties in the default <code>toString()</code> representation can be overridden + via the <code>name</code> attribute on the <code>Property</code> annotation. + </li> + <li> + Static fields and methods are no longer picked up by <code>@AutoProperty</code> + (<a class="externalLink" href="https://sourceforge.net/tracker/?func=detail&aid=2739467&group_id=239113&atid=1108645">bug 2739467</a>) + </li> + </ul> + </subsection> + <subsection name="Release 1.0-RC1 (2009-01-01)"> + <ul> + <li>Initial Release</li> + </ul> + </subsection> + </section> + </body> +</document> \ No newline at end of file Property changes on: trunk/PojomaticAll/Pojomatic/src/site/xdoc/changes.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/PojomaticAll/Pojomatic/src/site/xdoc/eclipse.xml =================================================================== --- trunk/PojomaticAll/Pojomatic/src/site/xdoc/eclipse.xml (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/site/xdoc/eclipse.xml 2010-04-16 04:28:51 UTC (rev 210) @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<document xmlns="http://maven.apache.org/XDOC/2.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd"> + <properties> + <title>Using with eclipse</title> + </properties> + <body> + <p> + Adding an eclipse template for pojomatic can make pojomating a class even easier. Open up the + Preferences dialog, and then go to Java->Editor->Templates. Then add a template named + "pojomatic" with the following body: + </p> + <source> +@Override public boolean equals(Object other) { return Pojomatic.equals(this, other); } +@Override public String toString() { return Pojomatic.toString(this); } +@Override public int hashCode() { return Pojomatic.hashCode(this); } +${:import(org.pojomatic.Pojomatic)} +</source> + <p> + After that, to pojomate a class, simply add an <code>@AutoProperty</code> annotation to the + class, and insert the macro in the class body by typing "pojomatic" and hitting Control-space. + </p> + </body> +</document> \ No newline at end of file Property changes on: trunk/PojomaticAll/Pojomatic/src/site/xdoc/eclipse.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/PojomaticAll/Pojomatic/src/site/xdoc/index.xml =================================================================== --- trunk/PojomaticAll/Pojomatic/src/site/xdoc/index.xml 2010-04-16 00:40:12 UTC (rev 209) +++ trunk/PojomaticAll/Pojomatic/src/site/xdoc/index.xml 2010-04-16 04:28:51 UTC (rev 210) @@ -1,4 +1,7 @@ -<document> +<?xml version="1.0" encoding="UTF-8"?> +<document xmlns="http://maven.apache.org/XDOC/2.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd"> <properties> <title>Pojomatic</title> </properties> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-04-16 00:40:18
|
Revision: 209 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=209&view=rev Author: iroberts Date: 2010-04-16 00:40:12 +0000 (Fri, 16 Apr 2010) Log Message: ----------- clear out some warnings Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/NoPojomaticPropertiesException.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/NoPojomaticPropertiesException.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/NoPojomaticPropertiesException.java 2010-04-13 05:20:34 UTC (rev 208) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/NoPojomaticPropertiesException.java 2010-04-16 00:40:12 UTC (rev 209) @@ -5,6 +5,8 @@ * annotated for use with Pojomatic. */ public class NoPojomaticPropertiesException extends IllegalArgumentException { + private static final long serialVersionUID = 1L; + public NoPojomaticPropertiesException(Class<?> pojoClass) { super("Class " + pojoClass.getName() + " has no Pojomatic properties"); } Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java 2010-04-13 05:20:34 UTC (rev 208) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java 2010-04-16 00:40:12 UTC (rev 209) @@ -1,7 +1,6 @@ package org.pojomatic; import org.pojomatic.diff.Differences; -import org.pojomatic.diff.NoDifferences; import org.pojomatic.internal.PojomatorImpl; import org.pojomatic.internal.SelfPopulatingMap; Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java 2010-04-13 05:20:34 UTC (rev 208) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java 2010-04-16 00:40:12 UTC (rev 209) @@ -61,9 +61,10 @@ @Test public void testCompatibleForEquality() { - class BeanSubClass extends Bean{}; + class BeanSubClass extends Bean{} class BeanWithExtraData extends Bean { + @SuppressWarnings("unused") @Property public int getY() { return 0; } } assertTrue(Pojomatic.areCompatibleForEquals(Bean.class, BeanSubClass.class)); Modified: trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java 2010-04-13 05:20:34 UTC (rev 208) +++ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java 2010-04-16 00:40:12 UTC (rev 209) @@ -2,7 +2,6 @@ import org.pojomatic.Pojomatic; import org.pojomatic.NoPojomaticPropertiesException; -import org.pojomatic.diff.Differences; /** * This class is not meant to be a part of the public API. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-04-13 05:20:40
|
Revision: 208 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=208&view=rev Author: iroberts Date: 2010-04-13 05:20:34 +0000 (Tue, 13 Apr 2010) Log Message: ----------- Add overview Added Paths: ----------- trunk/PojomaticAll/PojomaticTestUtils/src/main/javadoc/ trunk/PojomaticAll/PojomaticTestUtils/src/main/javadoc/overview.html Added: trunk/PojomaticAll/PojomaticTestUtils/src/main/javadoc/overview.html =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/main/javadoc/overview.html (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/src/main/javadoc/overview.html 2010-04-13 05:20:34 UTC (rev 208) @@ -0,0 +1,24 @@ +<!DOCTYPE HTML PUBLIC + "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> + <title>Overview</title> +</head> +<body> +<p> + Pojomatic Test Utils provide an enhancement to the traditional {@code assertEquals} method seen in + unit test libraries, in the form of a new method, {@code assertEqualsWithDiff}. This new method has + the same basic behavior as the original, with the added feature that if the two objects being + asserted to be equal are in fact not equal, but have types compatible for equality, then the + message of the thrown {@code AssertionError} will include the differences between the two objects + as determined by {@link Pojomatic#diff(Object, Object)}. +</p> +<p> + Because Junit and TestNG disagree as to the order of the expected and actual paramters to + {@code assertEquals}, two {@code PojomaticAssert} classes are provided: + {@link org.pojomatic.junit.PojomaticAssert} and {@link org.pojomatic.testng.PojomaticAssert}. +</p> +</body> +</html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-04-13 04:59:12
|
Revision: 207 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=207&view=rev Author: iroberts Date: 2010-04-13 04:59:06 +0000 (Tue, 13 Apr 2010) Log Message: ----------- more concise Modified Paths: -------------- trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java Modified: trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java 2010-04-13 04:58:03 UTC (rev 206) +++ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java 2010-04-13 04:59:06 UTC (rev 207) @@ -19,13 +19,7 @@ * @see Object#equals(Object) */ public static boolean equal(Object first, Object second) { - if (first == null && second == null) { - return true; - } - if (first != null && first.equals(second)) { - return true; - } - return false; + return first == null ? second == null : first.equals(second); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-04-13 04:58:09
|
Revision: 206 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=206&view=rev Author: iroberts Date: 2010-04-13 04:58:03 +0000 (Tue, 13 Apr 2010) Log Message: ----------- Javadoc Modified Paths: -------------- trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/junit/PojomaticAssert.java trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/testng/PojomaticAssert.java Modified: trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/junit/PojomaticAssert.java =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/junit/PojomaticAssert.java 2010-04-12 05:01:52 UTC (rev 205) +++ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/junit/PojomaticAssert.java 2010-04-13 04:58:03 UTC (rev 206) @@ -10,14 +10,14 @@ public class PojomaticAssert { /** - * Asserts that two possibly {@code null} objects are equal according to - * {@link Object#equals(Object)}. If not, the differences, - * via {@link Pojomatic#diff(Object, Object)}, are included in the failure message. + * Asserts that two objects are either both null or are equal according to + * {@link Object#equals(Object)}. If not, an {@code AssertionError} is thrown. If the objects are + * not equal, but the types of two objects are compatible for equality, then the differences as + * determined by {@link Pojomatic#diff(Object, Object)} are included in the failure message. * * @param expected the expected object * @param actual the object which should be tested to equal the expected object - * @throws AssertionError if the objects are not equal, with details of the differences - * included in the message + * @throws AssertionError if the objects are not equal. * @see #assertEqualsWithDiff(Object, Object, String) */ public static void assertEqualsWithDiff(Object expected, Object actual) { @@ -25,15 +25,16 @@ } /** - * Asserts that two possibly {@code null} objects are equal according to - * {@link Object#equals(Object)}. If not, the differences, - * via {@link Pojomatic#diff(Object, Object)}, are included in the failure message. + * Asserts that two objects are either both null or are equal according to + * {@link Object#equals(Object)}. If not, an {@code AssertionError} is thrown. If the objects are + * not equal, but the types of two objects are compatible for equality, then the differences as + * determined by {@link Pojomatic#diff(Object, Object)} are included in the failure message. * * @param expected the expected object * @param actual the object which should be tested to equal the expected object - * @param message the identifying message for the {@code AssertionError} ({@code null} okay) - * @throws AssertionError if the objects are not equal, with details of the differences - * included in the message + * @param message a message (possibly {@code null) to include at the begining of the + * {@code AssertionError} message. + * @throws AssertionError if the objects are not equal. */ public static void assertEqualsWithDiff(Object expected, Object actual, String message) { AssertUtils.assertEquals(message, expected, actual); Modified: trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java 2010-04-12 05:01:52 UTC (rev 205) +++ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java 2010-04-13 04:58:03 UTC (rev 206) @@ -10,7 +10,8 @@ public class AssertUtils { /** - * Determines if two possibly {@code null} objects are equal. + * Determines if two objects are both null or are equal according to + * {@link Object#equals(Object)}. * * @return {@code true} if both objects are null, * or {@code first} is non-null and {@code first.equals(second)}, @@ -28,7 +29,10 @@ } /** - * Asserts that the objects are equal via {@link #equal(Object, Object)}. + * Asserts that two objects are either both null or are equal according to + * {@link Object#equals(Object)}. If not, an {@code AssertionError} is thrown. If the objects are + * not equal, but the types of two objects are compatible for equality, then the differences as + * determined by {@link Pojomatic#diff(Object, Object)} are included in the failure message. * * @param message the message to add if the assertion fails * @param expected will be displayed first if the assertion fails Modified: trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/testng/PojomaticAssert.java =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/testng/PojomaticAssert.java 2010-04-12 05:01:52 UTC (rev 205) +++ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/testng/PojomaticAssert.java 2010-04-13 04:58:03 UTC (rev 206) @@ -10,9 +10,10 @@ public class PojomaticAssert { /** - * Asserts that two possibly {@code null} objects are equal according to - * {@link Object#equals(Object)}. If not, the differences, - * via {@link Pojomatic#diff(Object, Object)}, are included in the failure message. + * Asserts that two objects are either both null or are equal according to + * {@link Object#equals(Object)}. If not, an {@code AssertionError} is thrown. If the objects are + * not equal, but the types of two objects are compatible for equality, then the differences as + * determined by {@link Pojomatic#diff(Object, Object)} are included in the failure message. * * @param expected the expected object * @param actual the object which should be tested to equal the expected object @@ -25,9 +26,10 @@ } /** - * Asserts that two possibly {@code null} objects are equal according to - * {@link Object#equals(Object)}. If not, the differences, - * via {@link Pojomatic#diff(Object, Object)}, are included in the failure message. + * Asserts that two objects are either both null or are equal according to + * {@link Object#equals(Object)}. If not, an {@code AssertionError} is thrown. If the objects are + * not equal, but the types of two objects are compatible for equality, then the differences as + * determined by {@link Pojomatic#diff(Object, Object)} are included in the failure message. * * @param expected the expected object * @param actual the object which should be tested to equal the expected object This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-04-12 05:01:58
|
Revision: 205 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=205&view=rev Author: iroberts Date: 2010-04-12 05:01:52 +0000 (Mon, 12 Apr 2010) Log Message: ----------- package info for all packages Added Paths: ----------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/package-info.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/package-info.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/formatter/package-info.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/package-info.java Added: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/package-info.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/package-info.java (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/annotations/package-info.java 2010-04-12 05:01:52 UTC (rev 205) @@ -0,0 +1,4 @@ +/** + * Annotations and enums to control the behavior of Pojomatic. + */ +package org.pojomatic.annotations; Added: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/package-info.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/package-info.java (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/package-info.java 2010-04-12 05:01:52 UTC (rev 205) @@ -0,0 +1,4 @@ +/** + * API and implementation classes to support {@link org.pojomatic.Pojomatic#diff(Object, Object) Pojomatic.diff} + */ +package org.pojomatic.diff; Added: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/formatter/package-info.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/formatter/package-info.java (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/formatter/package-info.java 2010-04-12 05:01:52 UTC (rev 205) @@ -0,0 +1,5 @@ +/** + * API and classes to help control the format used by + * {@link org.pojomatic.Pojomatic#toString(Object)} Pojomatic.toString} + */ +package org.pojomatic.formatter; Added: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/package-info.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/package-info.java (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/package-info.java 2010-04-12 05:01:52 UTC (rev 205) @@ -0,0 +1,4 @@ +/** + * Core Pojomatic classes. + */ +package org.pojomatic; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-04-12 05:01:29
|
Revision: 204 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=204&view=rev Author: iroberts Date: 2010-04-12 05:01:23 +0000 (Mon, 12 Apr 2010) Log Message: ----------- Give more reason to visit the javadocs Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/site/xdoc/index.xml Modified: trunk/PojomaticAll/Pojomatic/src/site/xdoc/index.xml =================================================================== --- trunk/PojomaticAll/Pojomatic/src/site/xdoc/index.xml 2010-04-12 04:42:17 UTC (rev 203) +++ trunk/PojomaticAll/Pojomatic/src/site/xdoc/index.xml 2010-04-12 05:01:23 UTC (rev 204) @@ -57,6 +57,6 @@ will result in the following output: <source>Person{firstName: {John}, lastName: {Doe}, age: {32}}</source> -<p>For more information, see the <a href="apidocs/index.html">JavaDocs</a>.</p> +<p>For more information and examples, see the <a href="apidocs/index.html">JavaDocs</a>.</p> </body> </document> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-04-12 04:42:23
|
Revision: 203 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=203&view=rev Author: iroberts Date: 2010-04-12 04:42:17 +0000 (Mon, 12 Apr 2010) Log Message: ----------- switch to doxia to support syntax highlighting of code Added Paths: ----------- trunk/PojomaticAll/Pojomatic/src/site/xdoc/ trunk/PojomaticAll/Pojomatic/src/site/xdoc/index.xml Removed Paths: ------------- trunk/PojomaticAll/Pojomatic/src/site/apt/index.apt Deleted: trunk/PojomaticAll/Pojomatic/src/site/apt/index.apt =================================================================== --- trunk/PojomaticAll/Pojomatic/src/site/apt/index.apt 2010-04-12 04:41:17 UTC (rev 202) +++ trunk/PojomaticAll/Pojomatic/src/site/apt/index.apt 2010-04-12 04:42:17 UTC (rev 203) @@ -1,60 +0,0 @@ - ------ - Pojomatic - ------ - ------ - ------ - - - Pojomatic provides configurable implementations of the <<<equals(Object)>>>, <<<toString()>>> - and <<<hashCode()>>> methods inherited from <<<java.lang.Object>>>. - - For example, the following bean has been "pojomated": - ------------------------- -import org.pojomatic.Pojomatic; -import org.pojomatic.annotations.AutoProperty; - -@AutoProperty -public class Person { - private final String firstName; - private final String lastName; - private final int age; - - public Person(String firstName, String lastName, int age) { - this.firstName = firstName; - this.lastName = lastName; - this.age = age; - } - - public String getFirstName() { return this.firstName; } - public String getLastName() { return this.lastName; } - public int getAge() { return this.age; } - - @Override public boolean equals(Object o) { - return Pojomatic.equals(this, o); - } - - @Override public int hashCode() { - return Pojomatic.hashCode(this); - } - - @Override public String toString() { - return Pojomatic.toString(this); - } -} ------------------------- - - The above class implements <<<equals>>> and <<<hashCode>>> methods following the best practices - outlined in Josh Bloch's <Efective Java>. Moreover, running - ---- - System.out.println(new Person("John", "Doe", 32).toString()); ---- - - will result in the following output: - --------- -Person{firstName: {John}, lastName: {Doe}, age: {32}} --------- - - For more information, see the {{{apidocs/index.html}JavaDocs}}. Added: trunk/PojomaticAll/Pojomatic/src/site/xdoc/index.xml =================================================================== --- trunk/PojomaticAll/Pojomatic/src/site/xdoc/index.xml (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/site/xdoc/index.xml 2010-04-12 04:42:17 UTC (rev 203) @@ -0,0 +1,62 @@ +<document> + <properties> + <title>Pojomatic</title> + </properties> + <head> + <style type="text/css"> + .ln { color: rgb(0,0,0); font-weight: normal; font-style: normal; } + .s0 { color: rgb(0,0,128); font-weight: bold; } + .s1 { } + </style> + </head> + <body> +<p> +Pojomatic provides configurable implementations of the <code>equals(Object)</code>, <code>toString()</code> +and <code>hashCode()</code> methods inherited from <code>java.lang.Object</code>. +</p> +<p>For example, the following bean has been "pojomated":</p> +<div class="source"><pre> +<span class="s0">import </span><span class="s1">org.pojomatic.Pojomatic; +</span><span class="s0">import </span><span class="s1">org.pojomatic.annotations.AutoProperty; + +@AutoProperty +</span><span class="s0">public class </span><span class="s1">Person { + </span><span class="s0">private final </span><span class="s1">String firstName; + </span><span class="s0">private final </span><span class="s1">String lastName; + </span><span class="s0">private final int </span><span class="s1">age; + + </span><span class="s0">public </span><span class="s1">Person(String firstName, String lastName, </span><span class="s0">int </span><span class="s1">age) { + </span><span class="s0">this</span><span class="s1">.firstName = firstName; + </span><span class="s0">this</span><span class="s1">.lastName = lastName; + </span><span class="s0">this</span><span class="s1">.age = age; + } + + </span><span class="s0">public </span><span class="s1">String getFirstName() { return this</span><span class="s1">.firstName; } + </span><span class="s0">public </span><span class="s1">String getLastName() { return this</span><span class="s1">.lastName; } + </span><span class="s0">public int </span><span class="s1">getAge() { return this</span><span class="s1">.age; } + + @Override </span><span class="s0">public int </span><span class="s1">hashCode() { + </span><span class="s0">return </span><span class="s1">Pojomatic.hashCode(</span><span class="s0">this</span><span class="s1">); + } + + @Override </span><span class="s0">public </span><span class="s1">String toString() { + </span><span class="s0">return </span><span class="s1">Pojomatic.toString(</span><span class="s0">this</span><span class="s1">); + } + + @Override </span><span class="s0">public boolean </span><span class="s1">equals(Object o) { + </span><span class="s0">return </span><span class="s1">Pojomatic.equals(</span><span class="s0">this</span><span class="s1">, o); + } +} +</span></pre></div> +<p> + The above class implements <code>equals</code> and <code>hashCode</code> methods following the best practices + outlined in Josh Bloch's <em>Efective Java</em>. Moreover, running +</p> + +<source>System.out.println(new Person("John", "Doe", 32).toString());</source> +will result in the following output: +<source>Person{firstName: {John}, lastName: {Doe}, age: {32}}</source> + +<p>For more information, see the <a href="apidocs/index.html">JavaDocs</a>.</p> + </body> +</document> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-04-12 04:41:23
|
Revision: 202 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=202&view=rev Author: iroberts Date: 2010-04-12 04:41:17 +0000 (Mon, 12 Apr 2010) Log Message: ----------- Make accessors inline to save space Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/test/java/examples/Person.java Modified: trunk/PojomaticAll/Pojomatic/src/test/java/examples/Person.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/examples/Person.java 2010-04-12 04:23:21 UTC (rev 201) +++ trunk/PojomaticAll/Pojomatic/src/test/java/examples/Person.java 2010-04-12 04:41:17 UTC (rev 202) @@ -15,18 +15,10 @@ this.age = age; } - public String getFirstName() { - return this.firstName; - } + public String getLastName() { return this.lastName; } + public String getFirstName() { return this.firstName; } + public int getAge() { return this.age; } - public String getLastName() { - return this.lastName; - } - - public int getAge() { - return this.age; - } - @Override public int hashCode() { return Pojomatic.hashCode(this); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-04-12 04:23:27
|
Revision: 201 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=201&view=rev Author: iroberts Date: 2010-04-12 04:23:21 +0000 (Mon, 12 Apr 2010) Log Message: ----------- Fix bad tag Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java 2010-04-12 04:21:19 UTC (rev 200) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java 2010-04-12 04:23:21 UTC (rev 201) @@ -146,7 +146,7 @@ * @param other the instance to diff * @return the list of differences (possibly empty) between {@code instance} and {@code other} * among the properties examined by {@link #equals(Object, Object)} for type {@code T}. - * @throws NullPointerException if {@code pojo} or {@other} are null + * @throws NullPointerException if {@code pojo} or {@code other} are null * (this behavior may change in future releases). * @throws NoPojomaticPropertiesException if {@code pojo}'s class has no properties * annotated for use with Pojomatic, or if the types of {@code pojo} and {@code other} are not This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-04-12 04:21:25
|
Revision: 200 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=200&view=rev Author: iroberts Date: 2010-04-12 04:21:19 +0000 (Mon, 12 Apr 2010) Log Message: ----------- Get rid of obsolete @see references Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java 2010-04-04 04:55:19 UTC (rev 199) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java 2010-04-12 04:21:19 UTC (rev 200) @@ -19,7 +19,6 @@ * * @return the value from the left instance (possibly {@code null}) * @throws NoSuchElementException if the value does not exist on the left instance - * @see #existsOnLeft() */ Object leftValue() throws NoSuchElementException; @@ -28,7 +27,6 @@ * * @return the value from the right instance (possibly {@code null}) * @throws NoSuchElementException if the value does not exist on the right instance - * @see #existsOnRight() */ Object rightValue() throws NoSuchElementException; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-04-04 04:55:26
|
Revision: 199 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=199&view=rev Author: iroberts Date: 2010-04-04 04:55:19 +0000 (Sun, 04 Apr 2010) Log Message: ----------- *) Pojomatic.doDiff will throw an NPE if either argument is null. Hence Differences has no need to handle the case of one side or the other (or both) being null. *) Pojomatic.doDiff will also throw an exception if asked to compare instances of two classes which are not comparable for equals. *) The work of handling these cases now falls on pojomatic-test-utils. *) assertPojoEquals generated messages are more like those generated by junit. *) assertPojoEquals will show the full expected and actual in addition to the differences. Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/ValueDifference.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/ValueDifferenceTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/junit/PojomaticAssertTest.java trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertTest.java trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/OnlyPojomaticEqual.java trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/testng/PojomaticAssertTest.java Added Paths: ----------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/NoPojomaticPropertiesException.java trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/DifferentPojo.java Removed Paths: ------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/AbstractNullDifference.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceFromNull.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceToNull.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnLeft.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnRight.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceFromNullTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceToNullTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnLeftTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnRightTest.java Added: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/NoPojomaticPropertiesException.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/NoPojomaticPropertiesException.java (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/NoPojomaticPropertiesException.java 2010-04-04 04:55:19 UTC (rev 199) @@ -0,0 +1,11 @@ +package org.pojomatic; + +/** + * An exception thrown when asked to create a {@link Pojomator} for a class which has no properties + * annotated for use with Pojomatic. + */ +public class NoPojomaticPropertiesException extends IllegalArgumentException { + public NoPojomaticPropertiesException(Class<?> pojoClass) { + super("Class " + pojoClass.getName() + " has no Pojomatic properties"); + } +} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java 2010-04-04 04:55:19 UTC (rev 199) @@ -87,11 +87,11 @@ * @param <T> the type of the POJO * @param pojo the POJO - must not be null * @return the {@code toString} representation of {@code pojo}. - * @throws IllegalArgumentException if {@code pojo}'s class has no properties annotated for use - * with Pojomatic + * @throws NoPojomaticPropertiesException if {@code pojo}'s class has no properties annotated for + * use with Pojomatic * @see Pojomator#doToString(Object) */ - public static <T> String toString(T pojo) throws IllegalArgumentException { + public static <T> String toString(T pojo) throws NoPojomaticPropertiesException { return pojomator(getClass(pojo)).doToString(pojo); } @@ -100,11 +100,11 @@ * @param <T> the type of the POJO * @param pojo the POJO - must not be null * @return the {@code hashCode} for {@code pojo}. - * @throws IllegalArgumentException if {@code pojo}'s class has no properties annotated for use - * with Pojomatic + * @throws NoPojomaticPropertiesException if {@code pojo}'s class has no properties annotated for + * use with Pojomatic * @see Pojomator#doHashCode(Object) */ - public static <T> int hashCode(T pojo) throws IllegalArgumentException { + public static <T> int hashCode(T pojo) throws NoPojomaticPropertiesException { return pojomator(getClass(pojo)).doHashCode(pojo); } @@ -116,11 +116,11 @@ * @param other the object to compare to for equality * @return whether {@code pojo} and {@code other} are equal to each other in the sense of * {@code Object}'s {@code equals} method. - * @throws IllegalArgumentException if {@code pojo}'s class has no properties annotated for use - * with Pojomatic + * @throws NoPojomaticPropertiesException if {@code pojo}'s class has no properties annotated for + * use with Pojomatic * @see Pojomator#doEquals(Object, Object) */ - public static <T> boolean equals(T pojo, Object other) throws IllegalArgumentException { + public static <T> boolean equals(T pojo, Object other) throws NoPojomaticPropertiesException { return pojomator(getClass(pojo)).doEquals(pojo, other); } @@ -146,20 +146,20 @@ * @param other the instance to diff * @return the list of differences (possibly empty) between {@code instance} and {@code other} * among the properties examined by {@link #equals(Object, Object)} for type {@code T}. - * @throws IllegalArgumentException if {@code pojo}'s class has no properties annotated for use - * with Pojomatic + * @throws NullPointerException if {@code pojo} or {@other} are null + * (this behavior may change in future releases). + * @throws NoPojomaticPropertiesException if {@code pojo}'s class has no properties + * annotated for use with Pojomatic, or if the types of {@code pojo} and {@code other} are not + * compatible for equality with each other (this behavior may change in future releases). */ public static <T, S extends T> Differences diff(T pojo, S other) - throws NullPointerException, IllegalArgumentException { + throws NullPointerException, NoPojomaticPropertiesException { if (pojo == null) { - if (other != null) { - return pojomator(getClass(other)).doDiff(null, other); - } - else { //both null - return NoDifferences.getInstance(); - } + throw new NullPointerException("pojo is null"); } - + if (other == null) { + throw new NullPointerException("other is null"); + } return pojomator(getClass(pojo)).doDiff(pojo, other); } @@ -169,11 +169,12 @@ * @param <T> the type represented by {@code pojoClass} * @param pojoClass the class to create a {@code Pojomator} for. * @return a {@code Pojomator<T>} - * @throws IllegalArgumentException if {@code pojoClass} has no properties annotated for use + * @throws NoPojomaticPropertiesException if {@code pojoClass} has no properties annotated for use * with Pojomatic */ @SuppressWarnings("unchecked") // compiler does not know that the type parameter to Pojomator is T - public static <T> Pojomator<T> pojomator(Class<T> pojoClass) throws IllegalArgumentException { + public static <T> Pojomator<T> pojomator(Class<T> pojoClass) + throws NoPojomaticPropertiesException { return (Pojomator<T>) POJOMATORS.get(pojoClass); } Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java 2010-04-04 04:55:19 UTC (rev 199) @@ -142,7 +142,11 @@ * @param other the instance to diff * @return the differences between {@code instance} and {@code other} * among the properties examined by {@link #doEquals(Object, Object)}. - * + * @throws NullPointerException if {@code instance} or {@code other} is null + * (this behavoir may change in future releases). + * @throws IllegalArgumentException the type of {@code instance} or of {@code other} is not a + * class which is compatible for equality with {@code T} + * (this behavoir may change in future releases). * @see #doEquals(Object, Object) */ Differences doDiff(T instance, T other); Deleted: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/AbstractNullDifference.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/AbstractNullDifference.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/AbstractNullDifference.java 2010-04-04 04:55:19 UTC (rev 199) @@ -1,46 +0,0 @@ -package org.pojomatic.diff; - -import org.pojomatic.Pojomatic; -import org.pojomatic.annotations.AutoProperty; -import org.pojomatic.annotations.DefaultPojomaticPolicy; -import org.pojomatic.annotations.PojomaticPolicy; -import org.pojomatic.annotations.Property; - -/** - * A {@link Differences} whose {@link Differences#toString()} is generated exactly once. - */ -@AutoProperty(policy=DefaultPojomaticPolicy.NONE) -abstract class AbstractNullDifference implements Differences { - @Property(policy=PojomaticPolicy.ALL) - protected final Object instance; - - /** - * @param instance the non-null object being compared to {@code null}. - * @throws NullPointerException if {@code instance} is {@code null}. - */ - public AbstractNullDifference(Object instance) { - if (instance == null) { - throw new NullPointerException("Instance cannot be null"); - } - - this.instance = instance; - } - - public final boolean areEqual() { - return false; - } - - @Override - public abstract String toString(); - - @Override - public int hashCode() { - return Pojomatic.hashCode(this); - } - - @Override - public boolean equals(Object o) { - return Pojomatic.equals(this, o); - } - -} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java 2010-04-04 04:55:19 UTC (rev 199) @@ -15,20 +15,6 @@ String propertyName(); /** - * Whether or not the property exists on the left object. - * - * @return {@code true} if the property exists on the left object, {@code false} otherwise - */ - boolean existsOnLeft(); - - /** - * Whether or not the property exists on the right object. - * - * @return {@code true} if the property exists on the right object, {@code false} otherwise - */ - boolean existsOnRight(); - - /** * The value from the left instance (possibly {@code null}). * * @return the value from the left instance (possibly {@code null}) Deleted: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceFromNull.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceFromNull.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceFromNull.java 2010-04-04 04:55:19 UTC (rev 199) @@ -1,27 +0,0 @@ -package org.pojomatic.diff; - -/** - * The result of comparing {@code null} to a non-null object. - * @see DifferenceToNull - */ -public final class DifferenceFromNull extends AbstractNullDifference { - private final Iterable<OnlyOnRight> differences; - - public DifferenceFromNull(Object other, Iterable<OnlyOnRight> differences) { - super(other); - if (differences == null) { - throw new NullPointerException("Differences cannot be null"); - } - this.differences = differences; - } - - @Override - public String toString() { - return "null is different than the object {" + instance + "}"; - } - - public Iterable<? extends Difference> differences() { - return differences; - } - -} Deleted: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceToNull.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceToNull.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceToNull.java 2010-04-04 04:55:19 UTC (rev 199) @@ -1,26 +0,0 @@ -package org.pojomatic.diff; - -/** - * The result of comparing a non-null object to {@code null}. - * @see DifferenceFromNull - */ -public final class DifferenceToNull extends AbstractNullDifference { - private final Iterable<OnlyOnLeft> differences; - - public DifferenceToNull(Object instance, Iterable<OnlyOnLeft> differences) { - super(instance); - if (differences == null) { - throw new NullPointerException("Differences cannot be null"); - } - this.differences = differences; - } - - @Override - public String toString() { - return "the object {" + instance + "} is different than null"; - } - - public Iterable<? extends Difference> differences() { - return differences; - } -} Deleted: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnLeft.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnLeft.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnLeft.java 2010-04-04 04:55:19 UTC (rev 199) @@ -1,62 +0,0 @@ -package org.pojomatic.diff; - -import java.util.NoSuchElementException; - -import org.pojomatic.Pojomatic; -import org.pojomatic.annotations.Property; - -/** - * A {@link Difference} which only has a value on the left. - */ -public final class OnlyOnLeft implements Difference { - - private final String propertyName; - - private final Object leftValue; - - public OnlyOnLeft(String propertyName, Object leftValue) { - if (propertyName == null) { - throw new NullPointerException("Property name cannot be null"); - } - this.propertyName = propertyName; - this.leftValue = leftValue; - } - - @Property - public String propertyName() { - return propertyName; - } - - @Property - public Object leftValue() { - return leftValue; - } - - public boolean existsOnLeft() { - return true; - } - - public boolean existsOnRight() { - return false; - } - - public Object rightValue() throws NoSuchElementException { - throw new NoSuchElementException("Value only exists on the left"); - } - - @Override - public int hashCode() { - return Pojomatic.hashCode(this); - } - - @Override - public String toString() { - return Pojomatic.toString(this); - } - - @Override - public boolean equals(Object o) { - return Pojomatic.equals(this, o); - } - -} Deleted: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnRight.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnRight.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnRight.java 2010-04-04 04:55:19 UTC (rev 199) @@ -1,62 +0,0 @@ -package org.pojomatic.diff; - -import java.util.NoSuchElementException; - -import org.pojomatic.Pojomatic; -import org.pojomatic.annotations.Property; - -/** - * A {@link Difference} which only has a value on the right. - */ -public final class OnlyOnRight implements Difference { - - private final String propertyName; - - private final Object rightValue; - - public OnlyOnRight(String propertyName, Object rightValue) { - if (propertyName == null) { - throw new NullPointerException("Property name cannot be null"); - } - this.propertyName = propertyName; - this.rightValue = rightValue; - } - - @Property - public String propertyName() { - return propertyName; - } - - public Object leftValue() { - throw new NoSuchElementException("Value only exists on the right"); - } - - public boolean existsOnLeft() { - return false; - } - - public boolean existsOnRight() { - return true; - } - - @Property - public Object rightValue() throws NoSuchElementException { - return rightValue; - } - - @Override - public int hashCode() { - return Pojomatic.hashCode(this); - } - - @Override - public String toString() { - return Pojomatic.toString(this); - } - - @Override - public boolean equals(Object o) { - return Pojomatic.equals(this, o); - } - -} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/ValueDifference.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/ValueDifference.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/ValueDifference.java 2010-04-04 04:55:19 UTC (rev 199) @@ -29,14 +29,6 @@ return rightValue; } - public boolean existsOnLeft() { - return true; - } - - public boolean existsOnRight() { - return true; - } - @Override public boolean equals(Object obj) { return Pojomatic.equals(this, obj); Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/ClassProperties.java 2010-04-04 04:55:19 UTC (rev 199) @@ -11,6 +11,7 @@ import java.util.regex.Pattern; import org.pojomatic.PropertyElement; +import org.pojomatic.NoPojomaticPropertiesException; import org.pojomatic.annotations.*; /** @@ -50,10 +51,10 @@ * repeatedly is not inefficient. * @param pojoClass the class to inspect for properties * @return The {@code ClassProperties} for {@code pojoClass}. - * @throws IllegalArgumentException if {@code pojoClass} has no properties annotated for use + * @throws NoPojomaticPropertiesException if {@code pojoClass} has no properties annotated for use * with Pojomatic. */ - public static ClassProperties forClass(Class<?> pojoClass) throws IllegalArgumentException { + public static ClassProperties forClass(Class<?> pojoClass) throws NoPojomaticPropertiesException { return INSTANCES.get(pojoClass); } @@ -61,10 +62,10 @@ * Creates an instance for the given {@code pojoClass}. * * @param pojoClass the class to inspect for properties - * @throws IllegalArgumentException if {@code pojoClass} has no properties annotated for use + * @throws NoPojomaticPropertiesException if {@code pojoClass} has no properties annotated for use * with Pojomatic. */ - private ClassProperties(Class<?> pojoClass) throws IllegalArgumentException { + private ClassProperties(Class<?> pojoClass) throws NoPojomaticPropertiesException { if (pojoClass.isInterface()) { extractClassProperties(pojoClass, new OverridableMethods(), new ClassContributionTracker()); equalsParentClass = pojoClass; @@ -237,8 +238,7 @@ return; } } - throw new IllegalArgumentException( - "Class " + pojoClass.getName() + " has no Pojomatic properties"); + throw new NoPojomaticPropertiesException(pojoClass); } private String getPropertyName(Property property) { Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2010-04-04 04:55:19 UTC (rev 199) @@ -8,15 +8,12 @@ import org.pojomatic.Pojomator; import org.pojomatic.PropertyElement; +import org.pojomatic.NoPojomaticPropertiesException; import org.pojomatic.annotations.PojoFormat; import org.pojomatic.annotations.PropertyFormat; import org.pojomatic.diff.Difference; -import org.pojomatic.diff.DifferenceFromNull; -import org.pojomatic.diff.DifferenceToNull; import org.pojomatic.diff.Differences; import org.pojomatic.diff.NoDifferences; -import org.pojomatic.diff.OnlyOnLeft; -import org.pojomatic.diff.OnlyOnRight; import org.pojomatic.diff.PropertyDifferences; import org.pojomatic.diff.ValueDifference; import org.pojomatic.formatter.DefaultPojoFormatter; @@ -35,10 +32,10 @@ * Creates an instance for {@code clazz}. * * @param clazz the class - * @throws IllegalArgumentException if {@code clazz} has no properties annotated for use + * @throws NoPojomaticPropertiesException if {@code clazz} has no properties annotated for use * with Pojomatic */ - public PojomatorImpl(Class<T> clazz) throws IllegalArgumentException { + public PojomatorImpl(Class<T> clazz) throws NoPojomaticPropertiesException { this.clazz = clazz; classProperties = ClassProperties.forClass(clazz); pojoFormatterClass = findPojoFormatterClass(clazz); @@ -231,17 +228,15 @@ public Differences doDiff(T instance, T other) { final Collection<PropertyElement> diffProperties = classProperties.getEqualsProperties(); + if (instance == null) { + throw new NullPointerException("instance is null"); + } + if (other == null) { + throw new NullPointerException("other is null"); + } if (instance == other) { return NoDifferences.getInstance(); } - else if (instance == null) { - checkClass(other, "other"); - return new DifferenceFromNull(other, onlyOnRight(other, diffProperties)); - } - else if (other == null) { - checkClass(instance, "instance"); - return new DifferenceToNull(instance, onlyOnLeft(instance, diffProperties)); - } checkClass(instance, "instance"); checkClass(other, "other"); @@ -260,28 +255,11 @@ return new PropertyDifferences(differences); } - private Iterable<OnlyOnLeft> onlyOnLeft(T instance, Collection<PropertyElement> diffProperties) { - List<OnlyOnLeft> result = new ArrayList<OnlyOnLeft>(); - for (PropertyElement element : diffProperties) { - result.add(new OnlyOnLeft(element.getName(), element.getValue(instance))); - } - return result; - } - - private Iterable<OnlyOnRight> onlyOnRight(Object value, - Collection<PropertyElement> diffProperties) { - List<OnlyOnRight> result = new ArrayList<OnlyOnRight>(); - for (PropertyElement element : diffProperties) { - result.add(new OnlyOnRight(element.getName(), element.getValue(value))); - } - return result; - } - private void checkClass(T instance, String label) { - if (!clazz.isInstance(instance)) { - throw new ClassCastException( + if (!isCompatibleForEquality(instance.getClass())) { + throw new IllegalArgumentException( label + " has type " + instance.getClass().getName() - + " which is not a subtype of " + clazz.getName()); + + " which is not compatible for equality with " + clazz.getName()); } } Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java 2010-04-04 04:55:19 UTC (rev 199) @@ -4,16 +4,9 @@ import org.junit.Test; import org.pojomatic.annotations.Property; -import org.pojomatic.diff.DifferenceFromNull; -import org.pojomatic.diff.DifferenceToNull; -import org.pojomatic.diff.Differences; import org.pojomatic.diff.NoDifferences; -import org.pojomatic.diff.OnlyOnLeft; -import org.pojomatic.diff.OnlyOnRight; import org.pojomatic.internal.PojomatorImpl; -import com.google.common.collect.Sets; - public class PojomaticTest { public static class Bean { @Property public final int x; @@ -40,25 +33,19 @@ assertEquals(NoDifferences.getInstance(), Pojomatic.diff(BEAN, BEAN)); } - @Test + @Test(expected=NullPointerException.class) public void testDiffBothNull() { - assertEquals(NoDifferences.getInstance(), Pojomatic.diff(null, null)); + Pojomatic.diff(null, null); } - @Test + @Test(expected=NullPointerException.class) public void testDiffNullFirst() { - Iterable<OnlyOnRight> beanDifferences = Sets.newHashSet(new OnlyOnRight("x", BEAN.x)); - Differences differences = Pojomatic.diff(null, BEAN); - assertEquals(new DifferenceFromNull(BEAN, beanDifferences), differences); - assertEquals(beanDifferences, Sets.newHashSet(differences.differences())); + Pojomatic.diff(null, BEAN); } - @Test + @Test(expected=NullPointerException.class) public void testDiffNullSecond() { - Iterable<OnlyOnLeft> beanDifferences = Sets.newHashSet(new OnlyOnLeft("x", BEAN.x)); - Differences differences = Pojomatic.diff(BEAN, null); - assertEquals(new DifferenceToNull(BEAN, beanDifferences), differences); - assertEquals(beanDifferences, Sets.newHashSet(differences.differences())); + Pojomatic.diff(BEAN, null); } @Test Deleted: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceFromNullTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceFromNullTest.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceFromNullTest.java 2010-04-04 04:55:19 UTC (rev 199) @@ -1,33 +0,0 @@ -package org.pojomatic.diff; - -import static org.junit.Assert.*; - -import java.util.Collections; - -import org.junit.Test; - -public class DifferenceFromNullTest { - private static final Iterable<OnlyOnRight> EMPTY_DIFFERENCES = - Collections.<OnlyOnRight>emptyList(); - - @Test(expected = NullPointerException.class) - public void testNullValue() { - new DifferenceFromNull(null, EMPTY_DIFFERENCES); - } - - @Test(expected = NullPointerException.class) - public void testNullDifferences() { - new DifferenceFromNull(new Object(), null); - } - - @Test - public void testToString() { - DifferenceFromNull difference = new DifferenceFromNull(3, EMPTY_DIFFERENCES); - assertEquals("null is different than the object {3}", difference.toString()); - } - - @Test - public void testAreEqual() { - assertFalse(new DifferenceFromNull(3, EMPTY_DIFFERENCES).areEqual()); - } -} Deleted: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceToNullTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceToNullTest.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceToNullTest.java 2010-04-04 04:55:19 UTC (rev 199) @@ -1,32 +0,0 @@ -package org.pojomatic.diff; - -import static org.junit.Assert.*; - -import java.util.Collections; - -import org.junit.Test; - -public class DifferenceToNullTest { - private static final Iterable<OnlyOnLeft> EMPTY_DIFFERENCES = Collections.<OnlyOnLeft>emptyList(); - - @Test(expected = NullPointerException.class) - public void testNullValue() { - new DifferenceToNull(null, EMPTY_DIFFERENCES); - } - - @Test(expected = NullPointerException.class) - public void testNullDifferences() { - new DifferenceToNull(new Object(), null); - } - - @Test - public void testToString() { - DifferenceToNull differences = new DifferenceToNull(3, EMPTY_DIFFERENCES); - assertEquals("the object {3} is different than null", differences.toString()); - } - - @Test - public void testAreEqual() { - assertFalse(new DifferenceToNull(3, EMPTY_DIFFERENCES).areEqual()); - } -} Deleted: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnLeftTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnLeftTest.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnLeftTest.java 2010-04-04 04:55:19 UTC (rev 199) @@ -1,42 +0,0 @@ -package org.pojomatic.diff; - -import static org.junit.Assert.*; - -import java.util.NoSuchElementException; - -import org.junit.Test; - -public class OnlyOnLeftTest { - private static final OnlyOnLeft INSTANCE = new OnlyOnLeft("name", "value"); - - @Test(expected = NullPointerException.class) - public void testNullPropertyName() { - new OnlyOnLeft(null, new Object()); - } - - @Test - public void testPropertyName() { - assertEquals("name", INSTANCE.propertyName()); - } - - @Test - public void testLeftValue() { - assertEquals("value", INSTANCE.leftValue()); - } - - @Test - public void testExistsOnLeft() { - assertTrue(INSTANCE.existsOnLeft()); - } - - @Test - public void testExistsOnRight() { - assertFalse(INSTANCE.existsOnRight()); - } - - @Test(expected = NoSuchElementException.class) - public void testRightValue() { - INSTANCE.rightValue(); - } - -} Deleted: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnRightTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnRightTest.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnRightTest.java 2010-04-04 04:55:19 UTC (rev 199) @@ -1,42 +0,0 @@ -package org.pojomatic.diff; - -import static org.junit.Assert.*; - -import java.util.NoSuchElementException; - -import org.junit.Test; - -public class OnlyOnRightTest { - private static final OnlyOnRight INSTANCE = new OnlyOnRight("name", "value"); - - @Test(expected = NullPointerException.class) - public void testNullPropertyName() { - new OnlyOnRight(null, new Object()); - } - - @Test - public void testPropertyName() { - assertEquals("name", INSTANCE.propertyName()); - } - - @Test(expected = NoSuchElementException.class) - public void testLeftValue() { - INSTANCE.leftValue(); - } - - @Test - public void testExistsOnLeft() { - assertFalse(INSTANCE.existsOnLeft()); - } - - @Test - public void testExistsOnRight() { - assertTrue(INSTANCE.existsOnRight()); - } - - @Test - public void testRightValue() { - assertEquals("value", INSTANCE.rightValue()); - } - -} Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/ValueDifferenceTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/ValueDifferenceTest.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/ValueDifferenceTest.java 2010-04-04 04:55:19 UTC (rev 199) @@ -21,15 +21,4 @@ public void testRightValue() { assertEquals("that", DIFFERENCE.rightValue()); } - - @Test - public void testExistsOnLeft() { - assertTrue(DIFFERENCE.existsOnLeft()); - } - - @Test - public void testExistsOnRight() { - assertTrue(DIFFERENCE.existsOnRight()); - } - } Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2010-04-04 04:55:19 UTC (rev 199) @@ -11,12 +11,9 @@ import org.junit.Test; import org.pojomatic.Pojomatic; import org.pojomatic.Pojomator; +import org.pojomatic.NoPojomaticPropertiesException; import org.pojomatic.annotations.*; -import org.pojomatic.diff.OnlyOnLeft; -import org.pojomatic.diff.OnlyOnRight; import org.pojomatic.diff.ValueDifference; -import org.pojomatic.diff.DifferenceFromNull; -import org.pojomatic.diff.DifferenceToNull; import org.pojomatic.diff.Differences; import org.pojomatic.diff.PropertyDifferences; import org.pojomatic.formatter.DefaultPojoFormatter; @@ -227,26 +224,21 @@ makePojomatorImpl(FormattedObject.class).doToString(new FormattedObject("x"))); } - @Test public void testDiffNullInstance() { + @Test(expected=NullPointerException.class) + public void testDiffNullInstance() { ObjectPairProperty other = new ObjectPairProperty("this", "that"); - Differences actual = OBJECT_PAIR_PROPERTY_POJOMATOR.doDiff(null, other); - assertFalse(actual.areEqual()); - assertTrue(actual instanceof DifferenceFromNull); - assertEquals(Sets.newHashSet(new OnlyOnRight("s", "this"), new OnlyOnRight("t", "that")), - Sets.newHashSet(actual.differences())); + OBJECT_PAIR_PROPERTY_POJOMATOR.doDiff(null, other); } - @Test public void testDiffNullOther() { + @Test(expected=NullPointerException.class) + public void testDiffNullOther() { ObjectPairProperty instance = new ObjectPairProperty("this", "that"); - Differences actual = OBJECT_PAIR_PROPERTY_POJOMATOR.doDiff(instance, null); - assertFalse(actual.areEqual()); - assertTrue(actual instanceof DifferenceToNull); - assertEquals(Sets.newHashSet(new OnlyOnLeft("s", "this"), new OnlyOnLeft("t", "that")), - Sets.newHashSet(actual.differences())); + OBJECT_PAIR_PROPERTY_POJOMATOR.doDiff(instance, null); } - @Test public void testDiffNulls() { - assertTrue(OBJECT_PAIR_PROPERTY_POJOMATOR.doDiff(null, null).areEqual()); + @Test(expected=NullPointerException.class) + public void testDiffNulls() { + OBJECT_PAIR_PROPERTY_POJOMATOR.doDiff(null, null); } @Test public void testDiffSameObject() { @@ -286,9 +278,9 @@ misCastPojomator.doDiff(new ObjectPairProperty(1,2), "wrong"); fail("exception expcected"); } - catch (ClassCastException e) { + catch (IllegalArgumentException e) { assertEquals( - "other has type java.lang.String which is not a subtype of org.pojomatic.internal.PojomatorImplTest$ObjectPairProperty", + "other has type java.lang.String which is not compatible for equality with org.pojomatic.internal.PojomatorImplTest$ObjectPairProperty", e.getMessage()); } } @@ -300,14 +292,14 @@ misCastPojomator.doDiff("wrong", new ObjectPairProperty(1,2)); fail("exception expcected"); } - catch (ClassCastException e) { + catch (IllegalArgumentException e) { assertEquals( - "instance has type java.lang.String which is not a subtype of org.pojomatic.internal.PojomatorImplTest$ObjectPairProperty", + "instance has type java.lang.String which is not compatible for equality with org.pojomatic.internal.PojomatorImplTest$ObjectPairProperty", e.getMessage()); } } - @Test(expected=IllegalArgumentException.class) + @Test(expected= NoPojomaticPropertiesException.class) public void testNonPojomatedClass() { makePojomatorImpl(String.class); } Modified: trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/PojomaticTestUtils/src/main/java/org/pojomatic/test/AssertUtils.java 2010-04-04 04:55:19 UTC (rev 199) @@ -1,6 +1,7 @@ package org.pojomatic.test; import org.pojomatic.Pojomatic; +import org.pojomatic.NoPojomaticPropertiesException; import org.pojomatic.diff.Differences; /** @@ -30,24 +31,43 @@ * Asserts that the objects are equal via {@link #equal(Object, Object)}. * * @param message the message to add if the assertion fails - * @param first will be displayed first if the assertion fails - * @param second will be displayed second if the assertion fails + * @param expected will be displayed first if the assertion fails + * @param actual will be displayed second if the assertion fails * @throws AssertionError if the objects are not equal. {@link AssertionError#getMessage()} will * include information about the differences */ - public static void assertEquals(String message, Object first, Object second) { - if (!equal(first, second)) { - throw new AssertionError(buildMessage(message, Pojomatic.diff(first, second))); - } + public static void assertEquals(String message, Object expected, Object actual) { + if (!equal(expected, actual)) { + if (expected == null) { + throw new AssertionError( + makeBuilder(message).append("expected is null, but actual is ").append(actual)); + } + if (actual == null) { + throw new AssertionError( + makeBuilder(message).append("actual is null, but expected is ").append(expected)); + } + try { + if (Pojomatic.areCompatibleForEquals(expected.getClass(), actual.getClass())) { + throw new AssertionError(appendStandardEqualityMessage( + makeBuilder(message).append("differences between expected and actual:") + .append(Pojomatic.diff(expected, actual)) + .append(" ("), expected, actual).append(")").toString()); + } + } + catch (NoPojomaticPropertiesException e) {} + throw new AssertionError( + appendStandardEqualityMessage(makeBuilder(message), expected, actual).toString()); + } } - private static String buildMessage(String message, Differences differences) { - StringBuilder formatted = new StringBuilder(); - if (message != null) { - formatted.append(message).append(" "); - } + private static StringBuilder appendStandardEqualityMessage( + StringBuilder builder, Object expected, Object actual) { + return builder + .append("expected:<").append(expected).append("> but was:<").append(actual).append(">"); + } - return formatted.append(differences).toString(); + private static StringBuilder makeBuilder(String message) { + return message == null ? new StringBuilder() : new StringBuilder(message).append(" "); } private AssertUtils() {} Modified: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/junit/PojomaticAssertTest.java =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/junit/PojomaticAssertTest.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/junit/PojomaticAssertTest.java 2010-04-04 04:55:19 UTC (rev 199) @@ -5,8 +5,8 @@ public class PojomaticAssertTest extends AssertTest { @Override - protected void performAssertEquals(Object first, Object second, String message) { - PojomaticAssert.assertEqualsWithDiff(first, second, message); + protected void performAssertEquals(Object expected, Object actual, String message) { + PojomaticAssert.assertEqualsWithDiff(expected, actual, message); } } Modified: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertTest.java =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertTest.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/AssertTest.java 2010-04-04 04:55:19 UTC (rev 199) @@ -15,57 +15,94 @@ * Only the unit under test should throw {@link AssertionError}, so no assertions are allowed * within the implementation of this method. * - * @param first the object which should appear first if the assertion fails. Note that this - * could be either "expected" or "actual". - * @param second the object which should appear second if the assertion fails. Note that this + * @param expected the expected object + * @param actual the actual object * @param message the messaage to include with the assertion */ - protected abstract void performAssertEquals(Object first, Object second, String message); + protected abstract void performAssertEquals(Object expected, Object actual, String message); + private void performAssertEquals( + Object expected, Object actual, String message, String expectedMessage) { + try { + performAssertEquals(expected, actual, message); + fail("exception expected"); + } + catch (AssertionError e) { + assertEquals(expectedMessage, e.getMessage()); + } + } + @Test + public final void assertEqualsWhenEqual() { + performAssertEquals(new Container(3), new Container(3), "message"); + } + + @Test public final void assertEqualsBothNull() { performAssertEquals(null, null, null); } - @Test(expected=AssertionError.class) + @Test public final void assertEqualsNullExpected() { - performAssertEquals(null, new Container(null), null); + performAssertEquals( + null, new Container(null), null, + "expected is null, but actual is Container{test: {null}}"); } - @Test(expected=AssertionError.class) + @Test public final void assertEqualsNullActual() { - performAssertEquals(new Container(null), null, null); + performAssertEquals( + new Container(null), null, null, "actual is null, but expected is Container{test: {null}}"); } /** * Tests that {@link PojomaticAssert#assertEqualsWithDiff(Object, Object)} * uses {@link Object#equals(Object)} instead of {@link Pojomatic#equals(Object, Object)}. */ - @Test(expected=AssertionError.class) + @Test public final void assertEqualsViaInheritedEquals() { //create objects which are never equal via Object.equals(Object), but are equal via //Pojomatic.equals(Object, Object) OnlyPojomaticEqual first = new OnlyPojomaticEqual(); OnlyPojomaticEqual second = new OnlyPojomaticEqual(); + performAssertEquals(first, second, null, + "differences between expected and actual:no differences (expected:<toString> but was:<toString>)"); + } - performAssertEquals(first, second, null); + @Test + public final void assertEqualsNoMessage() { + performAssertEquals( + new Container("foo"), new Container("bar"), null, + "differences between expected and actual:[test: {foo} versus {bar}]" + + " (expected:<Container{test: {foo}}> but was:<Container{test: {bar}}>)"); } @Test - public final void assertEqualsMessage() { + public final void assertEqualsMessag2() { String first = "foo"; String second = "bar"; - try { - performAssertEquals(new Container(first), new Container(second), null); - } - catch (AssertionError e) { - assertEquals("[test: {foo} versus {bar}]", e.getMessage()); - } - try { - performAssertEquals(new Container(first), new Container(second), "custom message"); - } - catch (AssertionError e) { - assertEquals("custom message [test: {foo} versus {bar}]", e.getMessage()); - } + performAssertEquals( + new Container(first), new Container(second), null, + "differences between expected and actual:[test: {foo} versus {bar}]" + + " (expected:<Container{test: {foo}}> but was:<Container{test: {bar}}>)"); } + + @Test + public final void assertEqualsCustomMessage() { + performAssertEquals( + new Container("foo"), new Container("bar"), "hello", + "hello differences between expected and actual:[test: {foo} versus {bar}]" + + " (expected:<Container{test: {foo}}> but was:<Container{test: {bar}}>)"); + } + + @Test + public final void assertEqualsNonPojomatic() { + performAssertEquals("string a", "string b", null, "expected:<string a> but was:<string b>"); + } + + @Test + public final void assertEqualsNonComparable() { + performAssertEquals(new Container("foo"), new DifferentPojo("foo"), null, + "expected:<Container{test: {foo}}> but was:<DifferentPojo{test: {foo}}>"); + } } Copied: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/DifferentPojo.java (from rev 197, trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/Container.java) =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/DifferentPojo.java (rev 0) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/DifferentPojo.java 2010-04-04 04:55:19 UTC (rev 199) @@ -0,0 +1,37 @@ +package org.pojomatic.test; + +import org.pojomatic.Pojomatic; +import org.pojomatic.annotations.AutoProperty; + +/** + * Simple one-object container for use in tests. + */ +@AutoProperty +public class DifferentPojo { + + private final Object test; + + public DifferentPojo(Object test) { + this.test = test; + } + + public Object getTest() { + return test; + } + + @Override + public int hashCode() { + return Pojomatic.hashCode(this); + } + + @Override + public String toString() { + return Pojomatic.toString(this); + } + + @Override + public boolean equals(Object o) { + return Pojomatic.equals(this, o); + } + +} Modified: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/OnlyPojomaticEqual.java =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/OnlyPojomaticEqual.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/test/OnlyPojomaticEqual.java 2010-04-04 04:55:19 UTC (rev 199) @@ -20,4 +20,9 @@ } return false; } + + @Override + public String toString() { + return "toString"; + } } Modified: trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/testng/PojomaticAssertTest.java =================================================================== --- trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/testng/PojomaticAssertTest.java 2010-03-31 04:58:11 UTC (rev 198) +++ trunk/PojomaticAll/PojomaticTestUtils/src/test/java/org/pojomatic/testng/PojomaticAssertTest.java 2010-04-04 04:55:19 UTC (rev 199) @@ -5,9 +5,9 @@ public class PojomaticAssertTest extends AssertTest { @Override - protected void performAssertEquals(Object first, Object second, String message) { + protected void performAssertEquals(Object expected, Object actual, String message) { //in TestNG, the arguments are included in any failure message in reverse order - PojomaticAssert.assertEqualsWithDiff(second, first, message); + PojomaticAssert.assertEqualsWithDiff(actual, expected, message); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-03-31 04:58:17
|
Revision: 198 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=198&view=rev Author: iroberts Date: 2010-03-31 04:58:11 +0000 (Wed, 31 Mar 2010) Log Message: ----------- Expose the ability to determine if two classes are compatible for equality Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java 2010-03-12 06:49:21 UTC (rev 197) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java 2010-03-31 04:58:11 UTC (rev 198) @@ -124,6 +124,17 @@ return pojomator(getClass(pojo)).doEquals(pojo, other); } + /** + * Compute whether {@code classA} and {@code classB} are compatible for equality as specified + * by the documentation for {@link Pojomator#isCompatibleForEquality(Class)}. + * @param classA the first class to check for compatibility for equality + * @param classB the second class to check for compatibility for equality + * @return {@code true} if the two classes are compatible for equality, or {@code false} + * otherwise. + */ + public static boolean areCompatibleForEquals(Class<?> classA, Class<?> classB) { + return pojomator(classA).isCompatibleForEquality(classB); + } /** * Compute the differences between {@code pojo} and {@code other} among the properties Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java 2010-03-12 06:49:21 UTC (rev 197) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java 2010-03-31 04:58:11 UTC (rev 198) @@ -15,7 +15,8 @@ /** * A provider of the three standard {@code Object} methods, - * {@link Object#equals(Object)}, {@link Object#hashCode()} and {@link Object#toString()}. + * {@link Object#equals(Object)}, {@link Object#hashCode()} and {@link Object#toString()}, as + * well as a usefull method to aid in debugging, {@link #doDiff(Object, Object)}}. * * @param <T> the class this {@code Pojomator} is generated for. */ @@ -76,30 +77,17 @@ /** * Compute whether {@code instance} and {@code other} are equal to each other in the sense of - * {@code Object}'s {@link Object#equals(Object) equals} method. - * <p> - * For two instances to be considered equal, the first requirement is that their classes must be - * compatible for equality. Classes {@code A} and {@code B} are compatible for equality if - * they share a common superclass {@code C}, and for every class {@code D} which - * is a proper subclass of {@code C} and a superclass of {@code A} or {@code B} (including - * the classes {@code A} and {@code B} themselves), the following hold: - * <ul> - * <li>{@code D} has not added additional properties for inclusion in the {@code equals} calculation, and</li> - * <li>{@code D} has not been annotated with {@link OverridesEquals}</li> - * </ul> - * If {@code T} is an interface or is annotated with {@link SubclassCannotOverrideEquals}, - * then all subclasses of {@code T} are automatically assumed by {@code T}'s {@code Pojomator} - * to be comapatible for equals with each other and with {@code T}. Note that in this case. - * to add an {@link OverridesEquals} annotation or additional - * properties for inclusion in {@code equals} to a subclass of {@code T} will - * result in a violation of the contract for {@link Object#equals(Object)}. + * {@code Object}'s {@link Object#equals(Object) equals} method. For two instances to be + * considered equal, the first requirement is that their classes must be compatible for equality, + * as described in the documentation for {@link #isCompatibleForEquality(Class)}. * </p> * <p> - * More precisely, if {@code other} is null, this method returns {@code false}. Otherwise, it is verified that - * the class of {@code other} is compatible for {@code equals} with {@code T}; if not, then this method - * returns false. Otherwise, this method will return true provided that each property of {@code - * instance} which has a {@code PojomaticPolicy} other than {@code TO_STRING} or - * {@code NONE} is equal to the corresponding property of {@code other} in the following sense: + * More precisely, if {@code other} is null, this method returns {@code false}. Otherwise, if + * {@link #isCompatibleForEquality(Class) isCompatibleForEquals(other.getClass())} would return + * false, then this method will return false. Otherwise, this method will return true provided + * that each property of {@code instance} which has a {@code PojomaticPolicy} other than + * {@code TO_STRING} or {@code NONE} is equal to the corresponding property of {@code other} in + * the following sense: * <ul> * <li>Both are {@code null}, or</li> * <li>Both are reference-equals (==) to each other, or</li> @@ -122,6 +110,28 @@ boolean doEquals(T instance, Object other); /** + * Compute whether {@code otherClass} is compatible for equality with {@code T}. + * Classes {@code A} and {@code B} are compatible for equality if + * they share a common superclass {@code C}, and for every class {@code D} which + * is a proper subclass of {@code C} and a superclass of {@code A} or {@code B} (including + * the classes {@code A} and {@code B} themselves), the following hold: + * <ul> + * <li>{@code D} has not added additional properties for inclusion in the {@code equals} calculation, and</li> + * <li>{@code D} has not been annotated with {@link OverridesEquals}</li> + * </ul> + * If {@code T} is an interface or is annotated with {@link SubclassCannotOverrideEquals}, + * then all subclasses of {@code T} are automatically assumed by {@code T}'s {@code Pojomator} + * to be comapatible for equals with each other and with {@code T}. Note that in this case. + * to add an {@link OverridesEquals} annotation or additional + * properties for inclusion in {@code equals} to a subclass of {@code T} will + * result in a violation of the contract for {@link Object#equals(Object)}. + * @param otherClass the class to check for compatibility for equality with {@code T} + * @return {@code true} if {@code otherClass} is compatible for equality with {@code T}, and + * {@code false} otherwise. + */ + boolean isCompatibleForEquality(Class<?> otherClass); + + /** * Compute the differences between {@code instance} and {@code other} among the properties * examined by {@link #doEquals(Object, Object)}. Assuming that {@code instance} and {@code other} * are both non-null and have types which are compatible for equals, it is guaranteed that invoking Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2010-03-12 06:49:21 UTC (rev 197) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2010-03-31 04:58:11 UTC (rev 198) @@ -80,7 +80,7 @@ return false; } if (!instance.getClass().equals(other.getClass())) { - if (!classProperties.isCompatibleForEquals(other.getClass())) { + if (!isCompatibleForEquality(other.getClass())) { return false; } } @@ -93,6 +93,10 @@ return true; } + public boolean isCompatibleForEquality(Class<?> otherClass) { + return classProperties.isCompatibleForEquals(otherClass); + } + public int doHashCode(T instance) { int hashCode = HASH_CODE_SEED; if (instance == null) { Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java 2010-03-12 06:49:21 UTC (rev 197) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java 2010-03-31 04:58:11 UTC (rev 198) @@ -18,6 +18,7 @@ public static class Bean { @Property public final int x; public Bean(int x) { this.x = x; } + public Bean() { x = 0; } } private static Pojomator<Bean> BEAN_POJOMATOR = new PojomatorImpl<Bean>(Bean.class); @@ -70,4 +71,16 @@ assertTrue(Pojomatic.equals(new Bean(3), new Bean(3))); assertFalse(Pojomatic.equals(new Bean(3), new Bean(4))); } + + @Test + public void testCompatibleForEquality() { + class BeanSubClass extends Bean{}; + + class BeanWithExtraData extends Bean { + @Property public int getY() { return 0; } + } + assertTrue(Pojomatic.areCompatibleForEquals(Bean.class, BeanSubClass.class)); + assertFalse(Pojomatic.areCompatibleForEquals(Bean.class, BeanWithExtraData.class)); + assertFalse(Pojomatic.areCompatibleForEquals(BeanWithExtraData.class, Bean.class)); + } } Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2010-03-12 06:49:21 UTC (rev 197) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2010-03-31 04:58:11 UTC (rev 198) @@ -332,7 +332,6 @@ public String getString() { return string; } } - assertEquals("Interface{int: {2}, string: {hello}}", pojomator.doToString(new Impl1())); assertEquals(( HASH_CODE_MULTIPLIER + 2)*HASH_CODE_MULTIPLIER + "hello".hashCode(), pojomator.doHashCode(new Impl1())); @@ -341,6 +340,15 @@ assertFalse(pojomator.doEquals(new Impl1(), "not even in the right hierarchy")); } + @Test public void testIsCompatibleForEquals() { + assertTrue(OBJECT_PROPERTY_POJOMATOR.isCompatibleForEquality(ObjectProperty.class)); + assertFalse(OBJECT_PROPERTY_POJOMATOR.isCompatibleForEquality(ObjectPairProperty.class)); + assertTrue(makePojomatorImpl(Interface.class).isCompatibleForEquality(new Interface() { + public int getInt() { return 0; } + public String getString() { return null; } + }.getClass())); + } + @Test public void testToString() { @SuppressWarnings("unused") class SimplePojo { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2010-03-12 06:49:28
|
Revision: 197 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=197&view=rev Author: chriswhansen Date: 2010-03-12 06:49:21 +0000 (Fri, 12 Mar 2010) Log Message: ----------- Revamped Differences API so that the difference information can be accessed programmatically. Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/pom.xml trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceFromNull.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceToNull.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Differences.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/NoDifferences.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/PropertyDifferences.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/ValueDifference.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceFromNullTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceToNullTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/NoDifferencesTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/PropertyDifferencesTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/ValueDifferenceTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java Added Paths: ----------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnLeft.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnRight.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnLeftTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnRightTest.java Modified: trunk/PojomaticAll/Pojomatic/pom.xml =================================================================== --- trunk/PojomaticAll/Pojomatic/pom.xml 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/pom.xml 2010-03-12 06:49:21 UTC (rev 197) @@ -19,6 +19,15 @@ <url>https://pojomatic.svn.sourceforge.net/svnroot/pojomatic/trunk/pojomatic-all/pojomatic</url> </scm> + <dependencies> + <dependency> + <groupId>com.google.collections</groupId> + <artifactId>google-collections</artifactId> + <version>1.0</version> + <scope>test</scope> + </dependency> + </dependencies> + <reporting> <plugins> <plugin> Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomatic.java 2010-03-12 06:49:21 UTC (rev 197) @@ -1,6 +1,5 @@ package org.pojomatic; -import org.pojomatic.diff.DifferenceFromNull; import org.pojomatic.diff.Differences; import org.pojomatic.diff.NoDifferences; import org.pojomatic.internal.PojomatorImpl; @@ -143,7 +142,7 @@ throws NullPointerException, IllegalArgumentException { if (pojo == null) { if (other != null) { - return new DifferenceFromNull(other); + return pojomator(getClass(other)).doDiff(null, other); } else { //both null return NoDifferences.getInstance(); Added: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java 2010-03-12 06:49:21 UTC (rev 197) @@ -0,0 +1,49 @@ +package org.pojomatic.diff; + +import java.util.NoSuchElementException; + +/** + * A difference between two objects, 'left' and 'right'. + */ +public interface Difference { + + /** + * The name of the property. + * + * @return the name of the property + */ + String propertyName(); + + /** + * Whether or not the property exists on the left object. + * + * @return {@code true} if the property exists on the left object, {@code false} otherwise + */ + boolean existsOnLeft(); + + /** + * Whether or not the property exists on the right object. + * + * @return {@code true} if the property exists on the right object, {@code false} otherwise + */ + boolean existsOnRight(); + + /** + * The value from the left instance (possibly {@code null}). + * + * @return the value from the left instance (possibly {@code null}) + * @throws NoSuchElementException if the value does not exist on the left instance + * @see #existsOnLeft() + */ + Object leftValue() throws NoSuchElementException; + + /** + * The value from the right instance (possibly {@code null}). + * + * @return the value from the right instance (possibly {@code null}) + * @throws NoSuchElementException if the value does not exist on the right instance + * @see #existsOnRight() + */ + Object rightValue() throws NoSuchElementException; + +} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceFromNull.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceFromNull.java 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceFromNull.java 2010-03-12 06:49:21 UTC (rev 197) @@ -5,9 +5,14 @@ * @see DifferenceToNull */ public final class DifferenceFromNull extends AbstractNullDifference { + private final Iterable<OnlyOnRight> differences; - public DifferenceFromNull(Object other) { + public DifferenceFromNull(Object other, Iterable<OnlyOnRight> differences) { super(other); + if (differences == null) { + throw new NullPointerException("Differences cannot be null"); + } + this.differences = differences; } @Override @@ -15,4 +20,8 @@ return "null is different than the object {" + instance + "}"; } + public Iterable<? extends Difference> differences() { + return differences; + } + } Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceToNull.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceToNull.java 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/DifferenceToNull.java 2010-03-12 06:49:21 UTC (rev 197) @@ -5,13 +5,22 @@ * @see DifferenceFromNull */ public final class DifferenceToNull extends AbstractNullDifference { + private final Iterable<OnlyOnLeft> differences; - public DifferenceToNull(Object instance) { + public DifferenceToNull(Object instance, Iterable<OnlyOnLeft> differences) { super(instance); + if (differences == null) { + throw new NullPointerException("Differences cannot be null"); + } + this.differences = differences; } @Override public String toString() { return "the object {" + instance + "} is different than null"; } + + public Iterable<? extends Difference> differences() { + return differences; + } } Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Differences.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Differences.java 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Differences.java 2010-03-12 06:49:21 UTC (rev 197) @@ -4,15 +4,24 @@ * A summary of differences (if any) between two POJOs. */ public interface Differences { + /** - * @return a description of the differences + * The differences between the two objects. If there are no differences, an + * empty {@link Iterable}. + * + * @return the differences between the two objects, or an empty {@link Iterable} if there are none */ - @Override - String toString(); + Iterable<? extends Difference> differences(); /** * @return {@code true} if the two POJOs were {@code equal} to each other; * {@code false} otherwise. */ boolean areEqual(); + + /** + * @return a description of the differences + */ + @Override + String toString(); } Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/NoDifferences.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/NoDifferences.java 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/NoDifferences.java 2010-03-12 06:49:21 UTC (rev 197) @@ -1,5 +1,7 @@ package org.pojomatic.diff; +import java.util.Collections; + public final class NoDifferences implements Differences { private static final NoDifferences INSTANCE = new NoDifferences(); @@ -19,4 +21,8 @@ return INSTANCE; } + public Iterable<Difference> differences() { + return Collections.emptyList(); + } + } Added: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnLeft.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnLeft.java (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnLeft.java 2010-03-12 06:49:21 UTC (rev 197) @@ -0,0 +1,62 @@ +package org.pojomatic.diff; + +import java.util.NoSuchElementException; + +import org.pojomatic.Pojomatic; +import org.pojomatic.annotations.Property; + +/** + * A {@link Difference} which only has a value on the left. + */ +public final class OnlyOnLeft implements Difference { + + private final String propertyName; + + private final Object leftValue; + + public OnlyOnLeft(String propertyName, Object leftValue) { + if (propertyName == null) { + throw new NullPointerException("Property name cannot be null"); + } + this.propertyName = propertyName; + this.leftValue = leftValue; + } + + @Property + public String propertyName() { + return propertyName; + } + + @Property + public Object leftValue() { + return leftValue; + } + + public boolean existsOnLeft() { + return true; + } + + public boolean existsOnRight() { + return false; + } + + public Object rightValue() throws NoSuchElementException { + throw new NoSuchElementException("Value only exists on the left"); + } + + @Override + public int hashCode() { + return Pojomatic.hashCode(this); + } + + @Override + public String toString() { + return Pojomatic.toString(this); + } + + @Override + public boolean equals(Object o) { + return Pojomatic.equals(this, o); + } + +} Added: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnRight.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnRight.java (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/OnlyOnRight.java 2010-03-12 06:49:21 UTC (rev 197) @@ -0,0 +1,62 @@ +package org.pojomatic.diff; + +import java.util.NoSuchElementException; + +import org.pojomatic.Pojomatic; +import org.pojomatic.annotations.Property; + +/** + * A {@link Difference} which only has a value on the right. + */ +public final class OnlyOnRight implements Difference { + + private final String propertyName; + + private final Object rightValue; + + public OnlyOnRight(String propertyName, Object rightValue) { + if (propertyName == null) { + throw new NullPointerException("Property name cannot be null"); + } + this.propertyName = propertyName; + this.rightValue = rightValue; + } + + @Property + public String propertyName() { + return propertyName; + } + + public Object leftValue() { + throw new NoSuchElementException("Value only exists on the right"); + } + + public boolean existsOnLeft() { + return false; + } + + public boolean existsOnRight() { + return true; + } + + @Property + public Object rightValue() throws NoSuchElementException { + return rightValue; + } + + @Override + public int hashCode() { + return Pojomatic.hashCode(this); + } + + @Override + public String toString() { + return Pojomatic.toString(this); + } + + @Override + public boolean equals(Object o) { + return Pojomatic.equals(this, o); + } + +} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/PropertyDifferences.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/PropertyDifferences.java 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/PropertyDifferences.java 2010-03-12 06:49:21 UTC (rev 197) @@ -8,14 +8,14 @@ public class PropertyDifferences implements Differences { @Property - private final List<ValueDifference> differences; + private final List<Difference> differences; /** * @param differences cannot be {@code null} or empty * @throws NullPointerException if {@code differences} is {@code null} * @throws IllegalArgumentException if {@code differences.isEmpty()} is {@code true} */ - public PropertyDifferences(List<ValueDifference> differences) { + public PropertyDifferences(List<Difference> differences) { if (differences == null) { throw new NullPointerException("list of differences is null"); } @@ -25,7 +25,7 @@ this.differences = Collections.unmodifiableList(differences); } - public List<ValueDifference> getDifferences() { + public List<Difference> differences() { return differences; } Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/ValueDifference.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/ValueDifference.java 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/ValueDifference.java 2010-03-12 06:49:21 UTC (rev 197) @@ -1,32 +1,42 @@ package org.pojomatic.diff; import org.pojomatic.Pojomatic; -import org.pojomatic.annotations.AutoProperty; +import org.pojomatic.annotations.Property; -@AutoProperty -public class ValueDifference { +public class ValueDifference implements Difference { private final String propertyName; - private final Object lhs; - private final Object rhs; + private final Object leftValue; + private final Object rightValue; public ValueDifference(String propertyName, Object lhs, Object rhs) { this.propertyName = propertyName; - this.lhs = lhs; - this.rhs = rhs; + this.leftValue = lhs; + this.rightValue = rhs; } - public String getPropertyName() { + @Property + public String propertyName() { return propertyName; } - public Object getLhs() { - return lhs; + @Property + public Object leftValue() { + return leftValue; } - public Object getRhs() { - return rhs; + @Property + public Object rightValue() { + return rightValue; } + public boolean existsOnLeft() { + return true; + } + + public boolean existsOnRight() { + return true; + } + @Override public boolean equals(Object obj) { return Pojomatic.equals(this, obj); @@ -40,7 +50,7 @@ @Override public String toString() { //TODO - can we do better here? - return propertyName + ": {" + lhs + "} versus {" + rhs + "}"; + return propertyName + ": {" + leftValue + "} versus {" + rightValue + "}"; } } Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2010-03-12 06:49:21 UTC (rev 197) @@ -3,18 +3,22 @@ import java.lang.reflect.AnnotatedElement; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import org.pojomatic.Pojomator; import org.pojomatic.PropertyElement; import org.pojomatic.annotations.PojoFormat; import org.pojomatic.annotations.PropertyFormat; -import org.pojomatic.diff.ValueDifference; +import org.pojomatic.diff.Difference; import org.pojomatic.diff.DifferenceFromNull; import org.pojomatic.diff.DifferenceToNull; import org.pojomatic.diff.Differences; import org.pojomatic.diff.NoDifferences; +import org.pojomatic.diff.OnlyOnLeft; +import org.pojomatic.diff.OnlyOnRight; import org.pojomatic.diff.PropertyDifferences; +import org.pojomatic.diff.ValueDifference; import org.pojomatic.formatter.DefaultPojoFormatter; import org.pojomatic.formatter.DefaultPropertyFormatter; import org.pojomatic.formatter.PojoFormatter; @@ -108,7 +112,7 @@ else { if (value.getClass().isArray()) { Class<?> instanceComponentClass = value.getClass().getComponentType(); - if (! instanceComponentClass.isPrimitive()) { + if (!instanceComponentClass.isPrimitive()) { return Arrays.hashCode((Object[]) value); } else { @@ -116,7 +120,7 @@ return Arrays.hashCode((boolean[]) value); } else if (Byte.TYPE == instanceComponentClass) { - return Arrays.hashCode((byte[]) value); + return Arrays.hashCode((byte[]) value); } else if (Character.TYPE == instanceComponentClass) { return Arrays.hashCode((char[]) value); @@ -222,20 +226,23 @@ } public Differences doDiff(T instance, T other) { + final Collection<PropertyElement> diffProperties = classProperties.getEqualsProperties(); if (instance == other) { return NoDifferences.getInstance(); } else if (instance == null) { - return new DifferenceFromNull(other); + checkClass(other, "other"); + return new DifferenceFromNull(other, onlyOnRight(other, diffProperties)); } else if (other == null) { - return new DifferenceToNull(instance); + checkClass(instance, "instance"); + return new DifferenceToNull(instance, onlyOnLeft(instance, diffProperties)); } checkClass(instance, "instance"); checkClass(other, "other"); - List<ValueDifference> differences = new ArrayList<ValueDifference>(); - for (PropertyElement prop: classProperties.getEqualsProperties()) { + final List<Difference> differences = new ArrayList<Difference>(); + for (PropertyElement prop : diffProperties) { final Object instanceValue = prop.getValue(instance); final Object otherValue = prop.getValue(other); if (!areValuesEqual(instanceValue, otherValue)) { @@ -249,6 +256,23 @@ return new PropertyDifferences(differences); } + private Iterable<OnlyOnLeft> onlyOnLeft(T instance, Collection<PropertyElement> diffProperties) { + List<OnlyOnLeft> result = new ArrayList<OnlyOnLeft>(); + for (PropertyElement element : diffProperties) { + result.add(new OnlyOnLeft(element.getName(), element.getValue(instance))); + } + return result; + } + + private Iterable<OnlyOnRight> onlyOnRight(Object value, + Collection<PropertyElement> diffProperties) { + List<OnlyOnRight> result = new ArrayList<OnlyOnRight>(); + for (PropertyElement element : diffProperties) { + result.add(new OnlyOnRight(element.getName(), element.getValue(value))); + } + return result; + } + private void checkClass(T instance, String label) { if (!clazz.isInstance(instance)) { throw new ClassCastException( @@ -283,8 +307,8 @@ if (!otherValue.getClass().isArray()) { return false; } - Class<?> instanceComponentClass = instanceValue.getClass().getComponentType(); - Class<?> otherComponentClass = otherValue.getClass().getComponentType(); + final Class<?> instanceComponentClass = instanceValue.getClass().getComponentType(); + final Class<?> otherComponentClass = otherValue.getClass().getComponentType(); if (!instanceComponentClass.isPrimitive()) { if (otherComponentClass.isPrimitive()) { @@ -300,42 +324,42 @@ } if (Boolean.TYPE == instanceComponentClass) { - if(!Arrays.equals((boolean[]) instanceValue, (boolean[]) otherValue)) { + if (!Arrays.equals((boolean[]) instanceValue, (boolean[]) otherValue)) { return false; } } else if (Byte.TYPE == instanceComponentClass) { - if (! Arrays.equals((byte[]) instanceValue, (byte[]) otherValue)) { + if (!Arrays.equals((byte[]) instanceValue, (byte[]) otherValue)) { return false; } } else if (Character.TYPE == instanceComponentClass) { - if(!Arrays.equals((char[]) instanceValue, (char[]) otherValue)) { + if (!Arrays.equals((char[]) instanceValue, (char[]) otherValue)) { return false; } } else if (Short.TYPE == instanceComponentClass) { - if(!Arrays.equals((short[]) instanceValue, (short[]) otherValue)) { + if (!Arrays.equals((short[]) instanceValue, (short[]) otherValue)) { return false; } } else if (Integer.TYPE == instanceComponentClass) { - if(!Arrays.equals((int[]) instanceValue, (int[]) otherValue)) { + if (!Arrays.equals((int[]) instanceValue, (int[]) otherValue)) { return false; } } else if (Long.TYPE == instanceComponentClass) { - if(!Arrays.equals((long[]) instanceValue, (long[]) otherValue)) { + if (!Arrays.equals((long[]) instanceValue, (long[]) otherValue)) { return false; } } else if (Float.TYPE == instanceComponentClass) { - if(!Arrays.equals((float[]) instanceValue, (float[]) otherValue)) { + if (!Arrays.equals((float[]) instanceValue, (float[]) otherValue)) { return false; } } else if (Double.TYPE == instanceComponentClass) { - if(!Arrays.equals((double[]) instanceValue, (double[]) otherValue)) { + if (!Arrays.equals((double[]) instanceValue, (double[]) otherValue)) { return false; } } Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/PojomaticTest.java 2010-03-12 06:49:21 UTC (rev 197) @@ -5,9 +5,15 @@ import org.junit.Test; import org.pojomatic.annotations.Property; import org.pojomatic.diff.DifferenceFromNull; +import org.pojomatic.diff.DifferenceToNull; +import org.pojomatic.diff.Differences; import org.pojomatic.diff.NoDifferences; +import org.pojomatic.diff.OnlyOnLeft; +import org.pojomatic.diff.OnlyOnRight; import org.pojomatic.internal.PojomatorImpl; +import com.google.common.collect.Sets; + public class PojomaticTest { public static class Bean { @Property public final int x; @@ -29,7 +35,7 @@ } @Test - public void testDiff() { + public void testDiffNoDifferences() { assertEquals(NoDifferences.getInstance(), Pojomatic.diff(BEAN, BEAN)); } @@ -40,12 +46,18 @@ @Test public void testDiffNullFirst() { - assertEquals(new DifferenceFromNull(BEAN), Pojomatic.diff(null, BEAN)); + Iterable<OnlyOnRight> beanDifferences = Sets.newHashSet(new OnlyOnRight("x", BEAN.x)); + Differences differences = Pojomatic.diff(null, BEAN); + assertEquals(new DifferenceFromNull(BEAN, beanDifferences), differences); + assertEquals(beanDifferences, Sets.newHashSet(differences.differences())); } @Test public void testDiffNullSecond() { - assertEquals(BEAN_POJOMATOR.doDiff(BEAN, null), Pojomatic.diff(BEAN, null)); + Iterable<OnlyOnLeft> beanDifferences = Sets.newHashSet(new OnlyOnLeft("x", BEAN.x)); + Differences differences = Pojomatic.diff(BEAN, null); + assertEquals(new DifferenceToNull(BEAN, beanDifferences), differences); + assertEquals(beanDifferences, Sets.newHashSet(differences.differences())); } @Test Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceFromNullTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceFromNullTest.java 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceFromNullTest.java 2010-03-12 06:49:21 UTC (rev 197) @@ -2,22 +2,32 @@ import static org.junit.Assert.*; +import java.util.Collections; + import org.junit.Test; public class DifferenceFromNullTest { + private static final Iterable<OnlyOnRight> EMPTY_DIFFERENCES = + Collections.<OnlyOnRight>emptyList(); - @Test(expected=NullPointerException.class) - public void testConstructorNullPointerException() { - new DifferenceFromNull(null); + @Test(expected = NullPointerException.class) + public void testNullValue() { + new DifferenceFromNull(null, EMPTY_DIFFERENCES); } + @Test(expected = NullPointerException.class) + public void testNullDifferences() { + new DifferenceFromNull(new Object(), null); + } + @Test public void testToString() { - assertEquals("null is different than the object {3}", new DifferenceFromNull(3).toString()); + DifferenceFromNull difference = new DifferenceFromNull(3, EMPTY_DIFFERENCES); + assertEquals("null is different than the object {3}", difference.toString()); } @Test public void testAreEqual() { - assertFalse(new DifferenceFromNull(3).areEqual()); + assertFalse(new DifferenceFromNull(3, EMPTY_DIFFERENCES).areEqual()); } } Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceToNullTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceToNullTest.java 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceToNullTest.java 2010-03-12 06:49:21 UTC (rev 197) @@ -2,22 +2,31 @@ import static org.junit.Assert.*; +import java.util.Collections; + import org.junit.Test; public class DifferenceToNullTest { + private static final Iterable<OnlyOnLeft> EMPTY_DIFFERENCES = Collections.<OnlyOnLeft>emptyList(); - @Test(expected=NullPointerException.class) - public void testConstructorNullPointerException() { - new DifferenceToNull(null); + @Test(expected = NullPointerException.class) + public void testNullValue() { + new DifferenceToNull(null, EMPTY_DIFFERENCES); } + @Test(expected = NullPointerException.class) + public void testNullDifferences() { + new DifferenceToNull(new Object(), null); + } + @Test public void testToString() { - assertEquals("the object {3} is different than null", new DifferenceToNull(3).toString()); + DifferenceToNull differences = new DifferenceToNull(3, EMPTY_DIFFERENCES); + assertEquals("the object {3} is different than null", differences.toString()); } @Test public void testAreEqual() { - assertFalse(new DifferenceToNull(3).areEqual()); + assertFalse(new DifferenceToNull(3, EMPTY_DIFFERENCES).areEqual()); } } Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/NoDifferencesTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/NoDifferencesTest.java 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/NoDifferencesTest.java 2010-03-12 06:49:21 UTC (rev 197) @@ -16,4 +16,9 @@ assertEquals("no differences", NoDifferences.getInstance().toString()); } + @Test + public void testDifferences() { + assertFalse(NoDifferences.getInstance().differences().iterator().hasNext()); + } + } Added: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnLeftTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnLeftTest.java (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnLeftTest.java 2010-03-12 06:49:21 UTC (rev 197) @@ -0,0 +1,42 @@ +package org.pojomatic.diff; + +import static org.junit.Assert.*; + +import java.util.NoSuchElementException; + +import org.junit.Test; + +public class OnlyOnLeftTest { + private static final OnlyOnLeft INSTANCE = new OnlyOnLeft("name", "value"); + + @Test(expected = NullPointerException.class) + public void testNullPropertyName() { + new OnlyOnLeft(null, new Object()); + } + + @Test + public void testPropertyName() { + assertEquals("name", INSTANCE.propertyName()); + } + + @Test + public void testLeftValue() { + assertEquals("value", INSTANCE.leftValue()); + } + + @Test + public void testExistsOnLeft() { + assertTrue(INSTANCE.existsOnLeft()); + } + + @Test + public void testExistsOnRight() { + assertFalse(INSTANCE.existsOnRight()); + } + + @Test(expected = NoSuchElementException.class) + public void testRightValue() { + INSTANCE.rightValue(); + } + +} Added: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnRightTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnRightTest.java (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/OnlyOnRightTest.java 2010-03-12 06:49:21 UTC (rev 197) @@ -0,0 +1,42 @@ +package org.pojomatic.diff; + +import static org.junit.Assert.*; + +import java.util.NoSuchElementException; + +import org.junit.Test; + +public class OnlyOnRightTest { + private static final OnlyOnRight INSTANCE = new OnlyOnRight("name", "value"); + + @Test(expected = NullPointerException.class) + public void testNullPropertyName() { + new OnlyOnRight(null, new Object()); + } + + @Test + public void testPropertyName() { + assertEquals("name", INSTANCE.propertyName()); + } + + @Test(expected = NoSuchElementException.class) + public void testLeftValue() { + INSTANCE.leftValue(); + } + + @Test + public void testExistsOnLeft() { + assertFalse(INSTANCE.existsOnLeft()); + } + + @Test + public void testExistsOnRight() { + assertTrue(INSTANCE.existsOnRight()); + } + + @Test + public void testRightValue() { + assertEquals("value", INSTANCE.rightValue()); + } + +} Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/PropertyDifferencesTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/PropertyDifferencesTest.java 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/PropertyDifferencesTest.java 2010-03-12 06:49:21 UTC (rev 197) @@ -16,29 +16,36 @@ @Test(expected=IllegalArgumentException.class) public void testEmptyDifferences() { - new PropertyDifferences(Collections.<ValueDifference>emptyList()); + new PropertyDifferences(Collections.<Difference>emptyList()); } @Test public void testSingleDifferenceToString() { + PropertyDifferences propertyDifferences = new PropertyDifferences( + Arrays.<Difference>asList(new ValueDifference("foo", 3, 4))); assertEquals( "[foo: {3} versus {4}]", - new PropertyDifferences(Arrays.asList(new ValueDifference("foo", 3, 4))).toString()); + propertyDifferences.toString()); + + propertyDifferences = new PropertyDifferences( + Arrays.<Difference>asList(new ValueDifference("foo", null, 4))); assertEquals( "[foo: {null} versus {4}]", - new PropertyDifferences(Arrays.asList(new ValueDifference("foo", null, 4))).toString()); + propertyDifferences.toString()); } @Test public void testMultipleDifferencesToString() { assertEquals( "[foo: {3} versus {4}, bar: {this} versus {that}]", - new PropertyDifferences(Arrays.asList( + new PropertyDifferences(Arrays.<Difference>asList( new ValueDifference("foo", 3, 4), new ValueDifference("bar", "this", "that"))).toString()); } @Test public void testAreEqual() { - assertFalse(new PropertyDifferences(Arrays.asList(new ValueDifference("foo", 3, 4))).areEqual()); + PropertyDifferences propertyDifferences = new PropertyDifferences( + Arrays.<Difference>asList(new ValueDifference("foo", 3, 4))); + assertFalse(propertyDifferences.areEqual()); } } Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/ValueDifferenceTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/ValueDifferenceTest.java 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/ValueDifferenceTest.java 2010-03-12 06:49:21 UTC (rev 197) @@ -8,18 +8,28 @@ private ValueDifference DIFFERENCE = new ValueDifference("foo", "this", "that"); @Test - public void testGetPropertyName() { - assertEquals("foo", DIFFERENCE.getPropertyName()); + public void testPropertyName() { + assertEquals("foo", DIFFERENCE.propertyName()); } @Test - public void testGetLhs() { - assertEquals("this", DIFFERENCE.getLhs()); + public void testLeftValue() { + assertEquals("this", DIFFERENCE.leftValue()); } @Test - public void testGetRhs() { - assertEquals("that", DIFFERENCE.getRhs()); + public void testRightValue() { + assertEquals("that", DIFFERENCE.rightValue()); } + @Test + public void testExistsOnLeft() { + assertTrue(DIFFERENCE.existsOnLeft()); + } + + @Test + public void testExistsOnRight() { + assertTrue(DIFFERENCE.existsOnRight()); + } + } Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2010-02-26 23:10:31 UTC (rev 196) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2010-03-12 06:49:21 UTC (rev 197) @@ -12,6 +12,8 @@ import org.pojomatic.Pojomatic; import org.pojomatic.Pojomator; import org.pojomatic.annotations.*; +import org.pojomatic.diff.OnlyOnLeft; +import org.pojomatic.diff.OnlyOnRight; import org.pojomatic.diff.ValueDifference; import org.pojomatic.diff.DifferenceFromNull; import org.pojomatic.diff.DifferenceToNull; @@ -20,6 +22,8 @@ import org.pojomatic.formatter.DefaultPojoFormatter; import org.pojomatic.formatter.DefaultPropertyFormatter; +import com.google.common.collect.Sets; + public class PojomatorImplTest { private static Pojomator<ObjectProperty> OBJECT_PROPERTY_POJOMATOR = makePojomatorImpl(ObjectProperty.class); @@ -226,13 +230,19 @@ @Test public void testDiffNullInstance() { ObjectPairProperty other = new ObjectPairProperty("this", "that"); Differences actual = OBJECT_PAIR_PROPERTY_POJOMATOR.doDiff(null, other); + assertFalse(actual.areEqual()); assertTrue(actual instanceof DifferenceFromNull); + assertEquals(Sets.newHashSet(new OnlyOnRight("s", "this"), new OnlyOnRight("t", "that")), + Sets.newHashSet(actual.differences())); } @Test public void testDiffNullOther() { ObjectPairProperty instance = new ObjectPairProperty("this", "that"); Differences actual = OBJECT_PAIR_PROPERTY_POJOMATOR.doDiff(instance, null); + assertFalse(actual.areEqual()); assertTrue(actual instanceof DifferenceToNull); + assertEquals(Sets.newHashSet(new OnlyOnLeft("s", "this"), new OnlyOnLeft("t", "that")), + Sets.newHashSet(actual.differences())); } @Test public void testDiffNulls() { @@ -256,8 +266,8 @@ new ObjectPairProperty("this", "that"), new ObjectPairProperty("THIS", "that")); assertTrue(diffs instanceof PropertyDifferences); assertEquals( - Arrays.asList(new ValueDifference("s", "this", "THIS")), - ((PropertyDifferences) diffs).getDifferences()); + Sets.newHashSet(new ValueDifference("s", "this", "THIS")), + Sets.newHashSet(diffs.differences())); } @Test public void testDiffDifferentObjectsWithMultiplePropertiesDifferent() { @@ -265,17 +275,10 @@ new ObjectPairProperty("this", "that"), new ObjectPairProperty("THIS", "THAT")); assertEquals(PropertyDifferences.class, diffs.getClass()); assertEquals( - Arrays.asList(new ValueDifference("s", "this", "THIS"), new ValueDifference("t", "that", "THAT")), - ((PropertyDifferences) diffs).getDifferences()); + Sets.newHashSet(new ValueDifference("s", "this", "THIS"), new ValueDifference("t", "that", "THAT")), + Sets.newHashSet(diffs.differences())); } - @Test public void testDiffAgainstNull() { - ObjectPairProperty instance = new ObjectPairProperty("this", "that"); - Differences differences = OBJECT_PAIR_PROPERTY_POJOMATOR.doDiff(instance, null); - assertFalse(differences.areEqual()); - assertEquals(DifferenceToNull.class, differences.getClass()); - } - @Test public void testDiffAgainstWrongType() { Pojomator<?> pojomator = OBJECT_PAIR_PROPERTY_POJOMATOR; @SuppressWarnings("unchecked") Pojomator<Object> misCastPojomator = (Pojomator<Object>) pojomator; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-02-26 23:10:37
|
Revision: 196 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=196&view=rev Author: iroberts Date: 2010-02-26 23:10:31 +0000 (Fri, 26 Feb 2010) Log Message: ----------- fix indentation Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/site/apt/eclipse.apt Modified: trunk/PojomaticAll/Pojomatic/src/site/apt/eclipse.apt =================================================================== --- trunk/PojomaticAll/Pojomatic/src/site/apt/eclipse.apt 2010-02-26 16:37:07 UTC (rev 195) +++ trunk/PojomaticAll/Pojomatic/src/site/apt/eclipse.apt 2010-02-26 23:10:31 UTC (rev 196) @@ -10,9 +10,9 @@ with the following body: ------------------------ - @Override public boolean equals(Object other) { return Pojomatic.equals(this, other); } - @Override public String toString() { return Pojomatic.toString(this); } - @Override public int hashCode() { return Pojomatic.hashCode(this); } +@Override public boolean equals(Object other) { return Pojomatic.equals(this, other); } +@Override public String toString() { return Pojomatic.toString(this); } +@Override public int hashCode() { return Pojomatic.hashCode(this); } ${:import(org.pojomatic.Pojomatic)} ------------------------ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-02-26 16:37:13
|
Revision: 195 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=195&view=rev Author: iroberts Date: 2010-02-26 16:37:07 +0000 (Fri, 26 Feb 2010) Log Message: ----------- footloose and warning free Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java 2010-02-26 06:43:13 UTC (rev 194) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/ClassPropertiesTest.java 2010-02-26 16:37:07 UTC (rev 195) @@ -301,8 +301,8 @@ assertTrue( ClassProperties.forClass(Interface.class).isCompatibleForEquals(ChildOfInterface.class)); - @SubclassCannotOverrideEquals class A { @Property int x; } - class B extends A { @Property int y; } + @SubclassCannotOverrideEquals class A { @SuppressWarnings("unused") @Property int x; } + class B extends A { @SuppressWarnings("unused") @Property int y; } assertTrue(ClassProperties.forClass(A.class).isCompatibleForEquals(B.class)); assertFalse(ClassProperties.forClass(B.class).isCompatibleForEquals(A.class)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2010-02-26 06:43:20
|
Revision: 194 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=194&view=rev Author: chriswhansen Date: 2010-02-26 06:43:13 +0000 (Fri, 26 Feb 2010) Log Message: ----------- Rename test as well. Added Paths: ----------- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/ValueDifferenceTest.java Removed Paths: ------------- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceTest.java Deleted: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceTest.java 2010-02-26 06:27:06 UTC (rev 193) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceTest.java 2010-02-26 06:43:13 UTC (rev 194) @@ -1,25 +0,0 @@ -package org.pojomatic.diff; - -import static org.junit.Assert.*; - -import org.junit.Test; - -public class DifferenceTest { - private ValueDifference DIFFERENCE = new ValueDifference("foo", "this", "that"); - - @Test - public void testGetPropertyName() { - assertEquals("foo", DIFFERENCE.getPropertyName()); - } - - @Test - public void testGetLhs() { - assertEquals("this", DIFFERENCE.getLhs()); - } - - @Test - public void testGetRhs() { - assertEquals("that", DIFFERENCE.getRhs()); - } - -} Copied: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/ValueDifferenceTest.java (from rev 193, trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceTest.java) =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/ValueDifferenceTest.java (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/ValueDifferenceTest.java 2010-02-26 06:43:13 UTC (rev 194) @@ -0,0 +1,25 @@ +package org.pojomatic.diff; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ValueDifferenceTest { + private ValueDifference DIFFERENCE = new ValueDifference("foo", "this", "that"); + + @Test + public void testGetPropertyName() { + assertEquals("foo", DIFFERENCE.getPropertyName()); + } + + @Test + public void testGetLhs() { + assertEquals("this", DIFFERENCE.getLhs()); + } + + @Test + public void testGetRhs() { + assertEquals("that", DIFFERENCE.getRhs()); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2010-02-26 06:27:13
|
Revision: 193 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=193&view=rev Author: chriswhansen Date: 2010-02-26 06:27:06 +0000 (Fri, 26 Feb 2010) Log Message: ----------- Rename Difference to ValueDifference to reserve the name Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/PropertyDifferences.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/PropertyDifferencesTest.java trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java Added Paths: ----------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/ValueDifference.java Removed Paths: ------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java Deleted: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java 2010-02-26 00:40:22 UTC (rev 192) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java 2010-02-26 06:27:06 UTC (rev 193) @@ -1,46 +0,0 @@ -package org.pojomatic.diff; - -import org.pojomatic.Pojomatic; -import org.pojomatic.annotations.AutoProperty; - -@AutoProperty -public class Difference { - private final String propertyName; - private final Object lhs; - private final Object rhs; - - public Difference(String propertyName, Object lhs, Object rhs) { - this.propertyName = propertyName; - this.lhs = lhs; - this.rhs = rhs; - } - - public String getPropertyName() { - return propertyName; - } - - public Object getLhs() { - return lhs; - } - - public Object getRhs() { - return rhs; - } - - @Override - public boolean equals(Object obj) { - return Pojomatic.equals(this, obj); - } - - @Override - public int hashCode() { - return Pojomatic.hashCode(this); - } - - @Override - public String toString() { - //TODO - can we do better here? - return propertyName + ": {" + lhs + "} versus {" + rhs + "}"; - } - -} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/PropertyDifferences.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/PropertyDifferences.java 2010-02-26 00:40:22 UTC (rev 192) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/PropertyDifferences.java 2010-02-26 06:27:06 UTC (rev 193) @@ -8,14 +8,14 @@ public class PropertyDifferences implements Differences { @Property - private final List<Difference> differences; + private final List<ValueDifference> differences; /** * @param differences cannot be {@code null} or empty * @throws NullPointerException if {@code differences} is {@code null} * @throws IllegalArgumentException if {@code differences.isEmpty()} is {@code true} */ - public PropertyDifferences(List<Difference> differences) { + public PropertyDifferences(List<ValueDifference> differences) { if (differences == null) { throw new NullPointerException("list of differences is null"); } @@ -25,7 +25,7 @@ this.differences = Collections.unmodifiableList(differences); } - public List<Difference> getDifferences() { + public List<ValueDifference> getDifferences() { return differences; } Copied: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/ValueDifference.java (from rev 192, trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/Difference.java) =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/ValueDifference.java (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/diff/ValueDifference.java 2010-02-26 06:27:06 UTC (rev 193) @@ -0,0 +1,46 @@ +package org.pojomatic.diff; + +import org.pojomatic.Pojomatic; +import org.pojomatic.annotations.AutoProperty; + +@AutoProperty +public class ValueDifference { + private final String propertyName; + private final Object lhs; + private final Object rhs; + + public ValueDifference(String propertyName, Object lhs, Object rhs) { + this.propertyName = propertyName; + this.lhs = lhs; + this.rhs = rhs; + } + + public String getPropertyName() { + return propertyName; + } + + public Object getLhs() { + return lhs; + } + + public Object getRhs() { + return rhs; + } + + @Override + public boolean equals(Object obj) { + return Pojomatic.equals(this, obj); + } + + @Override + public int hashCode() { + return Pojomatic.hashCode(this); + } + + @Override + public String toString() { + //TODO - can we do better here? + return propertyName + ": {" + lhs + "} versus {" + rhs + "}"; + } + +} Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2010-02-26 00:40:22 UTC (rev 192) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2010-02-26 06:27:06 UTC (rev 193) @@ -9,7 +9,7 @@ import org.pojomatic.PropertyElement; import org.pojomatic.annotations.PojoFormat; import org.pojomatic.annotations.PropertyFormat; -import org.pojomatic.diff.Difference; +import org.pojomatic.diff.ValueDifference; import org.pojomatic.diff.DifferenceFromNull; import org.pojomatic.diff.DifferenceToNull; import org.pojomatic.diff.Differences; @@ -234,12 +234,12 @@ checkClass(instance, "instance"); checkClass(other, "other"); - List<Difference> differences = new ArrayList<Difference>(); + List<ValueDifference> differences = new ArrayList<ValueDifference>(); for (PropertyElement prop: classProperties.getEqualsProperties()) { final Object instanceValue = prop.getValue(instance); final Object otherValue = prop.getValue(other); if (!areValuesEqual(instanceValue, otherValue)) { - differences.add(new Difference(prop.getName(), instanceValue, otherValue)); + differences.add(new ValueDifference(prop.getName(), instanceValue, otherValue)); } } Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceTest.java 2010-02-26 00:40:22 UTC (rev 192) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/DifferenceTest.java 2010-02-26 06:27:06 UTC (rev 193) @@ -5,7 +5,7 @@ import org.junit.Test; public class DifferenceTest { - private Difference DIFFERENCE = new Difference("foo", "this", "that"); + private ValueDifference DIFFERENCE = new ValueDifference("foo", "this", "that"); @Test public void testGetPropertyName() { Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/PropertyDifferencesTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/PropertyDifferencesTest.java 2010-02-26 00:40:22 UTC (rev 192) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/diff/PropertyDifferencesTest.java 2010-02-26 06:27:06 UTC (rev 193) @@ -16,17 +16,17 @@ @Test(expected=IllegalArgumentException.class) public void testEmptyDifferences() { - new PropertyDifferences(Collections.<Difference>emptyList()); + new PropertyDifferences(Collections.<ValueDifference>emptyList()); } @Test public void testSingleDifferenceToString() { assertEquals( "[foo: {3} versus {4}]", - new PropertyDifferences(Arrays.asList(new Difference("foo", 3, 4))).toString()); + new PropertyDifferences(Arrays.asList(new ValueDifference("foo", 3, 4))).toString()); assertEquals( "[foo: {null} versus {4}]", - new PropertyDifferences(Arrays.asList(new Difference("foo", null, 4))).toString()); + new PropertyDifferences(Arrays.asList(new ValueDifference("foo", null, 4))).toString()); } @Test @@ -34,11 +34,11 @@ assertEquals( "[foo: {3} versus {4}, bar: {this} versus {that}]", new PropertyDifferences(Arrays.asList( - new Difference("foo", 3, 4), new Difference("bar", "this", "that"))).toString()); + new ValueDifference("foo", 3, 4), new ValueDifference("bar", "this", "that"))).toString()); } @Test public void testAreEqual() { - assertFalse(new PropertyDifferences(Arrays.asList(new Difference("foo", 3, 4))).areEqual()); + assertFalse(new PropertyDifferences(Arrays.asList(new ValueDifference("foo", 3, 4))).areEqual()); } } Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2010-02-26 00:40:22 UTC (rev 192) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2010-02-26 06:27:06 UTC (rev 193) @@ -12,7 +12,7 @@ import org.pojomatic.Pojomatic; import org.pojomatic.Pojomator; import org.pojomatic.annotations.*; -import org.pojomatic.diff.Difference; +import org.pojomatic.diff.ValueDifference; import org.pojomatic.diff.DifferenceFromNull; import org.pojomatic.diff.DifferenceToNull; import org.pojomatic.diff.Differences; @@ -256,7 +256,7 @@ new ObjectPairProperty("this", "that"), new ObjectPairProperty("THIS", "that")); assertTrue(diffs instanceof PropertyDifferences); assertEquals( - Arrays.asList(new Difference("s", "this", "THIS")), + Arrays.asList(new ValueDifference("s", "this", "THIS")), ((PropertyDifferences) diffs).getDifferences()); } @@ -265,7 +265,7 @@ new ObjectPairProperty("this", "that"), new ObjectPairProperty("THIS", "THAT")); assertEquals(PropertyDifferences.class, diffs.getClass()); assertEquals( - Arrays.asList(new Difference("s", "this", "THIS"), new Difference("t", "that", "THAT")), + Arrays.asList(new ValueDifference("s", "this", "THIS"), new ValueDifference("t", "that", "THAT")), ((PropertyDifferences) diffs).getDifferences()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-02-26 01:23:10
|
Revision: 192 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=192&view=rev Author: iroberts Date: 2010-02-26 00:40:22 +0000 (Fri, 26 Feb 2010) Log Message: ----------- Add a snippet for how to ease pojomatic use in eclipse Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/site/site.xml Added Paths: ----------- trunk/PojomaticAll/Pojomatic/src/site/apt/eclipse.apt Added: trunk/PojomaticAll/Pojomatic/src/site/apt/eclipse.apt =================================================================== --- trunk/PojomaticAll/Pojomatic/src/site/apt/eclipse.apt (rev 0) +++ trunk/PojomaticAll/Pojomatic/src/site/apt/eclipse.apt 2010-02-26 00:40:22 UTC (rev 192) @@ -0,0 +1,20 @@ + ------ + Using with eclipse + ------ + ------ + ------ + + + Adding an eclipse template for pojomatic can make pojomating a class even easier. Open up the + Preferences dialog, and then go to Java->Editor->Templates. Then add a template named "pojomatic" + with the following body: + +------------------------ + @Override public boolean equals(Object other) { return Pojomatic.equals(this, other); } + @Override public String toString() { return Pojomatic.toString(this); } + @Override public int hashCode() { return Pojomatic.hashCode(this); } +${:import(org.pojomatic.Pojomatic)} +------------------------ + + After that, to pojomate a class, simply add an <<<@AutoProperty>>> annotation to the class, and + insert the macro in the class body by typing "pojomatic" and hitting Control-space. Modified: trunk/PojomaticAll/Pojomatic/src/site/site.xml =================================================================== --- trunk/PojomaticAll/Pojomatic/src/site/site.xml 2010-02-26 00:25:17 UTC (rev 191) +++ trunk/PojomaticAll/Pojomatic/src/site/site.xml 2010-02-26 00:40:22 UTC (rev 192) @@ -3,6 +3,7 @@ <menu name="Overview"> <item name="Introduction" href="index.html"/> <item name="Changes" href="changes.html"/> + <item name="Eclipse" href="eclipse.html"/> </menu> <menu ref="reports"/> </body> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-02-26 01:22:07
|
Revision: 191 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=191&view=rev Author: iroberts Date: 2010-02-26 00:25:17 +0000 (Fri, 26 Feb 2010) Log Message: ----------- Forgot to commit test Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java Modified: trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2010-02-25 20:57:27 UTC (rev 190) +++ trunk/PojomaticAll/Pojomatic/src/test/java/org/pojomatic/internal/PojomatorImplTest.java 2010-02-26 00:25:17 UTC (rev 191) @@ -9,6 +9,7 @@ import java.util.List; import org.junit.Test; +import org.pojomatic.Pojomatic; import org.pojomatic.Pojomator; import org.pojomatic.annotations.*; import org.pojomatic.diff.Difference; @@ -337,6 +338,21 @@ assertFalse(pojomator.doEquals(new Impl1(), "not even in the right hierarchy")); } + @Test public void testToString() { + @SuppressWarnings("unused") + class SimplePojo { + @Property(policy=PojomaticPolicy.EQUALS) int x; + @Property(policy=PojomaticPolicy.HASHCODE_EQUALS) int y; + @Property(policy=PojomaticPolicy.TO_STRING) int z; + } + assertEquals( + "Pojomator for org.pojomatic.internal.PojomatorImplTest$1SimplePojo" + + " with equals properties {x,y}," + + " hashCodeProperties {y}," + + " and toStringProperties {z}", + Pojomatic.pojomator(SimplePojo.class).toString()); + } + @PojoFormat(SimplePojoFormatter.class) public static class FormattedObject { public FormattedObject(Object s) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <iro...@us...> - 2010-02-25 20:57:35
|
Revision: 190 http://pojomatic.svn.sourceforge.net/pojomatic/?rev=190&view=rev Author: iroberts Date: 2010-02-25 20:57:27 +0000 (Thu, 25 Feb 2010) Log Message: ----------- Add a toString method to Pojomator for debugging purposes. Modified Paths: -------------- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java 2010-02-25 16:45:45 UTC (rev 189) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/Pojomator.java 2010-02-25 20:57:27 UTC (rev 190) @@ -136,4 +136,14 @@ * @see #doEquals(Object, Object) */ Differences doDiff(T instance, T other); + + /** + * Return a simple String representation of this Pojomator. This is meant to aid in debugging + * which properties are being used for which purposes. The contents and format of this + * representation are subject to change. + * + * @return a simple String representation of this Pojomator. + */ + @Override + public String toString(); } Modified: trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java =================================================================== --- trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2010-02-25 16:45:45 UTC (rev 189) +++ trunk/PojomaticAll/Pojomatic/src/main/java/org/pojomatic/internal/PojomatorImpl.java 2010-02-25 20:57:27 UTC (rev 190) @@ -177,6 +177,33 @@ return result.toString(); } + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Pojomator for ").append(clazz.getName()).append(" with equals properties "); + propertiesList(builder, classProperties.getEqualsProperties()); + builder.append(", hashCodeProperties "); + propertiesList(builder, classProperties.getHashCodeProperties()); + builder.append(", and toStringProperties "); + propertiesList(builder, classProperties.getToStringProperties()); + return builder.toString(); + } + + private void propertiesList(StringBuilder builder, final Iterable<PropertyElement> properties) { + builder.append("{"); + boolean firstElement = true; + for (PropertyElement prop: properties) { + if (!firstElement) { + builder.append(","); + } + else { + firstElement = false; + } + builder.append(prop.getName()); + } + builder.append("}"); + } + private final Class<T> clazz; private final ClassProperties classProperties; private final List<FormattablePropertyElement> formattablePropertyElements = This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |