Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Hamcrest: equalToIgnoringCase: check equality of strings by ignoring case

By using 'equalToIgnoringCase' method, you can create a matcher of String that matches when the examined string is equal to the specified expected string, ignoring case.

Ex
String str = "abrakadabra";
assertThat("comparing strings by ignoring case ", str, equalToIgnoringCase("ABRAKADABRA"));

Find the below working application.

TestApp.java
package com.sample.model;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalToIgnoringCase;

import org.junit.Test;

public class TestApp {

@Test
public void testmethod() {
String str = "abrakadabra";

assertThat("comparing strings by ignoring case ", str, equalToIgnoringCase("ABRAKADABRA"));
assertThat("comparing strings by ignoring case ", str, equalToIgnoringCase("ABRAKAdabra"));
assertThat("comparing strings by ignoring case ", str, equalToIgnoringCase("abraKADABRA"));
assertThat("comparing strings by ignoring case ", str, equalToIgnoringCase("ABRAkaDABRA"));

}
}




Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Hamcrest: equalToIgnoringCase: check equality of strings by ignoring case

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×