Best Assertj code snippet using org.assertj.core.internal.Strings.stringContains
Source:Strings.java
...213 checkIsNotEmpty(values);214 checkCharSequenceArrayDoesNotHaveNullElements(values);215 Set<CharSequence> notFound = new LinkedHashSet<>();216 for (CharSequence value : values) {217 if (!stringContains(actual, value)) {218 notFound.add(value);219 }220 }221 if (notFound.isEmpty()) return;222 if (notFound.size() == 1 && values.length == 1) {223 throw failures.failure(info, shouldContain(actual, values[0], comparisonStrategy));224 }225 throw failures.failure(info, shouldContain(actual, values, notFound, comparisonStrategy));226 }227 /**228 * Verifies that the given {@code CharSequence} contains only digits.229 *230 * @param info contains information about the assertion.231 * @param actual the given {@code CharSequence}.232 * @throws NullPointerException if {@code actual} is {@code null}.233 * @throws AssertionError if {@code actual} contains non-digit characters or contains no digits at all.234 */235 public void assertContainsOnlyDigits(AssertionInfo info, CharSequence actual) {236 assertNotNull(info, actual);237 if (actual.length() == 0) throw failures.failure(info, shouldContainOnlyDigits(actual));238 for (int index = 0; index < actual.length(); index++) {239 char character = actual.charAt(index);240 if (!isDigit(character)) throw failures.failure(info, shouldContainOnlyDigits(actual, character, index));241 }242 }243 private void checkIsNotNull(CharSequence... values) {244 if (values == null) throw arrayOfValuesToLookForIsNull();245 }246 private void checkIsNotEmpty(CharSequence... values) {247 if (values.length == 0) throw arrayOfValuesToLookForIsEmpty();248 }249 /**250 * Delegates to {@link ComparisonStrategy#stringContains(String, String)}251 */252 private boolean stringContains(CharSequence actual, CharSequence sequence) {253 return comparisonStrategy.stringContains(actual.toString(), sequence.toString());254 }255 /**256 * Verifies that the given {@code CharSequence} contains the given sequence, ignoring case considerations.257 * 258 * @param info contains information about the assertion.259 * @param actual the actual {@code CharSequence}.260 * @param sequence the sequence to search for.261 * @throws NullPointerException if the given sequence is {@code null}.262 * @throws AssertionError if the given {@code CharSequence} is {@code null}.263 * @throws AssertionError if the actual {@code CharSequence} does not contain the given sequence.264 */265 public void assertContainsIgnoringCase(AssertionInfo info, CharSequence actual, CharSequence sequence) {266 checkCharSequenceIsNotNull(sequence);267 assertNotNull(info, actual);268 if (!actual.toString().toLowerCase().contains(sequence.toString().toLowerCase()))269 throw failures.failure(info, shouldContainIgnoringCase(actual, sequence));270 }271 /**272 * Verifies that the given {@code CharSequence} does not contain the given sequence.273 * 274 * @param info contains information about the assertion.275 * @param actual the actual {@code CharSequence}.276 * @param sequence the sequence to search for.277 * @throws NullPointerException if the given sequence is {@code null}.278 * @throws AssertionError if the given {@code CharSequence} is {@code null}.279 * @throws AssertionError if the actual {@code CharSequence} contains the given sequence.280 */281 public void assertDoesNotContain(AssertionInfo info, CharSequence actual, CharSequence sequence) {282 checkCharSequenceIsNotNull(sequence);283 assertNotNull(info, actual);284 if (stringContains(actual, sequence))285 throw failures.failure(info, shouldNotContain(actual, sequence, comparisonStrategy));286 }287 private void checkCharSequenceIsNotNull(CharSequence sequence) {288 checkNotNull(sequence, "The char sequence to look for should not be null");289 }290 /**291 * Verifies that two {@code CharSequence}s are equal, ignoring case considerations.292 * 293 * @param info contains information about the assertion.294 * @param actual the actual {@code CharSequence}.295 * @param expected the expected {@code CharSequence}.296 * @throws AssertionError if the given {@code CharSequence}s are not equal.297 */298 public void assertEqualsIgnoringCase(AssertionInfo info, CharSequence actual, CharSequence expected) {299 if (!areEqualIgnoringCase(actual, expected)) throw failures.failure(info, shouldBeEqual(actual, expected));300 }301 /**302 * Verifies that two {@code CharSequence}s are not equal, ignoring case considerations.303 *304 * @param info contains information about the assertion.305 * @param actual the actual {@code CharSequence}.306 * @param expected the expected {@code CharSequence}.307 * @throws AssertionError if the given {@code CharSequence}s are equal ignoring case considerations.308 */309 public void assertNotEqualsIgnoringCase(AssertionInfo info, CharSequence actual, CharSequence expected) {310 if (areEqualIgnoringCase(actual, expected))311 throw failures.failure(info, shouldNotBeEqualIgnoringCase(actual, expected));312 }313 private boolean areEqualIgnoringCase(CharSequence actual, CharSequence expected) {314 if (actual == null) return expected == null;315 if (expected == null) return false;316 return actual.toString().equalsIgnoreCase(expected.toString());317 }318 /**319 * Verifies that two {@code CharSequence}s are equal, ignoring any changes in whitespace.320 *321 * @param info contains information about the assertion.322 * @param actual the actual {@code CharSequence}.323 * @param expected the expected {@code CharSequence}.324 * @throws AssertionError if the given {@code CharSequence}s are not equal.325 */326 public void assertEqualsIgnoringWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected) {327 if (!areEqualIgnoringWhitespace(actual, expected))328 throw failures.failure(info, shouldBeEqualIgnoringWhitespace(actual, expected));329 }330 /**331 * Verifies that two {@code CharSequence}s are not equal, ignoring any changes in whitespace.332 *333 * @param info contains information about the assertion.334 * @param actual the actual {@code CharSequence}.335 * @param expected the expected {@code CharSequence}.336 * @throws AssertionError if the given {@code CharSequence}s are equal.337 */338 public void assertNotEqualsIgnoringWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected) {339 if (areEqualIgnoringWhitespace(actual, expected))340 throw failures.failure(info, shouldNotBeEqualIgnoringWhitespace(actual, expected));341 }342 private boolean areEqualIgnoringWhitespace(CharSequence actual, CharSequence expected) {343 if (actual == null) return expected == null;344 checkCharSequenceIsNotNull(expected);345 return removeAllWhitespaces(actual).equals(removeAllWhitespaces(expected));346 }347 // same implementation as Hamcrest's IsEqualIgnoringWhiteSpace348 private String removeAllWhitespaces(CharSequence toBeStripped) {349 final StringBuilder result = new StringBuilder();350 boolean lastWasSpace = true;351 for (int i = 0; i < toBeStripped.length(); i++) {352 char c = toBeStripped.charAt(i);353 if (isWhitespace(c)) {354 if (!lastWasSpace) result.append(' ');355 lastWasSpace = true;356 } else {357 result.append(c);358 lastWasSpace = false;359 }360 }361 return result.toString().trim();362 }363 /**364 * Verifies that actual {@code CharSequence}s contains only once the given sequence.365 * 366 * @param info contains information about the assertion.367 * @param actual the actual {@code CharSequence}.368 * @param sequence the given {@code CharSequence}.369 * @throws NullPointerException if the given sequence is {@code null}.370 * @throws AssertionError if the given {@code CharSequence} is {@code null}.371 * @throws AssertionError if the actual {@code CharSequence} does not contains <b>only once</b> the given372 * {@code CharSequence}.373 */374 public void assertContainsOnlyOnce(AssertionInfo info, CharSequence actual, CharSequence sequence) {375 checkCharSequenceIsNotNull(sequence);376 assertNotNull(info, actual);377 int sequenceOccurencesInActual = countOccurences(sequence, actual);378 if (sequenceOccurencesInActual == 1) return;379 throw failures.failure(info,380 shouldContainOnlyOnce(actual, sequence, sequenceOccurencesInActual, comparisonStrategy));381 }382 /**383 * Count occurrences of sequenceToSearch in actual {@link CharSequence}.384 * 385 * @param sequenceToSearch the sequence to search in in actual {@link CharSequence}.386 * @param actual the {@link CharSequence} to search occurrences in.387 * @return the number of occurrences of sequenceToSearch in actual {@link CharSequence}.388 */389 private int countOccurences(CharSequence sequenceToSearch, CharSequence actual) {390 String strToSearch = sequenceToSearch.toString();391 String strActual = actual.toString();392 int occurences = 0;393 for (int i = 0; i <= (strActual.length() - strToSearch.length()); i++) {394 if (comparisonStrategy.areEqual(strActual.substring(i, i + sequenceToSearch.length()), strToSearch)) {395 occurences++;396 }397 }398 return occurences;399 }400 /**401 * Verifies that the given {@code CharSequence} starts with the given prefix.402 * 403 * @param info contains information about the assertion.404 * @param actual the actual {@code CharSequence}.405 * @param prefix the given prefix.406 * @throws NullPointerException if the given sequence is {@code null}.407 * @throws AssertionError if the given {@code CharSequence} is {@code null}.408 * @throws AssertionError if the actual {@code CharSequence} does not start with the given prefix.409 */410 public void assertStartsWith(AssertionInfo info, CharSequence actual, CharSequence prefix) {411 failIfPrefixIsNull(prefix);412 assertNotNull(info, actual);413 if (!comparisonStrategy.stringStartsWith(actual.toString(), prefix.toString()))414 throw failures.failure(info, shouldStartWith(actual, prefix, comparisonStrategy));415 }416 /**417 * Verifies that the given {@code CharSequence} does not start with the given prefix.418 *419 * @param info contains information about the assertion.420 * @param actual the actual {@code CharSequence}.421 * @param prefix the given prefix.422 * @throws NullPointerException if the given sequence is {@code null}.423 * @throws AssertionError if the given {@code CharSequence} is {@code null}.424 * @throws AssertionError if the actual {@code CharSequence} starts with the given prefix.425 * @author Michal Kordas426 */427 public void assertDoesNotStartWith(AssertionInfo info, CharSequence actual, CharSequence prefix) {428 failIfPrefixIsNull(prefix);429 assertNotNull(info, actual);430 if (comparisonStrategy.stringStartsWith(actual.toString(), prefix.toString()))431 throw failures.failure(info, shouldNotStartWith(actual, prefix, comparisonStrategy));432 }433 private static void failIfPrefixIsNull(CharSequence prefix) {434 checkNotNull(prefix, "The given prefix should not be null");435 }436 /**437 * Verifies that the given {@code CharSequence} ends with the given suffix.438 * 439 * @param info contains information about the assertion.440 * @param actual the actual {@code CharSequence}.441 * @param suffix the given suffix.442 * @throws NullPointerException if the given sequence is {@code null}.443 * @throws AssertionError if the given {@code CharSequence} is {@code null}.444 * @throws AssertionError if the actual {@code CharSequence} does not end with the given suffix.445 */446 public void assertEndsWith(AssertionInfo info, CharSequence actual, CharSequence suffix) {447 failIfSuffixIsNull(suffix);448 assertNotNull(info, actual);449 if (!comparisonStrategy.stringEndsWith(actual.toString(), suffix.toString()))450 throw failures.failure(info, shouldEndWith(actual, suffix, comparisonStrategy));451 }452 /**453 * Verifies that the given {@code CharSequence} does not end with the given suffix.454 *455 * @param info contains information about the assertion.456 * @param actual the actual {@code CharSequence}.457 * @param suffix the given suffix.458 * @throws NullPointerException if the given sequence is {@code null}.459 * @throws AssertionError if the given {@code CharSequence} is {@code null}.460 * @throws AssertionError if the actual {@code CharSequence} ends with the given suffix.461 * @author Michal Kordas462 */463 public void assertDoesNotEndWith(AssertionInfo info, CharSequence actual, CharSequence suffix) {464 failIfSuffixIsNull(suffix);465 assertNotNull(info, actual);466 if (comparisonStrategy.stringEndsWith(actual.toString(), suffix.toString()))467 throw failures.failure(info, shouldNotEndWith(actual, suffix, comparisonStrategy));468 }469 private static void failIfSuffixIsNull(CharSequence suffix) {470 checkNotNull(suffix, "The given suffix should not be null");471 }472 /**473 * Verifies that the given {@code CharSequence} matches the given regular expression.474 * 475 * @param info contains information about the assertion.476 * @param actual the given {@code CharSequence}.477 * @param regex the regular expression to which the actual {@code CharSequence} is to be matched.478 * @throws NullPointerException if the given pattern is {@code null}.479 * @throws PatternSyntaxException if the regular expression's syntax is invalid.480 * @throws AssertionError if the given {@code CharSequence} is {@code null}.481 * @throws AssertionError if the actual {@code CharSequence} does not match the given regular expression.482 */483 public void assertMatches(AssertionInfo info, CharSequence actual, CharSequence regex) {484 checkRegexIsNotNull(regex);485 assertNotNull(info, actual);486 if (!Pattern.matches(regex.toString(), actual)) throw failures.failure(info, shouldMatch(actual, regex));487 }488 /**489 * Verifies that the given {@code CharSequence} does not match the given regular expression.490 * 491 * @param info contains information about the assertion.492 * @param actual the given {@code CharSequence}.493 * @param regex the regular expression to which the actual {@code CharSequence} is to be matched.494 * @throws NullPointerException if the given pattern is {@code null}.495 * @throws PatternSyntaxException if the regular expression's syntax is invalid.496 * @throws AssertionError if the given {@code CharSequence} is {@code null}.497 * @throws AssertionError if the actual {@code CharSequence} matches the given regular expression.498 */499 public void assertDoesNotMatch(AssertionInfo info, CharSequence actual, CharSequence regex) {500 checkRegexIsNotNull(regex);501 assertNotNull(info, actual);502 if (Pattern.matches(regex.toString(), actual)) throw failures.failure(info, shouldNotMatch(actual, regex));503 }504 private void checkRegexIsNotNull(CharSequence regex) {505 if (regex == null) throw patternToMatchIsNull();506 }507 /**508 * Verifies that the given {@code CharSequence} matches the given regular expression.509 * 510 * @param info contains information about the assertion.511 * @param actual the given {@code CharSequence}.512 * @param pattern the regular expression to which the actual {@code CharSequence} is to be matched.513 * @throws NullPointerException if the given pattern is {@code null}.514 * @throws AssertionError if the given {@code CharSequence} is {@code null}.515 * @throws AssertionError if the given {@code CharSequence} does not match the given regular expression.516 */517 public void assertMatches(AssertionInfo info, CharSequence actual, Pattern pattern) {518 checkIsNotNull(pattern);519 assertNotNull(info, actual);520 if (!pattern.matcher(actual).matches()) throw failures.failure(info, shouldMatch(actual, pattern.pattern()));521 }522 /**523 * Verifies that the given {@code CharSequence} does not match the given regular expression.524 * 525 * @param info contains information about the assertion.526 * @param actual the given {@code CharSequence}.527 * @param pattern the regular expression to which the actual {@code CharSequence} is to be matched.528 * @throws NullPointerException if the given pattern is {@code null}.529 * @throws AssertionError if the given {@code CharSequence} matches the given regular expression.530 */531 public void assertDoesNotMatch(AssertionInfo info, CharSequence actual, Pattern pattern) {532 checkIsNotNull(pattern);533 if (!(actual == null || !pattern.matcher(actual).matches()))534 throw failures.failure(info, shouldNotMatch(actual, pattern.pattern()));535 }536 private void checkIsNotNull(Pattern pattern) {537 if (pattern == null) throw patternToMatchIsNull();538 }539 private NullPointerException patternToMatchIsNull() {540 return new NullPointerException("The regular expression pattern to match should not be null");541 }542 private void assertNotNull(AssertionInfo info, CharSequence actual) {543 Objects.instance().assertNotNull(info, actual);544 }545 public void assertContainsSequence(AssertionInfo info, CharSequence actual, CharSequence[] sequence) {546 assertNotNull(info, actual);547 checkIsNotNull(sequence);548 checkIsNotEmpty(sequence);549 checkCharSequenceArrayDoesNotHaveNullElements(sequence);550 Set<CharSequence> notFound = new LinkedHashSet<>();551 for (CharSequence value : sequence) {552 if (!stringContains(actual, value)) notFound.add(value);553 }554 if (!notFound.isEmpty()) {555 // don't bother looking for a sequence, some of the sequence elements were not found !556 if (notFound.size() == 1 && sequence.length == 1) {557 throw failures.failure(info, shouldContain(actual, sequence[0], comparisonStrategy));558 }559 throw failures.failure(info, shouldContain(actual, sequence, notFound, comparisonStrategy));560 }561 // we have found all the given values but were they in the expected order ?562 if (sequence.length == 1) return; // no order check needed for a one element sequence563 // convert all to one char CharSequence list to ease comparison564 String strActual = actual.toString();565 for (int i = 1; i < sequence.length; i++) {566 int indexOfCurrentSequenceValue = indexOf(strActual, sequence[i - 1].toString());567 int indexOfNextSequenceValue = indexOf(strActual, sequence[i].toString());568 if (indexOfCurrentSequenceValue > indexOfNextSequenceValue) {569 throw failures.failure(info, shouldContainSequence(actual, sequence, i-1, comparisonStrategy));570 }571 // get rid of the start of String to properly handle duplicate sequence values572 // ex: "a-b-c" and sequence "a", "-", "b", "-", "c" would fail as the second "-" would be found before "b"573 strActual = strActual.substring(indexOfCurrentSequenceValue + 1);574 }575 }576 private int indexOf(String string, String toFind) {577 for (int i = 0; i < string.length(); i++) {578 if (comparisonStrategy.stringStartsWith(string.substring(i), toFind)) return i;579 }580 return -1;581 }582 public void assertXmlEqualsTo(AssertionInfo info, CharSequence actualXml, CharSequence expectedXml) {583 // check that actual and expected XML CharSequence are not null.584 // we consider that null values don't make much sense when you want to compare XML document as String/CharSequence.585 checkCharSequenceIsNotNull(expectedXml);586 assertNotNull(info, actualXml);587 // we only use default comparison strategy, it does not make sense to use a specific comparison strategy588 final String formattedActualXml = xmlPrettyFormat(actualXml.toString());589 final String formattedExpectedXml = xmlPrettyFormat(expectedXml.toString());590 if (!comparisonStrategy.areEqual(formattedActualXml, formattedExpectedXml))591 throw failures.failure(info, shouldBeEqual(formattedActualXml, formattedExpectedXml, comparisonStrategy,592 info.representation()));593 }594 public void assertIsSubstringOf(AssertionInfo info, CharSequence actual, CharSequence sequence) {595 assertNotNull(info, actual);596 checkNotNull(sequence, "Expecting CharSequence not to be null");597 if (stringContains(sequence.toString(), actual.toString())) return;598 throw failures.failure(info, shouldBeSubstring(actual, sequence, comparisonStrategy));599 }600 /**601 * Verifies that the given {@code CharSequence} contains the given regular expression.602 * 603 * @param info contains information about the assertion.604 * @param actual the given {@code CharSequence}.605 * @param regex the regular expression to find in the actual {@code CharSequence}.606 * @throws NullPointerException if the given pattern is {@code null}.607 * @throws PatternSyntaxException if the regular expression's syntax is invalid.608 * @throws AssertionError if the given {@code CharSequence} is {@code null}.609 * @throws AssertionError if the actual {@code CharSequence} does not contain the given regular expression.610 */611 public void assertContainsPattern(AssertionInfo info, CharSequence actual, CharSequence regex) {...
stringContains
Using AI Code Generation
1import org.assertj.core.api.Assertions;2import org.assertj.core.internal.Strings;3public class StringContainsTest {4 public static void main(String[] args) {5 String str1 = "Hello World";6 String str2 = "Hello";7 Strings strings = new Strings();8 Assertions.assertThat(strings.stringContains(str1, str2)).isTrue();9 Assertions.assertThat(strings.stringContains(str2, str1)).isFalse();10 }11}12[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ assertj ---13[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ assertj ---14[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ assertj ---15[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ assertj ---16[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ assertj ---
stringContains
Using AI Code Generation
1assertThat("foo").isNotNull();2assertThat("foo").isNotNull().isNotEmpty().hasSize(3).contains("o");3assertThat("foo").isNotNull().isNotEmpty().hasSize(3).contains("o").doesNotContain("a");4assertThat("foo").isNotNull().isNotEmpty().hasSize(3).contains("o").doesNotContain("a").startsWith("f").endsWith("o");5assertThat("foo").isNotNull().isNotEmpty().hasSize(3).contains("o").doesNotContain("a").startsWith("f").endsWith("o").matches("f..");6assertThat("foo").isNotNull().isNotEmpty().hasSize(3).contains("o").doesNotContain("a").startsWith("f").endsWith("o").matches("f..").doesNotMatch("a..");7assertThat("foo").isNotNull().isNotEmpty().hasSize(3).contains("o").doesNotContain("a").startsWith("f").endsWith("o").matches("f..").doesNotMatch("a..").isEqualTo("foo");8assertThat("foo").isNotNull().isNotEmpty().hasSize(3).contains("o").doesNotContain("a").startsWith("f").endsWith("o").matches("f..").doesNotMatch("a..").isEqualTo("foo").isEqualToIgnoringCase("FOO");9assertThat("foo").isNotNull().isNotEmpty().hasSize(3).contains("o").doesNotContain("a").startsWith("f").endsWith("o").matches("f..").doesNotMatch("a..").isEqualTo("foo").isEqualToIgnoringCase("FOO").isNotEqualTo("bar");10assertThat("foo").isNotNull().isNotEmpty().hasSize(3).contains("o").doesNotContain("a").startsWith("f").endsWith("o").matches("f..").doesNotMatch("a..").isEqualTo("foo").isEqualToIgnoringCase("FOO").isNotEqualTo("bar").isIn("foo", "bar");11assertThat("foo").isNotNull().isNotEmpty().hasSize(3).contains("o").doesNotContain("a").startsWith("f").endsWith("o").matches("f..").doesNotMatch("a..").isEqualTo("foo").isEqualToIgnoringCase("FOO").isNotEqualTo("bar").isIn("foo", "bar").isNotIn("a", "b");12assertThat("foo
stringContains
Using AI Code Generation
1import org.assertj.core.api.Assertions;2import org.assertj.core.internal.Strings;3Strings strings = new Strings();4String str1 = "This is a test string";5String str2 = "test";6Assertions.assertThat(strings.stringContains(str1, str2)).isTrue();7Assertions.assertThat(strings.stringContains(str1, "not")).isFalse();
stringContains
Using AI Code Generation
1assertThat("foo").as("check String contains another String")2 .satisfies(s -> assertThat(s).contains("oo"));3assertThat("foo").as("check String contains another String")4 .satisfies(s -> assertThat(s).doesNotContain("bar"));5assertThat("foo").as("check String contains another String")6 .satisfies(s -> assertThat(s).containsIgnoringCase("FOO"));7assertThat("foo").as("check String contains another String")8 .satisfies(s -> assertThat(s).containsOnlyOnce("o"));9assertThat("foo").as("check String contains another String")10 .satisfies(s -> assertThat(s).startsWith("f"));11assertThat("foo").as("check String contains another String")12 .satisfies(s -> assertThat(s).endsWith("o"));13assertThat("foo").as("check String contains another String")14 .satisfies(s -> assertThat(s).matches("f.*"));15assertThat("foo").as("check String contains another String")16 .satisfies(s -> assertThat(s).doesNotMatch("bar"));17assertThat("foo").as("check String contains another String")18 .satisfies(s -> assertThat(s).isEqualToIgnoringCase("FOO"));19assertThat("foo").as("check String contains another String")20 .satisfies(s -> assertThat(s).isEqualToIgnoringWhitespace("f o o"));21assertThat("foo").as("check String contains another String")22 .satisfies(s -> assertThat(s).containsSequence("o", "o"));23assertThat("foo").as("check String contains another String")24 .satisfies(s -> assertThat(s).containsPattern("f.*"));25assertThat("foo").as("check String contains another String")26 .satisfies(s -> assertThat(s).doesNotContainPattern("bar"));27assertThat("foo").as("check String contains another String")28 .satisfies(s -> assertThat(s).containsPattern("f.*").doesNotContainPattern("bar"));29assertThat("foo").as("check String contains another String")30 .satisfies(s -> assertThat(s).hasSameSizeAs("bar"));31assertThat("foo").as("check String contains another String")32 .satisfies(s -> assertThat(s).hasSize(3));33assertThat("foo").as("check String contains another String")
stringContains
Using AI Code Generation
1import static org.assertj.core.api.Assertions.assertThat;2import static org.assertj.core.api.Assertions.assertThatThrownBy;3import static org.assertj.core.api.Assertions.catchThrowable;4import static org.assertj.core.api.Assertions.fail;5import org.assertj.core.internal.Strings;6import org.junit.Test;7public class StringContainsTest {8 public void stringContainsTest() {9 Strings strings = new Strings();10 String str = "abc";11 String substring = "a";12 assertThat(strings.stringContains(str, substring)).isTrue();13 }14}15assertThat(actual).stringContains(substring)16package com.zetcode;17import org.junit.jupiter.api.Test;18import static org.assertj.core.api.Assertions.assertThat;19public class StringContainsTest {20 public void stringContainsTest() {21 String str = "abc";22 String substring = "a";23 assertThat(str).stringContains(substring);24 }25}26assertThat(actual).stringContainsIgnoringCase(substring)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!