commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r795908 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/fraction/BigFractionField.java test/org/apache/commons/math/fraction/BigFractionFieldTest.java
Date Mon, 20 Jul 2009 16:42:55 GMT
Author: luc
Date: Mon Jul 20 16:42:55 2009
New Revision: 795908

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

Added:
    commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/BigFractionFieldTest.java
  (with props)
Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/BigFractionField.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/BigFractionField.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/BigFractionField.java?rev=795908&r1=795907&r2=795908&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/BigFractionField.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/BigFractionField.java
Mon Jul 20 16:42:55 2009
@@ -31,8 +31,6 @@
  * @since 2.0
  */
 public class BigFractionField implements Field<BigFraction>, Serializable  {
-    // TODO: Add Serializable documentation
-    // TODO: Check Serializable implementation
 
     /** Serializable version identifier */
     private static final long serialVersionUID = -1699294557189741703L;
@@ -67,4 +65,12 @@
         private static final BigFractionField INSTANCE = new BigFractionField();
     }
 
+    /** 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/fraction/BigFractionFieldTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/BigFractionFieldTest.java?rev=795908&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/BigFractionFieldTest.java
(added)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/BigFractionFieldTest.java
Mon Jul 20 16:42:55 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.fraction;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.commons.math.TestUtils;
+import org.junit.Test;
+
+public class BigFractionFieldTest {
+
+    @Test
+    public void testZero() {
+        assertEquals(BigFraction.ZERO, BigFractionField.getInstance().getZero());
+    }
+
+    @Test
+    public void testOne() {
+        assertEquals(BigFraction.ONE, BigFractionField.getInstance().getOne());
+    }
+
+    @Test
+    public void testSerial() {
+        // deserializing the singleton should give the singleton itself back
+        BigFractionField field = BigFractionField.getInstance();
+        assertTrue(field == TestUtils.serializeAndRecover(field));
+    }
+
+}

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

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



Mime
View raw message