1   /*
2    * $Id: NullResultTestCase.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.transformers;
12  
13  import org.mule.providers.NullPayload;
14  import org.mule.tck.AbstractTransformerTestCase;
15  import org.mule.umo.transformer.TransformerException;
16  import org.mule.umo.transformer.UMOTransformer;
17  
18  public class NullResultTestCase extends AbstractTransformerTestCase
19  {
20  
21      private final NullResultTransformer transformer = new NullResultTransformer();
22  
23      public Object getTestData()
24      {
25          return new Object();
26      }
27  
28      public Object getResultData()
29      {
30          return NullPayload.getInstance();
31      }
32  
33      public UMOTransformer getTransformer() throws Exception
34      {
35          return transformer;
36      }
37  
38      public UMOTransformer getRoundTripTransformer() throws Exception
39      {
40          return null;
41      }
42  
43      public void testNullNotExpected() throws Exception
44      {
45          transformer.setReturnClass(String.class);
46          try
47          {
48              testTransform();
49              fail("Transformer should have thrown an exception because the return class doesn't match the result.");
50          }
51          catch (TransformerException e)
52          {
53              // expected
54          }
55      }
56  
57      public static final class NullResultTransformer extends AbstractTransformer
58      {
59          public NullResultTransformer()
60          {
61              super();
62              this.registerSourceType(Object.class);
63              this.setReturnClass(NullPayload.class);
64          }
65  
66          public Object doTransform(Object src, String encoding) throws TransformerException
67          {
68              return null;
69          }
70      }
71  
72  }