All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mockserver.test.Assert Maven / Gradle / Ivy

Go to download

A module used to simplify integration testing of all MockServer versions by sharing commons integration testing components

There is a newer version: 5.15.0
Show newest version
package org.mockserver.test;


import java.util.Collection;
import java.util.List;

import static org.junit.Assert.*;

/**
 * @author jamesdbloom
 */
public class Assert {

    /**
     * Asserts that string contains specified substring.
     */
    public static void assertContains(String string, String substring) {
        assertNotNull("string should not be null", string);
        assertNotNull("substring should not be null", substring);

        if (!string.contains(substring)) {
            fail("Unable to find [" + substring + "] in [" + string + "]");
        }
    }

    /**
     * Asserts that string contains specified substring.
     */
    public static void assertDoesNotContain(String string, String substring) {
        assertNotNull("string should not be null", string);
        assertNotNull("substring should not be null", substring);

        if (string.contains(substring)) {
            fail("Able to find [" + substring + "] in [" + string + "]");
        }
    }

    /**
     * Asserts that the two lists contain the same entries regardless of order
     */
    public static  void assertSameEntries(Collection collectionOne, Collection collectionTwo) {
        assertEquals("different number of entries between list [" + collectionOne + "] and [" + collectionTwo + "]", collectionOne.size(), collectionTwo.size());

        for (T expected : collectionOne) {
            if (!collectionTwo.contains(expected)) {
                fail("list [" + collectionOne + "] does not contain [" + expected + "]");
            }
        }

        for (T expected : collectionTwo) {
            if (!collectionOne.contains(expected)) {
                fail("list [" + collectionTwo + "] does not contain [" + expected + "]");
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy