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.lang;
17  
18  import static org.hamcrest.CoreMatchers.is;
19  import static org.hamcrest.MatcherAssert.assertThat;
20  
21  import org.junit.Test;
22  
23  import de.smartics.testdoc.annotations.TestDocHint;
24  import de.smartics.testdoc.annotations.Uut;
25  
26  /**
27   * Tests {@link StringFunction#isLastChar(String, char)}.
28   */
29  @Uut(type = StringFunction.class, method = "isLastChar(String, char)")
30  public class StringFunctionIsLastCharTest
31  {
32    // ********************************* Fields *********************************
33  
34    // --- constants ------------------------------------------------------------
35  
36    // --- members --------------------------------------------------------------
37  
38    // ****************************** Inner Classes *****************************
39  
40    // ********************************* Methods ********************************
41  
42    // --- prepare --------------------------------------------------------------
43  
44    // --- helper ---------------------------------------------------------------
45  
46    @Test
47    @TestDocHint(sentence = "isLastChar: null, {any} -> false",
48        indexSortKey = "001")
49    public void noCharacterIsTheLastCharOfTheNullString()
50    {
51      final boolean result = StringFunction.isLastChar(null, 'A');
52      assertThat(result, is(false));
53    }
54  
55    @Test
56    @TestDocHint(sentence = "isLastChar: \"\", {any} -> false",
57        indexSortKey = "002")
58    public void noCharacterIsTheLastCharOfTheEmptyString()
59    {
60      final boolean result = StringFunction.isLastChar("", 'A');
61      assertThat(result, is(false));
62    }
63  
64    @Test
65    @TestDocHint(sentence = "isLastChar: \"a\", 'a' -> true",
66        indexSortKey = "003")
67    public void theLastCharOfAOneCharacterStringMatches()
68    {
69      final boolean result = StringFunction.isLastChar("a", 'a');
70      assertThat(result, is(true));
71    }
72  
73    @Test
74    @TestDocHint(sentence = "isLastChar: \"a\", 'x' -> false",
75        indexSortKey = "004")
76    public void theLastCharOfAOneCharacterStringThatDoesNotMatch()
77    {
78      final boolean result = StringFunction.isLastChar("a", 'x');
79      assertThat(result, is(false));
80    }
81  
82    @Test
83    @TestDocHint(sentence = "isLastChar: \"abc\", 'c' -> true",
84        indexSortKey = "005")
85    public void theLastCharOfAStringThatMatches()
86    {
87      final boolean result = StringFunction.isLastChar("abc", 'c');
88      assertThat(result, is(true));
89    }
90  
91    @Test
92    @TestDocHint(sentence = "isLastChar: \"abc\", 'x' -> false",
93        indexSortKey = "006")
94    public void theLastCharOfAStringThatDoesNotMatch()
95    {
96      final boolean result = StringFunction.isLastChar("abc", 'x');
97      assertThat(result, is(false));
98    }
99  
100   // --- tests ----------------------------------------------------------------
101 
102 }