View Javadoc

1   /*
2    * $Id: StringByteArrayTransformersTestCase.java 20321 2010-11-24 15:21:24Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transformer.simple;
12  
13  import org.mule.api.transformer.Transformer;
14  import org.mule.transformer.AbstractTransformerTestCase;
15  
16  import java.util.Arrays;
17  
18  public class StringByteArrayTransformersTestCase extends AbstractTransformerTestCase
19  {
20  
21      public Transformer getTransformer() throws Exception
22      {
23          return new ObjectToByteArray();
24      }
25  
26      public Transformer getRoundTripTransformer() throws Exception
27      {
28          return new ByteArrayToObject();
29      }
30  
31      public Object getTestData()
32      {
33          return "Test";
34      }
35  
36      public Object getResultData()
37      {
38          return "Test".getBytes();
39      }
40  
41      @Override
42      public boolean compareResults(Object src, Object result)
43      {
44          if (src == null && result == null)
45          {
46              return true;
47          }
48          if (src == null || result == null)
49          {
50              return false;
51          }
52          return Arrays.equals((byte[]) src, (byte[]) result);
53      }
54  
55      @Override
56      public boolean compareRoundtripResults(Object src, Object result)
57      {
58          if (src == null && result == null)
59          {
60              return true;
61          }
62          if (src == null || result == null)
63          {
64              return false;
65          }
66          return src.equals(result);
67      }
68  }