View Javadoc

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