How to use endsWith method of org.hamcrest.core.StringEndsWith class

Best junit code snippet using org.hamcrest.core.StringEndsWith.endsWith

Run junit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

1package org.hamcrest.core;
3import org.hamcrest.AbstractMatcherTest;
4import org.hamcrest.Matcher;
6import static org.hamcrest.core.StringEndsWith.endsWith;
7import static org.hamcrest.core.StringEndsWith.endsWithIgnoringCase;
10public class StringEndsWithTest extends AbstractMatcherTest {
11    static final String EXCERPT = "EXCERPT";
12    final Matcher<String> stringEndsWith = endsWith(EXCERPT);
14    @Override
15    protected Matcher<?> createMatcher() {
16        return stringEndsWith;
17    }
19    public void testMatchesSubstringAtEnd() {
20        assertDoesNotMatch(stringEndsWith, EXCERPT + "END");
21        assertMatches(stringEndsWith, "START" + EXCERPT);
22        assertMatches(stringEndsWith, EXCERPT);
23        assertDoesNotMatch(stringEndsWith, EXCERPT.toLowerCase());
24        assertDoesNotMatch(stringEndsWith, "START" + EXCERPT + "END");
25        assertMatches(stringEndsWith, EXCERPT + EXCERPT);
26        assertDoesNotMatch(stringEndsWith, "EXCER");
28        assertMismatchDescription("was \"Something else\"", stringEndsWith, "Something else");
29        assertDescription("a string ending with \"EXCERPT\"", stringEndsWith);
30    }
32    public void testMatchesSubstringAtEndIngoringCase() {
33        final Matcher<String> ignoringCase = endsWithIgnoringCase("EXCERpt");
34        assertDoesNotMatch(ignoringCase, "eXCErpt" + "END");
35        assertMatches(ignoringCase, "START" + "EXceRpt");
36        assertMatches(ignoringCase, "EXcerPT");
37        assertDoesNotMatch(ignoringCase, "START" + "ExcERpt" + "END");
38        assertMatches(ignoringCase, "exCERpt" + "EXCerPt");
39        assertDoesNotMatch(ignoringCase, "ExcER");
41        assertMismatchDescription("was \"Something else\"", ignoringCase, "Something else");
42        assertDescription("a string ending with \"EXCERpt\" ignoring case", ignoringCase);
43    }
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in StringEndsWith

Trigger endsWith code on LambdaTest Cloud Grid

Execute automation tests with endsWith on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)