(no commit message)
[utils] / support / general / src / test / java / org / wamblee / persistence / JpaMergeSupportTest.java
index 3e92799bbe01c509bf706e65ae30e7240252f19a..f6ae20bb8598dd871c325511fa017f169fa4e109 100644 (file)
@@ -33,10 +33,10 @@ public class JpaMergeSupportTest {
 
     private static class X1 {
         @Id
-        int id;
+        private int id;
 
         @Version
-        int version;
+        private int version;
 
         private String value;
 
@@ -62,11 +62,16 @@ public class JpaMergeSupportTest {
             }
             return value.equals(((X1) aObj).getValue());
         }
+        
+        @Override
+        public int hashCode() {
+            return 0;
+        }
     }
 
     private static class X2 {
         @Id
-        int id;
+        private int id;
 
         private List<X1> list;
 
@@ -81,7 +86,7 @@ public class JpaMergeSupportTest {
 
     private static class X3 {
         @Id
-        int id;
+        private int id;
 
         private Set<X1> set;
 
@@ -96,7 +101,7 @@ public class JpaMergeSupportTest {
 
     private static class X4 {
         @Id
-        int id;
+        private int id;
 
         private Map<String, X1> map;
 
@@ -111,7 +116,7 @@ public class JpaMergeSupportTest {
 
     private static class X5 {
         @Id
-        int id;
+        private int id;
 
         private X1[] array;
 
@@ -128,6 +133,28 @@ public class JpaMergeSupportTest {
         }
     }
 
+    private static class X6 {
+        @Id
+        private int id;
+
+        public X1 getNotaGetter(String aMessage) {
+            return null;
+        }
+
+        public void getNotaGetter2() {
+
+        }
+    }
+
+    private static class X7 {
+        @Id
+        private int id;
+
+        private void getX() {
+            fail("Private getters should not be used");
+        }
+    }
+
     @Test
     public void testSimple() {
         X1 x = new X1();
@@ -360,4 +387,22 @@ public class JpaMergeSupportTest {
         JpaMergeSupport.merge(x, y);
     }
 
+    @Test
+    public void testNotAGetter() {
+        X6 x = new X6();
+        x.id = 100;
+        X6 y = new X6();
+
+        JpaMergeSupport.merge(x, y);
+        assertEquals(x.id, y.id);
+    }
+
+    @Test
+    public void testPrivateGetter() {
+        X7 x = new X7();
+        x.id = 100;
+        X7 y = new X7();
+        JpaMergeSupport.merge(x, y);
+        assertEquals(x.id, y.id);
+    }
 }