View Javadoc

1   /*
2    * Copyright 2011-2012 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 de.smartics.util.adapt;
17  
18  import static org.hamcrest.CoreMatchers.equalTo;
19  import static org.hamcrest.CoreMatchers.is;
20  import static org.hamcrest.CoreMatchers.allOf;
21  import static org.hamcrest.Matchers.containsString;
22  import static org.junit.Assert.assertThat;
23  
24  import org.junit.Test;
25  import org.junit.experimental.categories.Category;
26  
27  import de.smartics.testdoc.annotations.Uut;
28  import de.smartics.testdoc.categories.type.Construction;
29  
30  /**
31   * Tests {@link AdapterException}.
32   */
33  @Category(Construction.class)
34  public class AdaptableExceptionTest
35  {
36    // ********************************* Fields *********************************
37  
38    // --- constants ------------------------------------------------------------
39  
40    // --- members --------------------------------------------------------------
41  
42    // ****************************** Inner Classes *****************************
43  
44    // ********************************* Methods ********************************
45  
46    // --- prepare --------------------------------------------------------------
47  
48    // --- helper ---------------------------------------------------------------
49  
50    // --- tests ----------------------------------------------------------------
51  
52    @SuppressWarnings("unchecked")
53    @Test
54    @Uut(type = AdaptableException.class,
55        method = "AdaptableException(java.lang.Class, java.lang.Class)")
56    public void allowsCreationWithoutRootCause()
57    {
58      final AdaptableException uut =
59          new AdaptableException(Class.class, Object.class);
60  
61      assertThat(uut.getMessage(),
62          allOf(containsString("Class"), containsString("Object")));
63      assertThat(Class.class.getName(), is(equalTo(uut.getInstanceType()
64          .getName())));
65      assertThat(Object.class.getName(), is(equalTo(uut.getAdapterType()
66          .getName())));
67    }
68  
69    @Test
70    @Uut(type = AdaptableException.class,
71        method = "AdaptableException(java.lang.Class, java.lang.Class)")
72    public void allowsCreationWithoutAnyTypeInformation()
73    {
74      final AdaptableException uut = new AdaptableException(null, null);
75  
76      assertThat(
77          uut.getMessage(),
78          is(equalTo("Instance of unknown type cannot be assigned to unknown type.")));
79    }
80  
81  }