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.CoreMatchers.nullValue;
21  import static org.hamcrest.MatcherAssert.assertThat;
22  
23  import org.junit.Test;
24  import org.junit.experimental.categories.Category;
25  
26  import de.smartics.testdoc.annotations.TestDocHint;
27  import de.smartics.testdoc.annotations.Uut;
28  import de.smartics.testdoc.categories.Technical;
29  
30  /**
31   * Tests {@link StringFunction#toHyphenVersion(String)}.
32   */
33  @Uut(type = StringFunction.class, method = "toHyphenVersion(String)")
34  public class StringFunctionToHyphenVersionTest
35  {
36    // ********************************* Fields *********************************
37  
38    // --- constants ------------------------------------------------------------
39  
40    // --- members --------------------------------------------------------------
41  
42    // ****************************** Inner Classes *****************************
43  
44    // ********************************* Methods ********************************
45  
46    // --- prepare --------------------------------------------------------------
47  
48    // --- helper ---------------------------------------------------------------
49  
50    @Test
51    @TestDocHint(sentence = "toHyphenVersion: null -> null", indexSortKey = "001")
52    public void returnsNullIfNullIsPassedAsArgument()
53    {
54      final String result = StringFunction.toHyphenVersion(null);
55      assertThat(result, is(nullValue()));
56    }
57  
58    @Test
59    @TestDocHint(sentence = "toHyphenVersion: \"\" -> \"\"", indexSortKey = "002")
60    public void returnsTheEmptyStringIfTheEmptyStringIsPassedAsArgument()
61    {
62      final String result = StringFunction.toHyphenVersion("");
63      assertThat(result, is(equalTo("")));
64    }
65  
66    @Test
67    @TestDocHint(sentence = "toHyphenVersion: \"abc\" -> \"abc\"",
68        indexSortKey = "003")
69    public void hyphenVersionOfAllLowerCaseInputIsUnmodified()
70    {
71      final String result = StringFunction.toHyphenVersion("abc"); // NOPMD
72      assertThat(result, is(equalTo("abc")));
73    }
74  
75    @Test
76    @TestDocHint(sentence = "toHyphenVersion: \"Abc\" -> \"abc\"",
77        indexSortKey = "004")
78    public void hyphenVersionOfFistLetterCapitalIsTransformedToAllLowerCase()
79    {
80      final String result = StringFunction.toHyphenVersion("Abc");
81      assertThat(result, is(equalTo("abc")));
82    }
83  
84    @Test
85    @TestDocHint(sentence = "toHyphenVersion: \"a\" -> \"a\"",
86        indexSortKey = "005")
87    @Category(Technical.class)
88    public void alsoWorksOnASingleLowerCaseLetter()
89    {
90      final String result = StringFunction.toHyphenVersion("a");
91      assertThat(result, is(equalTo("a")));
92    }
93  
94    @Test
95    @TestDocHint(sentence = "toHyphenVersion: \"A\" -> \"a\"",
96        indexSortKey = "006")
97    @Category(Technical.class)
98    public void alsoWorksOnASingleCapitalLetter()
99    {
100     final String result = StringFunction.toHyphenVersion("A");
101     assertThat(result, is(equalTo("a")));
102   }
103 
104   @Test
105   @TestDocHint(sentence = "toHyphenVersion: \"aBc\" -> \"a-bc\"",
106       indexSortKey = "010")
107   public void hyphensACapitalLetter()
108   {
109     final String result = StringFunction.toHyphenVersion("aBc");
110     assertThat(result, is(equalTo("a-bc")));
111   }
112 
113   @Test
114   @TestDocHint(
115       sentence = "toHyphenVersion: \"thisIsACamleCaseExample\" -> \"this-is-a-camle-case-example\"",
116       indexSortKey = "011")
117   public void hyphensMultipleCapitalLetter()
118   {
119     final String result =
120         StringFunction.toHyphenVersion("thisIsACamleCaseExample");
121     assertThat(result, is(equalTo("this-is-a-camle-case-example")));
122   }
123   // --- tests ----------------------------------------------------------------
124 
125 }