/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/*
 * Test class for BinaryTCPClientImpl utility methods.  
 *
 */
package org.apache.jmeter.protocol.tcp.sampler;

import org.apache.jorphan.util.JOrphanUtils;

import junit.framework.TestCase;

public class BinaryTCPClientImplTest extends TestCase {

    public void testHexStringToByteArray() throws Exception {
        byte [] ba;
        ba = BinaryTCPClientImpl.hexStringToByteArray("");
        assertEquals(0, ba.length);
 
        ba = BinaryTCPClientImpl.hexStringToByteArray("00");
        assertEquals(1, ba.length);
        assertEquals(0, ba[0]);
 
        ba = BinaryTCPClientImpl.hexStringToByteArray("0f107f8081ff");
        assertEquals(6, ba.length);
        assertEquals(15,   ba[0]);
        assertEquals(16,   ba[1]);
        assertEquals(127,  ba[2]);
        assertEquals(-128, ba[3]);
        assertEquals(-127, ba[4]);
        assertEquals(-1,   ba[5]);
        
    }

    public void testLoopBack() throws Exception {
        assertEquals("0f107f8081ff", JOrphanUtils.baToHexString(BinaryTCPClientImpl.hexStringToByteArray("0f107f8081ff")));      
    }

}

@@ -913,16 +913,154 @@
 mpler;%0A%0A
+import java.io.ByteArrayInputStream;%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.InputStream;%0A%0Aimport junit.framework.TestCase;%0A%0A
 import o
@@ -1101,42 +1101,8 @@
 s;%0A%0A
-import junit.framework.TestCase;%0A%0A
 publ
@@ -1516,33 +1516,33 @@
 ByteArray(%220f107
-f
+F
 8081ff%22);%0A      
@@ -1793,201 +1793,1328 @@
     
-%0A    %7D%0A%0A    public void testLoopBack() throws Exception %7B%0A        assertEquals(%220f107f8081ff%22, JOrphanUtils.baToHexString(BinaryTCPClientImpl.hexStringToByteArray(%220f107f8081ff%22)));      %0A    %7D%0A
+try %7B%0A            ba = BinaryTCPClientImpl.hexStringToByteArray(%220f107f8081ff1%22);// odd chars%0A            fail(%22Expected IllegalArgumentException%22);%0A        %7D catch (IllegalArgumentException expected)%7B%0A            // ignored%0A        %7D%0A        try %7B%0A            ba = BinaryTCPClientImpl.hexStringToByteArray(%220f107xxf8081ff%22); // invalid%0A            fail(%22Expected IllegalArgumentException%22);%0A        %7D catch (IllegalArgumentException expected)%7B%0A            // ignored%0A        %7D%0A    %7D%0A%0A    public void testLoopBack() throws Exception %7B%0A        assertEquals(%220f107f8081ff%22, JOrphanUtils.baToHexString(BinaryTCPClientImpl.hexStringToByteArray(%220f107f8081ff%22)));      %0A    %7D%0A%0A    public void testRoundTrip() throws Exception %7B%0A        BinaryTCPClientImpl bi = new BinaryTCPClientImpl();%0A        InputStream is = null;%0A        try %7B%0A            bi.write(null, is);%0A            fail(%22Expected UnsupportedOperationException%22);%0A        %7D catch (UnsupportedOperationException expected) %7B%0A            // ignored%0A        %7D%0A        ByteArrayOutputStream os = new ByteArrayOutputStream();%0A        bi.write(os, %223132333435%22); // '12345'%0A        os.close();%0A        assertEquals(%2212345%22,os.toString());%0A        ByteArrayInputStream bis = new ByteArrayInputStream(os.toByteArray());%0A        assertEquals(%223132333435%22,bi.read(bis));%0A    %7D
 %0A%7D%0A

Add error tests and round-trip