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 BlankArgumentException}.
31   */
32  @Category(Construction.class)
33  public class BlankArgumentExceptionTest
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 = BlankArgumentException.class, method = "BlankArgumentException(java.lang.String)")
53    public void allowsToSpecifyTheNameOfTheMissingArgument()
54    {
55      final String argumentName = "testArgument";
56      final BlankArgumentException uut = new BlankArgumentException(argumentName);
57  
58      assertThat(uut.getMessage(), containsString(argumentName));
59    }
60  
61    @Test
62    @Uut(type = BlankArgumentException.class, method = "BlankArgumentException(java.lang.String)")
63    public void allowsToLeaveOutTheNameOfTheMissingArgument()
64    {
65      final String argumentName = null;
66      final BlankArgumentException uut = new BlankArgumentException(argumentName);
67  
68      assertThat(uut.getMessage(), is(equalTo("Argument must not be blank.")));
69    }
70  
71    @Test
72    @Uut(type = BlankArgumentException.class, method = "BlankArgumentException()")
73    public void providesANoargsConstuctorAlthoughItsUseIsDiscouraged()
74    {
75      final BlankArgumentException uut = new BlankArgumentException();
76  
77      assertThat(uut.getMessage(), is(equalTo("Argument must not be blank.")));
78    }
79  }