Package org.jpos.util

Source Code of org.jpos.util.ISOBinaryFieldDeepCopierTest

package org.jpos.util;

import java.util.Arrays;

import org.apache.commons.lang.ArrayUtils;
import org.jpos.iso.ISOBinaryField;

import junit.framework.TestCase;

/**
* $Revision: 23416 $
* $Date: 2007-03-14 00:14:09 +0000 (Wed, 14 Mar 2007) $
* $Author: nsmith $
*/
public final class ISOBinaryFieldDeepCopierTest extends TestCase {

    private ISOBinaryFieldDeepCopier copier;
   
    protected void setUp() throws Exception {
        copier = new ISOBinaryFieldDeepCopier();
    }
   
    public void testDoDeepCopyOfISOBinaryFieldWhenArrayContentChanges() throws Exception {
        byte[] fieldContentToBeUpdated = new byte[] {0x12, 0x34, 0x56, 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0};
        byte[] originalFieldContent = ArrayUtils.clone(fieldContentToBeUpdated);
       
        ISOBinaryField fieldWhichWillBeModified = new ISOBinaryField(42, fieldContentToBeUpdated);
        ISOBinaryField fieldWhoseValueShouldNotChange = (ISOBinaryField) copier.doDeepCopy(fieldWhichWillBeModified);
       
        fieldContentToBeUpdated[5] = 0x00;
        fieldWhichWillBeModified.setFieldNumber(41);
       
        assertNotNull(fieldWhichWillBeModified);
        assertNotNull(fieldWhoseValueShouldNotChange);
        assertNotSame(fieldWhichWillBeModified, fieldWhoseValueShouldNotChange);
        assertTrue(Arrays.equals(originalFieldContent, (byte[]) fieldWhoseValueShouldNotChange.getValue()));
        assertTrue(Arrays.equals(fieldContentToBeUpdated, (byte[]) fieldWhichWillBeModified.getValue()));
        ISOBinaryFieldEqualityTester.assertNotEquals(fieldWhichWillBeModified, fieldWhoseValueShouldNotChange);
    }
   
    public void testDoDeepCopyOfISOBinaryFieldWhenFieldContentChanges() throws Exception {
        byte[] originalFieldContent = new byte[] {0x12, 0x34, 0x56, 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0};
        byte[] newFieldContent = new byte[] {0x11, 0x33, 0x55, 0x77, (byte) 0x99, (byte) 0xBB, (byte) 0xDD, (byte) 0xFF};
       
        ISOBinaryField fieldWhichWillBeModified = new ISOBinaryField(42, originalFieldContent);
        ISOBinaryField fieldWhoseValueShouldNotChange = (ISOBinaryField) copier.doDeepCopy(fieldWhichWillBeModified);
       
        fieldWhichWillBeModified.setValue(newFieldContent);
        fieldWhichWillBeModified.setFieldNumber(41);
       
        assertNotNull(fieldWhichWillBeModified);
        assertNotNull(fieldWhoseValueShouldNotChange);
        assertNotSame(fieldWhichWillBeModified, fieldWhoseValueShouldNotChange);
        assertTrue(Arrays.equals(originalFieldContent, (byte[]) fieldWhoseValueShouldNotChange.getValue()));
        assertTrue(Arrays.equals(newFieldContent, (byte[]) fieldWhichWillBeModified.getValue()));
        ISOBinaryFieldEqualityTester.assertNotEquals(fieldWhichWillBeModified, fieldWhoseValueShouldNotChange);
    }
}
TOP

Related Classes of org.jpos.util.ISOBinaryFieldDeepCopierTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.