以下の方法のJunitを書いています
誰かがこれに対する適切な解決策を提案できますか
Junitを実行した後、私は例外を下回っています
java.lang.ArrayIndexOutOfBoundsException: -84
at org.apache.commons.codec.binary.Base64.isBase64(Base64.java:137)
at org.apache.commons.codec.binary.Base64.isArrayByteBase64(Base64.java:163)
私のテストクラス
public class DecodeToObjectTest extends TestCase {
public void testDecode() {
try {
String data="data";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(data);
// convert String into InputStream
DecodeToObject.decode(new String(baos.toByteArray()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
私がテストする必要がある方法
public static
Object decode(
String input ) throws IOException,
ClassNotFoundException
{
Log log = LogFactory.getFactory().getInstance(
"com.avocent.cps.report.service" );
try
{
boolean c = Base64.isArrayByteBase64( input.getBytes() );
if(log.isDebugEnabled()){
log.debug( "DecodeToObject :Entering Helper Input: " + input ); }
byte[] data = Base64.decodeBase64( input.getBytes() );
ObjectInputStream ois = new ObjectInputStream(
new ByteArrayInputStream( data ) );
if(log.isDebugEnabled()){
log.debug( "DecodeToObject :Object Input stream ois: " + ois ); }
Object obj = null;
obj = ois.readObject();
if(log.isDebugEnabled()){
log.debug(
"DecodeToObject :Convering object to String: "
+ obj.toString() );
}
ois.close();
if(log.isDebugEnabled()){
log.debug(
"DecodeToObject :Decoded byte array to object successfully " );
}
return obj;
}
catch( ClassNotFoundException cnfe )
{
if(log.isErrorEnabled()){
log.error( "DecodeToObject : Error :" );
}
throw cnfe;
}
catch( IOException ioe )
{
if(log.isErrorEnabled()){
log.error( "DecodeToObject : Error :" );
}
throw ioe;
}
}