View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package test.de.smartics.properties.spi.core.util;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.is;
20  import static org.hamcrest.Matchers.notNullValue;
21  import static org.hamcrest.Matchers.nullValue;
22  
23  import java.lang.reflect.Method;
24  
25  import org.junit.Test;
26  import org.junit.experimental.categories.Category;
27  
28  import de.smartics.properties.spi.core.util.SerializableMethod;
29  import de.smartics.testdoc.annotations.Uut;
30  import de.smartics.testdoc.categories.Technical;
31  
32  /**
33   * Tests {@link SerializableMethod}.
34   */
35  @Uut(type = SerializableMethod.class)
36  public class SerializableMethodTest
37  {
38    // ********************************* Fields *********************************
39  
40    // --- constants ------------------------------------------------------------
41  
42    private static final Class<?>[] NO_PARAMETER = new Class<?>[0];
43  
44    private static final Method METHOD;
45  
46    static
47    {
48      try
49      {
50        METHOD = String.class.getMethod("toString", NO_PARAMETER);
51      }
52      catch (final Exception e)
53      {
54        throw new IllegalStateException("Cannot find method for test.", e);
55      }
56    }
57  
58    // --- members --------------------------------------------------------------
59  
60    // ****************************** Inner Classes *****************************
61  
62    // ********************************* Methods ********************************
63  
64    // --- prepare --------------------------------------------------------------
65  
66    // --- helper ---------------------------------------------------------------
67  
68    // --- tests ----------------------------------------------------------------
69  
70    @Test
71    public void allowsNullMethod()
72    {
73      final SerializableMethod uut = new SerializableMethod(null);
74      assertThat(uut.getMethod(), is(nullValue()));
75    }
76  
77    @Test
78    public void allowsToAccessWrappedMethod()
79    {
80      final SerializableMethod uut = new SerializableMethod(METHOD);
81      final Method method = uut.getMethod();
82      assertThat(method, is(METHOD));
83    }
84  
85    @Test
86    public void providesAStringRepresentation()
87    {
88      final SerializableMethod uut = new SerializableMethod(METHOD);
89      assertThat(uut.toString(), is(notNullValue()));
90    }
91  
92    @Test
93    @Category(Technical.class)
94    public void providesAStringRepresentationForNullMethod()
95    {
96      final SerializableMethod uut = new SerializableMethod(null);
97      assertThat(uut.toString(), is(nullValue()));
98    }
99  }