~ubuntu-branches/ubuntu/maverick/libcommons-compress-java/maverick

« back to all changes in this revision

Viewing changes to src/test/org/apache/commons/compress/archivers/zip/ZipShortTestCase.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-12-17 15:17:09 UTC
  • Revision ID: james.westby@ubuntu.com-20071217151709-dqfo6iq1zxyssgf6
Tags: upstream-0~svn604876
ImportĀ upstreamĀ versionĀ 0~svn604876

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Licensed to the Apache Software Foundation (ASF) under one
 
3
 * or more contributor license agreements.  See the NOTICE file
 
4
 * distributed with this work for additional information
 
5
 * regarding copyright ownership.  The ASF licenses this file
 
6
 * to you under the Apache License, Version 2.0 (the
 
7
 * "License"); you may not use this file except in compliance
 
8
 * with the License.  You may obtain a copy of the License at
 
9
 *
 
10
 * http://www.apache.org/licenses/LICENSE-2.0
 
11
 *
 
12
 * Unless required by applicable law or agreed to in writing,
 
13
 * software distributed under the License is distributed on an
 
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
15
 * KIND, either express or implied.  See the License for the
 
16
 * specific language governing permissions and limitations
 
17
 * under the License.
 
18
 */
 
19
 
 
20
package org.apache.commons.compress.archivers.zip;
 
21
 
 
22
import org.apache.commons.compress.archivers.zip.ZipShort;
 
23
 
 
24
import junit.framework.TestCase;
 
25
 
 
26
/**
 
27
 * JUnit 3 testcases for org.apache.tools.zip.ZipShort.
 
28
 *
 
29
 * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
 
30
 */
 
31
public class ZipShortTestCase
 
32
    extends TestCase
 
33
{
 
34
    public ZipShortTestCase( String name )
 
35
    {
 
36
        super( name );
 
37
    }
 
38
 
 
39
    /**
 
40
     * Test conversion to bytes.
 
41
     */
 
42
    public void testToBytes()
 
43
    {
 
44
        final ZipShort zipShort = new ZipShort( 0x1234 );
 
45
        byte[] result = zipShort.getBytes();
 
46
        assertEquals( "length getBytes", 2, result.length );
 
47
        assertEquals( "first byte getBytes", 0x34, result[ 0 ] );
 
48
        assertEquals( "second byte getBytes", 0x12, result[ 1 ] );
 
49
    }
 
50
 
 
51
    /**
 
52
     * Test conversion from bytes.
 
53
     */
 
54
    public void testFromBytes()
 
55
    {
 
56
        byte[] val = new byte[]{0x34, 0x12};
 
57
        final ZipShort zipShort = new ZipShort( val );
 
58
        assertEquals( "value from bytes", 0x1234, zipShort.getValue() );
 
59
    }
 
60
 
 
61
    /**
 
62
     * Test the contract of the equals method.
 
63
     */
 
64
    public void testEquals()
 
65
    {
 
66
        final ZipShort zipShort = new ZipShort( 0x1234 );
 
67
        final ZipShort zipShort2 = new ZipShort( 0x1234 );
 
68
        final ZipShort zipShort3 = new ZipShort( 0x5678 );
 
69
 
 
70
        assertTrue( "reflexive", zipShort.equals( zipShort ) );
 
71
 
 
72
        assertTrue( "works", zipShort.equals( zipShort2 ) );
 
73
        assertTrue( "works, part two", !zipShort.equals( zipShort3 ) );
 
74
 
 
75
        assertTrue( "symmetric", zipShort2.equals( zipShort ) );
 
76
 
 
77
        assertTrue( "null handling", !zipShort.equals( null ) );
 
78
        assertTrue( "non ZipShort handling", !zipShort.equals( new Integer( 0x1234 ) ) );
 
79
    }
 
80
 
 
81
    /**
 
82
     * Test sign handling.
 
83
     */
 
84
    public void testSign()
 
85
    {
 
86
        final ZipShort zipShort = new ZipShort( new byte[]{(byte)0xFF, (byte)0xFF} );
 
87
        assertEquals( 0x0000FFFF, zipShort.getValue() );
 
88
    }
 
89
}