You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by bw...@apache.org on 2003/05/27 13:22:19 UTC

cvs commit: maven-new/core/src/test/org/apache/maven/util MD5SumTest.java IOUtilityTest.java

bwalding    2003/05/27 04:22:19

  Added:       core/src/test/org/apache/maven/util MD5SumTest.java
                        IOUtilityTest.java
  Log:
  Test cases for new classes / MD5Sum
  
  Revision  Changes    Path
  1.1                  maven-new/core/src/test/org/apache/maven/util/MD5SumTest.java
  
  Index: MD5SumTest.java
  ===================================================================
  /*
   * Created on 27/05/2003
   *
   * To change this generated comment go to 
   * Window>Preferences>Java>Code Generation>Code Template
   */
  package org.apache.maven.util;
  
  import java.io.File;
  
  import junit.framework.TestCase;
  
  /**
   * @author <a href="bwalding@jakarta.org">Ben Walding</a>
   * @version $Id: MD5SumTest.java,v 1.1 2003/05/27 11:22:19 bwalding Exp $
   */
  public class MD5SumTest extends TestCase
  {
      public void testEncode()
      {
          MD5Sum md5 = new MD5Sum();
          byte b[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  
          assertEquals("000102030405060708090a0b0c0d0e0f", md5.encode(b));
      }
  
      public void testGetBytes() throws Exception
      {
          String baseDir = System.getProperty("basedir");
  
          File testDir = new File(baseDir + "/src/test-input/org/apache/maven/util");
          testChecksum(new File(testDir, "md5sum-1.input"), "5df603f19b757269cd167fb0d27dca29");
          testChecksum(new File(testDir, "md5sum-2.input"), "4eff64aeb4eecc8e9fcb6dea7a04531e");
      }
      
      public void testChecksum(File input, String expected) throws Exception {
          MD5Sum sum = new MD5Sum();
  
          sum.setFile(input);
          sum.execute();
  
          assertEquals("md5(md5sum.input)", expected, sum.getChecksum());
      }
  
  }
  
  
  
  1.1                  maven-new/core/src/test/org/apache/maven/util/IOUtilityTest.java
  
  Index: IOUtilityTest.java
  ===================================================================
  package org.apache.maven.util;
  
  /* ====================================================================
   * 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 Maven" 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 Maven", 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/>.
   *
   * ====================================================================
   */
  
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.util.Random;
  
  import junit.framework.TestCase;
  
  /**
   * @author  Ben Walding
   * @version $Id: IOUtilityTest.java,v 1.1 2003/05/27 11:22:19 bwalding Exp $
   */
  public class IOUtilityTest extends TestCase
  {
  
      public void testTransferStream() throws Exception
      {
          testTransfer(0);
          testTransfer(1);
          testTransfer(500);
          testTransfer(1024);
          testTransfer(16385);
          testTransfer(1000000); //1 MILLLLIION BYTES!
      }
  
      public void testTransfer(int length) throws Exception
      {
          byte[] bufIn = new byte[length];
          //Want repeatability, but different datasets depending on length
          Random r = new Random();
          r.setSeed(length);
          r.nextBytes(bufIn);
  
          ByteArrayInputStream bais = new ByteArrayInputStream(bufIn);
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
  
          IOUtility.transferStream(bais, baos);
  
          byte[] bufOut = baos.toByteArray();
  
          assertEquals("input.length == output.length", bufIn.length, bufOut.length);
  
          for (int i = 0; i < bufIn.length; i++)
          {
              if (bufIn[i] != bufOut[i])
              {
                  fail("The input and output streams failed to match at position " + i + " (0 based)");
              }
          }
  
      }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org