You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2003/08/26 20:39:53 UTC

cvs commit: incubator-geronimo/modules/common/src/test/org/apache/geronimo/common CounterTest.java DurationTest.java LongCounterTest.java

jdillon     2003/08/26 11:39:53

  Modified:    modules/common/src/java/org/apache/geronimo/common
                        Duration.java
  Added:       modules/common/src/test/org/apache/geronimo/common
                        CounterTest.java DurationTest.java
                        LongCounterTest.java
  Log:
   o Applied patch GERONIMO-23 (fixed error in o.a.g.common.Duration constants  + some unit tests)
  Brent Worden
  
  Revision  Changes    Path
  1.2       +9 -9      incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/Duration.java
  
  Index: Duration.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/common/src/java/org/apache/geronimo/common/Duration.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Duration.java	24 Aug 2003 20:51:22 -0000	1.1
  +++ Duration.java	26 Aug 2003 18:39:52 -0000	1.2
  @@ -94,14 +94,14 @@
           super(time.longValue());
       }
       
  -    public static final long ONE_YEAR = 2903040000L;
  -    public static final long ONE_MONTH = 241920000;
  -    public static final long ONE_WEEK = 60480000;
  -    public static final long ONE_DAY = 8640000;
  -    public static final long ONE_HOUR = 3600000;
  -    public static final long ONE_MINUTE = 600000;
  -    public static final long ONE_SECOND = 1000;
  -    public static final long ONE_MILLISECOND = 1;
  +    public static final long ONE_MILLISECOND =    1L;
  +    public static final long ONE_SECOND =      1000L * ONE_MILLISECOND;
  +    public static final long ONE_MINUTE =        60L * ONE_SECOND;
  +    public static final long ONE_HOUR =          60L * ONE_MINUTE;
  +    public static final long ONE_DAY =           24L * ONE_HOUR;
  +    public static final long ONE_WEEK =           7L * ONE_DAY;
  +    public static final long ONE_MONTH =          4L * ONE_WEEK;
  +    public static final long ONE_YEAR =          12L * ONE_MONTH;
       
       public String toString()
       {
  
  
  
  1.1                  incubator-geronimo/modules/common/src/test/org/apache/geronimo/common/CounterTest.java
  
  Index: CounterTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.common;
  
  import junit.framework.TestCase;
  
  /**
   * Unit test for {@link Counter} class.
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/26 18:39:53 $
   */
  public class CounterTest
      extends TestCase
  {
      public void testIncrement() {
          Counter c = new Counter();
          
          assertEquals(0, c.getCount());
          
          c.increment();
          c.increment();
          
          assertEquals(2, c.getCount());
      }
  
      public void testDecrement() {
          Counter c = new Counter(2);
          
          assertEquals(2, c.getCount());
          
          c.decrement();
          c.decrement();
          
          assertEquals(0, c.getCount());
      }
      
      public void testReset() {
          Counter c = new Counter(2);
          
          assertEquals(2, c.getCount());
          
          c.increment();
          c.increment();
          
          assertEquals(4, c.getCount());
          
          c.reset();
          
          assertEquals(0, c.getCount());
      }
      
      public void testEquals() {
          Counter first = new Counter();
          Counter second = new Counter(2);
          
          assertFalse(first.equals(second));
          
          first.increment();
          first.increment();
          
          assertTrue(first.equals(second));
      }
      
      public void testEqualsNull() {
          Counter first = new Counter();
          
          assertFalse(first.equals(null));
      }
  
      public void testEqualsOther() {
          Counter first = new Counter();
          
          assertFalse(first.equals(new Object()));
      }
      
      public void testMakeDirectionalIncreasing() {
          Counter increasing = Counter.makeDirectional(new Counter(), true);
          
          assertEquals(0, increasing.getCount());
          
          increasing.increment();
          increasing.increment();
  
          assertEquals(2, increasing.getCount());
          
          try {
              increasing.decrement();
              fail();
          } catch(UnsupportedOperationException ex){
              // success
          }
      }
      
      public void testMakeDirectionalDecreasing() {
          Counter decreasing = Counter.makeDirectional(new Counter(2), false);
          
          assertEquals(2, decreasing.getCount());
          
          decreasing.decrement();
          decreasing.decrement();
  
          assertEquals(0, decreasing.getCount());
          
          try {
              decreasing.increment();
              fail();
          } catch(UnsupportedOperationException ex){
              // success
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/common/src/test/org/apache/geronimo/common/DurationTest.java
  
  Index: DurationTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.common;
  
  import junit.framework.TestCase;
  
  /**
   * Unit test for {@link Duration} class.
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/26 18:39:53 $
   */
  public class DurationTest
      extends TestCase
  {
      public void testConstructorNull() {
          try {
              Duration d = new Duration(null);
              fail();
          } catch(NullPointerException ex){
              // success
          }
      }
      
      public void testConstructorPrimative() {
          Duration d = new Duration(1000L);
          assertEquals("1s", d.toString());
      }
      
      public void testConstructorNumber() {
          Duration d = new Duration(new Long(1000L));
          assertEquals("1s", d.toString());
      }
      
      public void testToStringMillisecond() {
          Duration d = new Duration(1L);
          assertEquals("1ms", d.toString());
      }
      
      public void testToStringMinute() {
          Duration d = new Duration(60L * 1000L);
          assertEquals("1m", d.toString());
      }
      
      public void testToStringHour() {
          Duration d = new Duration(60L * 60L * 1000L);
          assertEquals("1h", d.toString());
      }
      
      public void testToStringDay() {
          Duration d = new Duration(24L * 60L * 60L * 1000L);
          assertEquals("1d", d.toString());
      }
      
      public void testToStringWeek() {
          Duration d = new Duration(7L * 24L * 60L * 60L * 1000L);
          assertEquals("1w", d.toString());
      }
      
      public void testToStringOnes() {
          Duration d = new Duration(Duration.ONE_WEEK + Duration.ONE_DAY +
              Duration.ONE_HOUR + Duration.ONE_MINUTE + Duration.ONE_SECOND +
              Duration.ONE_MILLISECOND);
          assertEquals("1w:1d:1h:1m:1s:1ms", d.toString());
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/common/src/test/org/apache/geronimo/common/LongCounterTest.java
  
  Index: LongCounterTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.common;
  
  import junit.framework.TestCase;
  
  /**
   * Unit test for {@link LongCounter} class.
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/26 18:39:53 $
   */
  public class LongCounterTest
      extends TestCase
  {
      public void testIncrement() {
          LongCounter c = new LongCounter();
          
          assertEquals(0, c.getCount());
          
          c.increment();
          c.increment();
          
          assertEquals(2, c.getCount());
      }
  
      public void testDecrement() {
          LongCounter c = new LongCounter(2);
          
          assertEquals(2, c.getCount());
          
          c.decrement();
          c.decrement();
          
          assertEquals(0, c.getCount());
      }
      
      public void testReset() {
          LongCounter c = new LongCounter(2);
          
          assertEquals(2, c.getCount());
          
          c.increment();
          c.increment();
          
          assertEquals(4, c.getCount());
          
          c.reset();
          
          assertEquals(0, c.getCount());
      }
      
      public void testEquals() {
          LongCounter first = new LongCounter();
          LongCounter second = new LongCounter(2);
          
          assertFalse(first.equals(second));
          
          first.increment();
          first.increment();
          
          assertTrue(first.equals(second));
      }
      
      public void testEqualsNull() {
          LongCounter first = new LongCounter();
          
          assertFalse(first.equals(null));
      }
  
      public void testEqualsOther() {
          LongCounter first = new LongCounter();
          
          assertFalse(first.equals(new Object()));
      }
      
      public void testMakeDirectionalIncreasing() {
          LongCounter increasing = LongCounter.makeDirectional(new LongCounter(), true);
          
          assertEquals(0, increasing.getCount());
          
          increasing.increment();
          increasing.increment();
  
          assertEquals(2, increasing.getCount());
          
          try {
              increasing.decrement();
              fail();
          } catch(UnsupportedOperationException ex){
              // success
          }
      }
      
      public void testMakeDirectionalDecreasing() {
          LongCounter decreasing = LongCounter.makeDirectional(new LongCounter(2), false);
          
          assertEquals(2, decreasing.getCount());
          
          decreasing.decrement();
          decreasing.decrement();
  
          assertEquals(0, decreasing.getCount());
          
          try {
              decreasing.increment();
              fail();
          } catch(UnsupportedOperationException ex){
              // success
          }
      }
  }