commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r795911 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/complex/ComplexField.java test/org/apache/commons/math/complex/ComplexFieldTest.java
Date Mon, 20 Jul 2009 16:48:30 GMT
Author: luc
Date: Mon Jul 20 16:48:30 2009
New Revision: 795911

URL: http://svn.apache.org/viewvc?rev=795911&view=rev
Log:
handle serialization of ComplexField (which is a singleton) properly and test it

Added:
    commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexFieldTest.java
  (with props)
Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/complex/ComplexField.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/complex/ComplexField.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/complex/ComplexField.java?rev=795911&r1=795910&r2=795911&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/complex/ComplexField.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/complex/ComplexField.java Mon
Jul 20 16:48:30 2009
@@ -31,8 +31,6 @@
  * @since 2.0
  */
 public class ComplexField implements Field<Complex>, Serializable  {
-    // TODO: Add Serializable documentation
-    // TODO: Check Serializable implementation
 
     /** Serializable version identifier. */
     private static final long serialVersionUID = -6130362688700788798L;
@@ -67,4 +65,12 @@
         private static final ComplexField INSTANCE = new ComplexField();
     }
 
+    /** Handle deserialization of the singleton.
+     * @return the singleton instance
+     */
+    private Object readResolve() {
+        // return the singleton instance
+        return LazyHolder.INSTANCE; 
+    }
+
 }

Added: commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexFieldTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexFieldTest.java?rev=795911&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexFieldTest.java
(added)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexFieldTest.java
Mon Jul 20 16:48:30 2009
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.complex;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.commons.math.TestUtils;
+import org.junit.Test;
+
+public class ComplexFieldTest {
+
+    @Test
+    public void testZero() {
+        assertEquals(Complex.ZERO, ComplexField.getInstance().getZero());
+    }
+
+    @Test
+    public void testOne() {
+        assertEquals(Complex.ONE, ComplexField.getInstance().getOne());
+    }
+
+    @Test
+    public void testSerial() {
+        // deserializing the singleton should give the singleton itself back
+        ComplexField field = ComplexField.getInstance();
+        assertTrue(field == TestUtils.serializeAndRecover(field));
+    }
+
+}

Propchange: commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexFieldTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexFieldTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message