View Javadoc
1   package org.apache.commons.jcs.engine.control;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.jcs.engine.behavior.IElementSerializer;
23  import org.apache.commons.jcs.utils.serialization.StandardSerializer;
24  
25  import java.io.IOException;
26  
27  /** For mocking. */
28  public class MockElementSerializer
29      implements IElementSerializer
30  {
31      /** test property */
32      private String testProperty;
33  
34      /** What's used in the background */
35      private final StandardSerializer serializer = new StandardSerializer();
36  
37      /** times out was called */
38      public int deSerializeCount = 0;
39  
40      /** times in was called */
41      public int serializeCount = 0;
42  
43      /**
44       * @param bytes
45       * @return Object
46       * @throws IOException
47       * @throws ClassNotFoundException
48       *
49       */
50      @Override
51      public <T> T deSerialize( byte[] bytes, ClassLoader loader )
52          throws IOException, ClassNotFoundException
53      {
54          deSerializeCount++;
55          return serializer.deSerialize( bytes, loader );
56      }
57  
58      /**
59       * @param obj
60       * @return byte[]
61       * @throws IOException
62       *
63       */
64      @Override
65      public <T> byte[] serialize( T obj )
66          throws IOException
67      {
68          serializeCount++;
69          return serializer.serialize( obj );
70      }
71  
72      /**
73       * @param testProperty
74       */
75      public void setTestProperty( String testProperty )
76      {
77          this.testProperty = testProperty;
78      }
79  
80      /**
81       * @return testProperty
82       */
83      public String getTestProperty()
84      {
85          return testProperty;
86      }
87  }