Skip to content

Commit 06bb965

Browse files
authored
Merge pull request eugenp#5661 from cror/substring-indexof
BAEL-2365: added 2 further examples with substring and indexOf
2 parents 002e934 + 129aa9d commit 06bb965

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

java-strings/src/test/java/com/baeldung/string/SubstringUnitTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,14 @@ public void givenAString_whenUsedSubstringWithIndexOf_ShouldReturnProperSubstrin
5959
Assert.assertEquals("United States of America", text.substring(text.indexOf('(') + 1, text.indexOf(')')));
6060
}
6161

62+
@Test
63+
public void givenAString_whenUsedSubstringWithLastIndexOf_ShouldReturnProperSubstring() {
64+
Assert.assertEquals("1984", text.substring(text.lastIndexOf('-') + 1, text.indexOf('.')));
65+
}
66+
67+
@Test
68+
public void givenAString_whenUsedSubstringWithIndexOfAString_ShouldReturnProperSubstring() {
69+
Assert.assertEquals("USA (United States of America)", text.substring(text.indexOf("USA"), text.indexOf(')') + 1));
70+
}
71+
6272
}

0 commit comments

Comments
 (0)