Commit 25e25c89473dbd07d298fc4cf086ac5ace50714d
1 parent
d5646790
Exists in
master
Aumento na cobertura de testes.
Showing
1 changed file
with
30 additions
and
5 deletions
Show diff stats
impl/core/src/test/java/br/gov/frameworkdemoiselle/util/StringsTest.java
| @@ -70,6 +70,7 @@ public class StringsTest { | @@ -70,6 +70,7 @@ public class StringsTest { | ||
| 70 | testEqualsGetString("teste {0}", "teste 1", "1"); | 70 | testEqualsGetString("teste {0}", "teste 1", "1"); |
| 71 | testEqualsGetString("{0} teste", "Um teste", "Um"); | 71 | testEqualsGetString("{0} teste", "Um teste", "Um"); |
| 72 | testEqualsGetString("{1} testando {0}", "Apenas testando novamente", "novamente", "Apenas"); | 72 | testEqualsGetString("{1} testando {0}", "Apenas testando novamente", "novamente", "Apenas"); |
| 73 | + testEqualsGetString("{0} testando {1}", "Apenas testando {1}", "Apenas", null); | ||
| 73 | testEqualsGetString("testando {1} novamente", "testando isto novamente", "aquilo", "isto"); | 74 | testEqualsGetString("testando {1} novamente", "testando isto novamente", "aquilo", "isto"); |
| 74 | testEqualsGetString("teste", "teste", "1", "2"); | 75 | testEqualsGetString("teste", "teste", "1", "2"); |
| 75 | testEqualsGetString("teste {0}.", "teste \\.", "\\"); | 76 | testEqualsGetString("teste {0}.", "teste \\.", "\\"); |
| @@ -128,7 +129,12 @@ public class StringsTest { | @@ -128,7 +129,12 @@ public class StringsTest { | ||
| 128 | assertEquals("Ab", Strings.firstToUpper("ab")); | 129 | assertEquals("Ab", Strings.firstToUpper("ab")); |
| 129 | assertEquals("AB", Strings.firstToUpper("aB")); | 130 | assertEquals("AB", Strings.firstToUpper("aB")); |
| 130 | } | 131 | } |
| 131 | - | 132 | + |
| 133 | + @Test | ||
| 134 | + public void testToStringWhenObjectIsNull() { | ||
| 135 | + assertEquals("", Strings.toString(null)); | ||
| 136 | + } | ||
| 137 | + | ||
| 132 | @Test | 138 | @Test |
| 133 | public void testToString() throws SecurityException, NoSuchFieldException { | 139 | public void testToString() throws SecurityException, NoSuchFieldException { |
| 134 | 140 | ||
| @@ -138,24 +144,29 @@ public class StringsTest { | @@ -138,24 +144,29 @@ public class StringsTest { | ||
| 138 | private String name = "myName"; | 144 | private String name = "myName"; |
| 139 | 145 | ||
| 140 | private String lastname = "myLastname"; | 146 | private String lastname = "myLastname"; |
| 141 | - | 147 | + |
| 148 | + private String nullField = null; | ||
| 149 | + | ||
| 142 | @Ignore | 150 | @Ignore |
| 143 | private String ignore = "ignoreMe"; | 151 | private String ignore = "ignoreMe"; |
| 152 | + | ||
| 144 | } | 153 | } |
| 145 | 154 | ||
| 146 | mockStatic(Reflections.class); | 155 | mockStatic(Reflections.class); |
| 147 | Test test = new Test(); | 156 | Test test = new Test(); |
| 148 | 157 | ||
| 149 | expect(Reflections.getNonStaticDeclaredFields(test.getClass())).andReturn(Test.class.getDeclaredFields()); | 158 | expect(Reflections.getNonStaticDeclaredFields(test.getClass())).andReturn(Test.class.getDeclaredFields()); |
| 150 | - expect(Reflections.getFieldValue(EasyMock.anyObject(Field.class), EasyMock.anyObject())).andReturn("MyName"); | 159 | + expect(Reflections.getFieldValue(EasyMock.anyObject(Field.class), EasyMock.anyObject())).andReturn("myName"); |
| 151 | expect(Reflections.getFieldValue(EasyMock.anyObject(Field.class), EasyMock.anyObject())) | 160 | expect(Reflections.getFieldValue(EasyMock.anyObject(Field.class), EasyMock.anyObject())) |
| 152 | - .andReturn("MyLastname"); | 161 | + .andReturn("myLastname"); |
| 162 | + expect(Reflections.getFieldValue(EasyMock.anyObject(Field.class), EasyMock.anyObject())).andReturn(null); | ||
| 153 | expect(Reflections.getFieldValue(EasyMock.anyObject(Field.class), EasyMock.anyObject())).andReturn("Object"); | 163 | expect(Reflections.getFieldValue(EasyMock.anyObject(Field.class), EasyMock.anyObject())).andReturn("Object"); |
| 154 | 164 | ||
| 155 | replayAll(Reflections.class); | 165 | replayAll(Reflections.class); |
| 156 | 166 | ||
| 157 | // FIXME Este this$0=Object não deveria aparecer! | 167 | // FIXME Este this$0=Object não deveria aparecer! |
| 158 | - assertEquals("Test [name=MyName, lastname=MyLastname, this$0=Object]", Strings.toString(new Test())); | 168 | + assertEquals("Test [name=myName, lastname=myLastname, nullField=null, this$0=Object]", |
| 169 | + Strings.toString(new Test())); | ||
| 159 | 170 | ||
| 160 | verifyAll(); | 171 | verifyAll(); |
| 161 | } | 172 | } |
| @@ -192,4 +203,18 @@ public class StringsTest { | @@ -192,4 +203,18 @@ public class StringsTest { | ||
| 192 | assertEquals("{*}", Strings.insertBraces("*")); | 203 | assertEquals("{*}", Strings.insertBraces("*")); |
| 193 | assertEquals("{?}", Strings.insertBraces("?")); | 204 | assertEquals("{?}", Strings.insertBraces("?")); |
| 194 | } | 205 | } |
| 206 | + | ||
| 207 | + @Test | ||
| 208 | + public void testRemoveCharsWhenStringIsNull() { | ||
| 209 | + assertEquals(null, Strings.removeChars(null, 'a')); | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + @Test | ||
| 213 | + public void testRemoveCharsWhenStringIsNotNull() { | ||
| 214 | + String string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus lobortis."; | ||
| 215 | + string = Strings.removeChars(string, 'L', 'l'); | ||
| 216 | + assertEquals(-1, string.indexOf('L')); | ||
| 217 | + assertEquals(-1, string.indexOf('l')); | ||
| 218 | + } | ||
| 219 | + | ||
| 195 | } | 220 | } |