1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 import de.smartics.testdoc.categories.type.Coverage;
30
31
32
33
34 @Uut(type = StringFunction.class, method = "chop(StringBuilder)")
35 public class StringFunctionChopTest
36 {
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 @Test
52 @TestDocHint(sentence = "chop: null -> null", indexSortKey = "001")
53 public void returnsNullIfNullIsPassedAsArgument()
54 {
55 final String result = StringFunction.chop(null);
56 assertThat(result, is(nullValue()));
57 }
58
59 @Test
60 @TestDocHint(sentence = "chop: \"\" -> \"\"", indexSortKey = "002")
61 public void returnsTheEmptyStringIfTheEmptyStringIsPassedAsArgument()
62 {
63 final String result = StringFunction.chop(new StringBuilder(""));
64 assertThat(result, is(equalTo("")));
65 }
66
67 @Test
68 @TestDocHint(sentence = "chop: \"x\" -> \"\"", indexSortKey = "003")
69 @Category(Technical.class)
70 public void chopsTheLastCharacterIfThereIsOne()
71 {
72 final String result = StringFunction.chop(new StringBuilder("x"));
73 assertThat(result, is(equalTo("")));
74 }
75
76 @Test
77 @TestDocHint(sentence = "chop: \"abc\" -> \"ab\"", indexSortKey = "004")
78 public void chopsTheLastCharacterIfNotEmpty()
79 {
80 final String result = StringFunction.chop(new StringBuilder("abc"));
81 assertThat(result, is(equalTo("ab")));
82 }
83
84 @Test
85 @TestDocHint(sentence = "chop: \"abc\\r\\n\" -> \"abc\"",
86 indexSortKey = "005")
87 public void chopsCarrigeReturnNewLineAsOneCharacter()
88 {
89 final String result = StringFunction.chop(new StringBuilder("abc\r\n"));
90 assertThat(result, is(equalTo("abc")));
91 }
92
93 @Test
94 @TestDocHint(sentence = "chop: \"\\r\" -> \"\"", indexSortKey = "006")
95 @Category(Technical.class)
96 public void chopsCarrigeReturnWithoutNewLineAsOneChar()
97 {
98 final String result = StringFunction.chop(new StringBuilder("\r"));
99 assertThat(result, is(equalTo("")));
100 }
101
102 @Test
103 @TestDocHint(sentence = "chop: \"\\r\\n\" -> \"\"", indexSortKey = "007")
104 @Category(Technical.class)
105 public void chopsCarrigeReturnNewLineAsOneCharacterIfTheyAreTheOnlyChars()
106 {
107 final String result = StringFunction.chop(new StringBuilder("\r\n"));
108 assertThat(result, is(equalTo("")));
109 }
110
111 @Test
112 @TestDocHint(sentence = "chop: \"\\n\" -> \"\"", indexSortKey = "008")
113 @Category(Technical.class)
114 public void handlesASingleNewlineCorrectly()
115 {
116 final String result = StringFunction.chop(new StringBuilder("\n"));
117 assertThat(result, is(equalTo("")));
118 }
119
120 @Test
121 @TestDocHint(sentence = "chop: \"ab\\n\" -> \"ab\"", indexSortKey = "009")
122 @Category(Coverage.class)
123 public void handlesLengthGreaterOneAndNewlineCorrectly()
124 {
125 final String result = StringFunction.chop(new StringBuilder("ab\n"));
126 assertThat(result, is(equalTo("ab")));
127 }
128
129 @Test
130 @TestDocHint(sentence = "chop: \"\\r\" -> \"\"", indexSortKey = "010")
131 @Category(Technical.class)
132 public void handlesASingleCarrigeReturnCorrectly()
133 {
134 final String result = StringFunction.chop(new StringBuilder("\r"));
135 assertThat(result, is(equalTo("")));
136 }
137
138
139
140 }