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
10
* http://www.apache.org/licenses/LICENSE-2.0
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
20
package org.apache.commons.compress.archivers.zip;
22
import org.apache.commons.compress.archivers.zip.ZipShort;
24
import junit.framework.TestCase;
27
* JUnit 3 testcases for org.apache.tools.zip.ZipShort.
29
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
31
public class ZipShortTestCase
34
public ZipShortTestCase( String name )
40
* Test conversion to bytes.
42
public void testToBytes()
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 ] );
52
* Test conversion from bytes.
54
public void testFromBytes()
56
byte[] val = new byte[]{0x34, 0x12};
57
final ZipShort zipShort = new ZipShort( val );
58
assertEquals( "value from bytes", 0x1234, zipShort.getValue() );
62
* Test the contract of the equals method.
64
public void testEquals()
66
final ZipShort zipShort = new ZipShort( 0x1234 );
67
final ZipShort zipShort2 = new ZipShort( 0x1234 );
68
final ZipShort zipShort3 = new ZipShort( 0x5678 );
70
assertTrue( "reflexive", zipShort.equals( zipShort ) );
72
assertTrue( "works", zipShort.equals( zipShort2 ) );
73
assertTrue( "works, part two", !zipShort.equals( zipShort3 ) );
75
assertTrue( "symmetric", zipShort2.equals( zipShort ) );
77
assertTrue( "null handling", !zipShort.equals( null ) );
78
assertTrue( "non ZipShort handling", !zipShort.equals( new Integer( 0x1234 ) ) );
84
public void testSign()
86
final ZipShort zipShort = new ZipShort( new byte[]{(byte)0xFF, (byte)0xFF} );
87
assertEquals( 0x0000FFFF, zipShort.getValue() );