diff --git a/.travis.yml b/.travis.yml index b6287adb..cdcd63e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,9 @@ language: java -# Need to select an older Ubuntu distribution that supports JDK7 -dist: trusty - -# Workaround to using openjdk7 with Gradle due to security issue: -# https://github.com/gradle/gradle/issues/2421 -before_install: -- BCPROV_FILENAME=bcprov-ext-jdk15on-158.jar -- wget "https://bouncycastle.org/download/${BCPROV_FILENAME}" -- sudo mv $BCPROV_FILENAME /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext -- sudo perl -pi.bak -e 's/^(security\.provider\.)([0-9]+)/$1.($2+1)/ge' /etc/java-7-openjdk/security/java.security -- echo "security.provider.1=org.bouncycastle.jce.provider.BouncyCastleProvider" | sudo tee -a /etc/java-7-openjdk/security/java.security - jdk: - - openjdk7 - - oraclejdk8 - openjdk8 - - oraclejdk9 + - openjdk11 + - openjdk12 script: - ./gradlew clean build javadoc diff --git a/build.gradle b/build.gradle index 306f2488..3453efe0 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,7 @@ version = "2.2-SNAPSHOT" subprojects { apply plugin: 'java-library' + apply plugin: 'checkstyle' sourceCompatibility = JavaVersion.VERSION_1_7 targetCompatibility = JavaVersion.VERSION_1_7 @@ -18,6 +19,24 @@ subprojects { mavenCentral() } + checkstyle { + + project.ext.checkstyleVersion = '8.23' + + sourceSets = [ project.sourceSets.main, project.sourceSets.test ] + ignoreFailures = false + configFile = file("${project.rootDir}/checkstyle.xml") + + configurations { + checkstyle + } + + dependencies{ + assert project.hasProperty("checkstyleVersion") + checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}" + } + } + test { testLogging { exceptionFormat = 'full' diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 00000000..71a12974 --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e0b3fb8d..ff9f5762 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Sun Aug 25 22:31:56 CEST 2019 +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/hamcrest-core/src/main/java/org/hamcrest/core/deprecated/HamcrestCoreIsDeprecated.java b/hamcrest-core/src/main/java/org/hamcrest/core/deprecated/HamcrestCoreIsDeprecated.java index 19482c3d..395025c8 100644 --- a/hamcrest-core/src/main/java/org/hamcrest/core/deprecated/HamcrestCoreIsDeprecated.java +++ b/hamcrest-core/src/main/java/org/hamcrest/core/deprecated/HamcrestCoreIsDeprecated.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core.deprecated; /** diff --git a/hamcrest-core/src/main/java/org/hamcrest/core/deprecated/package-info.java b/hamcrest-core/src/main/java/org/hamcrest/core/deprecated/package-info.java index 394ab821..579f5748 100644 --- a/hamcrest-core/src/main/java/org/hamcrest/core/deprecated/package-info.java +++ b/hamcrest-core/src/main/java/org/hamcrest/core/deprecated/package-info.java @@ -1,3 +1,35 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + /** * All classes in hamcrest-core.jar have been migrated to * hamcrest.jar. Please use that dependency instead. diff --git a/hamcrest-integration/src/main/java/org/hamcrest/EasyMock2Matchers.java b/hamcrest-integration/src/main/java/org/hamcrest/EasyMock2Matchers.java index 936aa7d5..c18bccea 100644 --- a/hamcrest-integration/src/main/java/org/hamcrest/EasyMock2Matchers.java +++ b/hamcrest-integration/src/main/java/org/hamcrest/EasyMock2Matchers.java @@ -1,7 +1,38 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; -import org.hamcrest.integration.EasyMock2Adapter; import org.hamcrest.core.IsEqual; +import org.hamcrest.integration.EasyMock2Adapter; /** * diff --git a/hamcrest-integration/src/main/java/org/hamcrest/JMock1Matchers.java b/hamcrest-integration/src/main/java/org/hamcrest/JMock1Matchers.java index 6aac6f87..6b896b63 100644 --- a/hamcrest-integration/src/main/java/org/hamcrest/JMock1Matchers.java +++ b/hamcrest-integration/src/main/java/org/hamcrest/JMock1Matchers.java @@ -1,7 +1,38 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; -import org.hamcrest.integration.JMock1Adapter; import org.hamcrest.core.IsEqual; +import org.hamcrest.integration.JMock1Adapter; import org.jmock.core.Constraint; public class JMock1Matchers { diff --git a/hamcrest-integration/src/main/java/org/hamcrest/JavaLangMatcherAssert.java b/hamcrest-integration/src/main/java/org/hamcrest/JavaLangMatcherAssert.java index 6cc97e81..b9afef9d 100644 --- a/hamcrest-integration/src/main/java/org/hamcrest/JavaLangMatcherAssert.java +++ b/hamcrest-integration/src/main/java/org/hamcrest/JavaLangMatcherAssert.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; /** diff --git a/hamcrest-integration/src/main/java/org/hamcrest/integration/EasyMock2Adapter.java b/hamcrest-integration/src/main/java/org/hamcrest/integration/EasyMock2Adapter.java index 09ab0f7d..2c04f752 100644 --- a/hamcrest-integration/src/main/java/org/hamcrest/integration/EasyMock2Adapter.java +++ b/hamcrest-integration/src/main/java/org/hamcrest/integration/EasyMock2Adapter.java @@ -1,7 +1,38 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.integration; -import org.easymock.IArgumentMatcher; import org.easymock.EasyMock; +import org.easymock.IArgumentMatcher; import org.hamcrest.Matcher; import org.hamcrest.StringDescription; @@ -18,6 +49,8 @@ public class EasyMock2Adapter implements IArgumentMatcher { * Hamcrest {@link org.hamcrest.Matcher} to act as an * EasyMock {@link org.easymock.IArgumentMatcher} and * report it to EasyMock so it can be kept track of. + * @param matcher the matcher + * @return the wrapped matcher */ public static IArgumentMatcher adapt(Matcher matcher) { EasyMock2Adapter easyMock2Matcher = new EasyMock2Adapter(matcher); diff --git a/hamcrest-integration/src/main/java/org/hamcrest/integration/JMock1Adapter.java b/hamcrest-integration/src/main/java/org/hamcrest/integration/JMock1Adapter.java index fa2021ce..f61433bb 100644 --- a/hamcrest-integration/src/main/java/org/hamcrest/integration/JMock1Adapter.java +++ b/hamcrest-integration/src/main/java/org/hamcrest/integration/JMock1Adapter.java @@ -1,8 +1,39 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.integration; -import org.jmock.core.Constraint; import org.hamcrest.Matcher; import org.hamcrest.StringDescription; +import org.jmock.core.Constraint; /** * An adapter allowing a Hamcrest {@link org.hamcrest.Matcher} @@ -18,6 +49,8 @@ public class JMock1Adapter implements Constraint { * Convenience factory method that will adapt a * Hamcrest {@link org.hamcrest.Matcher} to act as an * jMock {@link org.jmock.core.Constraint}. + * @param matcher the matcher + * @return the adapted matcher */ public static Constraint adapt(Matcher matcher) { return new JMock1Adapter(matcher); diff --git a/hamcrest-library/src/main/java/org/hamcrest/library/deprecated/HamcrestLibraryIsDeprecated.java b/hamcrest-library/src/main/java/org/hamcrest/library/deprecated/HamcrestLibraryIsDeprecated.java index b7ec20c3..4f3cd433 100644 --- a/hamcrest-library/src/main/java/org/hamcrest/library/deprecated/HamcrestLibraryIsDeprecated.java +++ b/hamcrest-library/src/main/java/org/hamcrest/library/deprecated/HamcrestLibraryIsDeprecated.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.library.deprecated; /** diff --git a/hamcrest-library/src/main/java/org/hamcrest/library/deprecated/package-info.java b/hamcrest-library/src/main/java/org/hamcrest/library/deprecated/package-info.java index c98f5aff..b2226950 100644 --- a/hamcrest-library/src/main/java/org/hamcrest/library/deprecated/package-info.java +++ b/hamcrest-library/src/main/java/org/hamcrest/library/deprecated/package-info.java @@ -1,3 +1,35 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + /** * All classes in hamcrest-library.jar have been migrated to * hamcrest.jar. Please use that dependency instead. diff --git a/hamcrest/src/main/java/org/hamcrest/BaseDescription.java b/hamcrest/src/main/java/org/hamcrest/BaseDescription.java index d0c8fc41..a35f6c01 100644 --- a/hamcrest/src/main/java/org/hamcrest/BaseDescription.java +++ b/hamcrest/src/main/java/org/hamcrest/BaseDescription.java @@ -1,12 +1,41 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; -import org.hamcrest.internal.ArrayIterator; -import org.hamcrest.internal.SelfDescribingValueIterator; - +import static java.lang.String.valueOf; import java.util.Arrays; import java.util.Iterator; - -import static java.lang.String.valueOf; +import org.hamcrest.internal.ArrayIterator; +import org.hamcrest.internal.SelfDescribingValueIterator; /** * A {@link Description} that is stored as a string. @@ -18,13 +47,13 @@ public Description appendText(String text) { append(text); return this; } - + @Override public Description appendDescriptionOf(SelfDescribing value) { value.describeTo(this); return this; } - + @Override public Description appendValue(Object value) { if (value == null) { @@ -64,8 +93,7 @@ public Description appendValue(Object value) { private String descriptionOf(Object value) { try { return valueOf(value); - } - catch (Exception e) { + } catch (Exception e) { return value.getClass().getName() + "@" + Integer.toHexString(value.hashCode()); } } @@ -75,16 +103,16 @@ private String descriptionOf(Object value) { public final Description appendValueList(String start, String separator, String end, T... values) { return appendValueList(start, separator, end, Arrays.asList(values)); } - + @Override public Description appendValueList(String start, String separator, String end, Iterable values) { return appendValueList(start, separator, end, values.iterator()); } - + private Description appendValueList(String start, String separator, String end, Iterator values) { return appendList(start, separator, end, new SelfDescribingValueIterator<>(values)); } - + @Override public Description appendList(String start, String separator, String end, Iterable values) { return appendList(start, separator, end, values.iterator()); @@ -92,21 +120,23 @@ public Description appendList(String start, String separator, String end, Iterab private Description appendList(String start, String separator, String end, Iterator i) { boolean separate = false; - + append(start); while (i.hasNext()) { - if (separate) append(separator); + if (separate) { + append(separator); + } appendDescriptionOf(i.next()); separate = true; } append(end); - + return this; } /** - * Append the String str to the description. - * The default implementation passes every character to {@link #append(char)}. + * Append the String str to the description. + * The default implementation passes every character to {@link #append(char)}. * Override in subclasses to provide an efficient implementation. */ protected void append(String str) { @@ -114,9 +144,9 @@ protected void append(String str) { append(str.charAt(i)); } } - + /** - * Append the char c to the description. + * Append the char c to the description. */ protected abstract void append(char c); diff --git a/hamcrest/src/main/java/org/hamcrest/BaseMatcher.java b/hamcrest/src/main/java/org/hamcrest/BaseMatcher.java index aaa6e957..b2b58cf0 100644 --- a/hamcrest/src/main/java/org/hamcrest/BaseMatcher.java +++ b/hamcrest/src/main/java/org/hamcrest/BaseMatcher.java @@ -1,8 +1,40 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; /** * BaseClass for all Matcher implementations. * + * @param allows to restrict the matched types * @see Matcher */ public abstract class BaseMatcher implements Matcher { diff --git a/hamcrest/src/main/java/org/hamcrest/Condition.java b/hamcrest/src/main/java/org/hamcrest/Condition.java index 02ce09e6..b7f69705 100644 --- a/hamcrest/src/main/java/org/hamcrest/Condition.java +++ b/hamcrest/src/main/java/org/hamcrest/Condition.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; /** @@ -8,22 +39,32 @@ * * Based on https://github.com/npryce/maybe-java * @author Steve Freeman 2012 http://www.hamcrest.com + * @param the type of matched objects */ - public abstract class Condition { public static final NotMatched NOT_MATCHED = new NotMatched(); + /** + * One step in the chain of conditions + * @param the type of the value to check + * @param the type of the returned condition + */ public interface Step { Condition apply(I value, Description mismatch); } - private Condition() { } + private Condition() { + } public abstract boolean matching(Matcher match, String message); public abstract Condition and(Step mapping); - public final boolean matching(Matcher match) { return matching(match, ""); } - public final Condition then(Step mapping) { return and(mapping); } + public final boolean matching(Matcher match) { + return matching(match, ""); + } + public final Condition then(Step mapping) { + return and(mapping); + } @SuppressWarnings("unchecked") public static Condition notMatched() { @@ -60,9 +101,13 @@ public Condition and(Step next) { } private static final class NotMatched extends Condition { - @Override public boolean matching(Matcher match, String message) { return false; } + @Override + public boolean matching(Matcher match, String message) { + return false; + } - @Override public Condition and(Step mapping) { + @Override + public Condition and(Step mapping) { return notMatched(); } } diff --git a/hamcrest/src/main/java/org/hamcrest/CoreMatchers.java b/hamcrest/src/main/java/org/hamcrest/CoreMatchers.java index 02b5e426..1792be97 100644 --- a/hamcrest/src/main/java/org/hamcrest/CoreMatchers.java +++ b/hamcrest/src/main/java/org/hamcrest/CoreMatchers.java @@ -1,450 +1,554 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; import org.hamcrest.core.IsIterableContaining; -@SuppressWarnings("UnusedDeclaration") +/** + * A collection of static factory methods for core matchers. + */ public class CoreMatchers { - /** - * Creates a matcher that matches if the examined object matches ALL of the specified matchers. - * For example: - *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
- */ - public static org.hamcrest.Matcher allOf(java.lang.Iterable> matchers) { - return org.hamcrest.core.AllOf.allOf(matchers); - } - - /** - * Creates a matcher that matches if the examined object matches ALL of the specified matchers. - * For example: - *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
- */ - @SafeVarargs - public static org.hamcrest.Matcher allOf(org.hamcrest.Matcher... matchers) { - return org.hamcrest.core.AllOf.allOf(matchers); - } - - - /** - * Creates a matcher that matches if the examined object matches ANY of the specified matchers. - * For example: - *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
- */ - public static org.hamcrest.core.AnyOf anyOf(java.lang.Iterable> matchers) { - return org.hamcrest.core.AnyOf.anyOf(matchers); - } - - /** - * Creates a matcher that matches if the examined object matches ANY of the specified matchers. - * For example: - *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
- */ - @SafeVarargs - public static org.hamcrest.core.AnyOf anyOf(org.hamcrest.Matcher... matchers) { - return org.hamcrest.core.AnyOf.anyOf(matchers); - } - - /** - * Creates a matcher that matches when both of the specified matchers match the examined object. - * For example: - *
assertThat("fab", both(containsString("a")).and(containsString("b")))
- */ - public static org.hamcrest.core.CombinableMatcher.CombinableBothMatcher both(org.hamcrest.Matcher matcher) { - return org.hamcrest.core.CombinableMatcher.both(matcher); - } - - /** - * Creates a matcher that matches when either of the specified matchers match the examined object. - * For example: - *
assertThat("fan", either(containsString("a")).or(containsString("b")))
- */ - public static org.hamcrest.core.CombinableMatcher.CombinableEitherMatcher either(org.hamcrest.Matcher matcher) { - return org.hamcrest.core.CombinableMatcher.either(matcher); - } - - /** - * Wraps an existing matcher, overriding its description with that specified. All other functions are - * delegated to the decorated matcher, including its mismatch description. - * For example: - *
describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())
- * - * @param description - * the new description for the wrapped matcher - * @param matcher - * the matcher to wrap - * @param values - * optional values to insert into the tokenised description - */ - public static org.hamcrest.Matcher describedAs(java.lang.String description, org.hamcrest.Matcher matcher, java.lang.Object... values) { - return org.hamcrest.core.DescribedAs.describedAs(description, matcher, values); - } - - /** - * Creates a matcher for {@link Iterable}s that only matches when a single pass over the - * examined {@link Iterable} yields items that are all matched by the specified - * itemMatcher. - * For example: - *
assertThat(Arrays.asList("bar", "baz"), everyItem(startsWith("ba")))
- * - * @param itemMatcher - * the matcher to apply to every item provided by the examined {@link Iterable} - */ - public static org.hamcrest.Matcher> everyItem(org.hamcrest.Matcher itemMatcher) { - return org.hamcrest.core.Every.everyItem(itemMatcher); - } - - /** - * Decorates another Matcher, retaining its behaviour, but allowing tests - * to be slightly more expressive. - * For example: - *
assertThat(cheese, is(equalTo(smelly)))
- * instead of: - *
assertThat(cheese, equalTo(smelly))
- */ - public static org.hamcrest.Matcher is(org.hamcrest.Matcher matcher) { - return org.hamcrest.core.Is.is(matcher); - } - - /** - * A shortcut to the frequently used is(equalTo(x)). - * For example: - *
assertThat(cheese, is(smelly))
- * instead of: - *
assertThat(cheese, is(equalTo(smelly)))
- */ - public static org.hamcrest.Matcher is(T value) { - return org.hamcrest.core.Is.is(value); - } - - /** - * A shortcut to the frequently used is(instanceOf(SomeClass.class)). - * For example: - *
assertThat(cheese, isA(Cheddar.class))
- * instead of: - *
assertThat(cheese, is(instanceOf(Cheddar.class)))
- */ - public static org.hamcrest.Matcher isA(java.lang.Class type) { - return org.hamcrest.core.Is.isA(type); - } - - /** - * Creates a matcher that always matches, regardless of the examined object. - */ - public static org.hamcrest.Matcher anything() { - return org.hamcrest.core.IsAnything.anything(); - } - - /** - * Creates a matcher that always matches, regardless of the examined object, but describes - * itself with the specified {@link String}. - * - * @param description - * a meaningful {@link String} used when describing itself - */ - public static org.hamcrest.Matcher anything(java.lang.String description) { - return org.hamcrest.core.IsAnything.anything(description); - } - - /** - * Creates a matcher for {@link Iterable}s that only matches when a single pass over the - * examined {@link Iterable} yields at least one item that is matched by the specified - * itemMatcher. Whilst matching, the traversal of the examined {@link Iterable} - * will stop as soon as a matching item is found. - * For example: - *
assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))
- * - * @param itemMatcher - * the matcher to apply to items provided by the examined {@link Iterable} - */ - public static org.hamcrest.Matcher> hasItem(org.hamcrest.Matcher itemMatcher) { - return IsIterableContaining.hasItem(itemMatcher); - } - - /** - * Creates a matcher for {@link Iterable}s that only matches when a single pass over the - * examined {@link Iterable} yields at least one item that is equal to the specified - * item. Whilst matching, the traversal of the examined {@link Iterable} - * will stop as soon as a matching item is found. - * For example: - *
assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))
- * - * @param item - * the item to compare against the items provided by the examined {@link Iterable} - */ - public static org.hamcrest.Matcher> hasItem(T item) { - return IsIterableContaining.hasItem(item); - } - - /** - * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the - * examined {@link Iterable} yield at least one item that is matched by the corresponding - * matcher from the specified itemMatchers. Whilst matching, each traversal of - * the examined {@link Iterable} will stop as soon as a matching item is found. - * For example: - *
assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))
- * - * @param itemMatchers - * the matchers to apply to items provided by the examined {@link Iterable} - */ - @SafeVarargs - public static org.hamcrest.Matcher> hasItems(org.hamcrest.Matcher... itemMatchers) { - return IsIterableContaining.hasItems(itemMatchers); - } - - /** - * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the - * examined {@link Iterable} yield at least one item that is equal to the corresponding - * item from the specified items. Whilst matching, each traversal of the - * examined {@link Iterable} will stop as soon as a matching item is found. - * For example: - *
assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))
- * - * @param items - * the items to compare against the items provided by the examined {@link Iterable} - */ - @SafeVarargs - public static org.hamcrest.Matcher> hasItems(T... items) { - return IsIterableContaining.hasItems(items); - } - - /** - * Creates a matcher that matches when the examined object is logically equal to the specified - * operand, as determined by calling the {@link java.lang.Object#equals} method on - * the examined object. - * - *

If the specified operand is null then the created matcher will only match if - * the examined object's equals method returns true when passed a - * null (which would be a violation of the equals contract), unless the - * examined object itself is null, in which case the matcher will return a positive - * match.

- * - *

The created matcher provides a special behaviour when examining Arrays, whereby - * it will match if both the operand and the examined object are arrays of the same length and - * contain items that are equal to each other (according to the above rules) in the same - * indexes.

- * For example: - *
-   * assertThat("foo", equalTo("foo"));
-   * assertThat(new String[] {"foo", "bar"}, equalTo(new String[] {"foo", "bar"}));
-   * 
- */ - public static org.hamcrest.Matcher equalTo(T operand) { - return org.hamcrest.core.IsEqual.equalTo(operand); - } - - /** - * Creates an {@link org.hamcrest.core.IsEqual} matcher that does not enforce the values being - * compared to be of the same static type. - */ - public static org.hamcrest.Matcher equalToObject(java.lang.Object operand) { - return org.hamcrest.core.IsEqual.equalToObject(operand); - } - - /** - * Creates a matcher that matches when the examined object is an instance of the specified type, - * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the - * the examined object. - * - *

The created matcher forces a relationship between specified type and the examined object, and should be - * used when it is necessary to make generics conform, for example in the JMock clause - * with(any(Thing.class))

- * For example: - *
assertThat(new Canoe(), instanceOf(Canoe.class));
- */ - public static org.hamcrest.Matcher any(java.lang.Class type) { - return org.hamcrest.core.IsInstanceOf.any(type); - } - - /** - * Creates a matcher that matches when the examined object is an instance of the specified type, - * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the - * the examined object. - * - *

The created matcher assumes no relationship between specified type and the examined object.

- * For example: - *
assertThat(new Canoe(), instanceOf(Paddlable.class));
- */ - public static org.hamcrest.Matcher instanceOf(java.lang.Class type) { - return org.hamcrest.core.IsInstanceOf.instanceOf(type); - } - - /** - * Creates a matcher that wraps an existing matcher, but inverts the logic by which - * it will match. - * For example: - *
assertThat(cheese, is(not(equalTo(smelly))))
- * - * @param matcher - * the matcher whose sense should be inverted - */ - public static org.hamcrest.Matcher not(org.hamcrest.Matcher matcher) { - return org.hamcrest.core.IsNot.not(matcher); - } - - /** - * A shortcut to the frequently used not(equalTo(x)). - * For example: - *
assertThat(cheese, is(not(smelly)))
- * instead of: - *
assertThat(cheese, is(not(equalTo(smelly))))
- * - * @param value - * the value that any examined object should not equal - */ - public static org.hamcrest.Matcher not(T value) { - return org.hamcrest.core.IsNot.not(value); - } - - /** - * A shortcut to the frequently used not(nullValue()). - * For example: - *
assertThat(cheese, is(notNullValue()))
- * instead of: - *
assertThat(cheese, is(not(nullValue())))
- */ - public static org.hamcrest.Matcher notNullValue() { - return org.hamcrest.core.IsNull.notNullValue(); - } - - /** - * A shortcut to the frequently used not(nullValue(X.class)). Accepts a - * single dummy argument to facilitate type inference.. - * For example: - *
assertThat(cheese, is(notNullValue(X.class)))
- * instead of: - *
assertThat(cheese, is(not(nullValue(X.class))))
- * - * @param type - * dummy parameter used to infer the generic type of the returned matcher - */ - public static org.hamcrest.Matcher notNullValue(java.lang.Class type) { - return org.hamcrest.core.IsNull.notNullValue(type); - } - - /** - * Creates a matcher that matches if examined object is null. - * For example: - *
assertThat(cheese, is(nullValue())
- */ - public static org.hamcrest.Matcher nullValue() { - return org.hamcrest.core.IsNull.nullValue(); - } - - /** - * Creates a matcher that matches if examined object is null. Accepts a - * single dummy argument to facilitate type inference. - * For example: - *
assertThat(cheese, is(nullValue(Cheese.class))
- * - * @param type - * dummy parameter used to infer the generic type of the returned matcher - */ - public static org.hamcrest.Matcher nullValue(java.lang.Class type) { - return org.hamcrest.core.IsNull.nullValue(type); - } - - /** - * Creates a matcher that matches only when the examined object is the same instance as - * the specified target object. - * - * @param target - * the target instance against which others should be assessed - */ - public static org.hamcrest.Matcher sameInstance(T target) { - return org.hamcrest.core.IsSame.sameInstance(target); - } - - /** - * Creates a matcher that matches only when the examined object is the same instance as - * the specified target object. - * - * @param target - * the target instance against which others should be assessed - */ - public static org.hamcrest.Matcher theInstance(T target) { - return org.hamcrest.core.IsSame.theInstance(target); - } - - /** - * Creates a matcher that matches if the examined {@link String} contains the specified - * {@link String} anywhere. - * For example: - *
assertThat("myStringOfNote", containsString("ring"))
- * - * @param substring - * the substring that the returned matcher will expect to find within any examined string - */ - public static org.hamcrest.Matcher containsString(java.lang.String substring) { - return org.hamcrest.core.StringContains.containsString(substring); - } - - /** - * Creates a matcher that matches if the examined {@link String} contains the specified - * {@link String} anywhere, ignoring case. - * For example: - *
assertThat("myStringOfNote", containsString("ring"))
- * - * @param substring - * the substring that the returned matcher will expect to find within any examined string - */ - public static org.hamcrest.Matcher containsStringIgnoringCase(java.lang.String substring) { - return org.hamcrest.core.StringContains.containsStringIgnoringCase(substring); - } - - /** - *

- * Creates a matcher that matches if the examined {@link String} starts with the specified - * {@link String}. - *

- * For example: - *
assertThat("myStringOfNote", startsWith("my"))
- * - * @param prefix - * the substring that the returned matcher will expect at the start of any examined string - */ - public static org.hamcrest.Matcher startsWith(java.lang.String prefix) { - return org.hamcrest.core.StringStartsWith.startsWith(prefix); - } - - /** - *

- * Creates a matcher that matches if the examined {@link String} starts with the specified - * {@link String}, ignoring case - *

- * For example: - *
assertThat("myStringOfNote", startsWith("my"))
- * - * @param prefix - * the substring that the returned matcher will expect at the start of any examined string - */ - public static org.hamcrest.Matcher startsWithIgnoringCase(java.lang.String prefix) { - return org.hamcrest.core.StringStartsWith.startsWithIgnoringCase(prefix); - } - - /** - * Creates a matcher that matches if the examined {@link String} ends with the specified - * {@link String}. - * For example: - *
assertThat("myStringOfNote", endsWith("Note"))
- * - * @param suffix - * the substring that the returned matcher will expect at the end of any examined string - */ - public static org.hamcrest.Matcher endsWith(java.lang.String suffix) { - return org.hamcrest.core.StringEndsWith.endsWith(suffix); - } - - /** - * Creates a matcher that matches if the examined {@link String} ends with the specified - * {@link String}, ignoring case. - * For example: - *
assertThat("myStringOfNote", endsWith("Note"))
- * - * @param suffix - * the substring that the returned matcher will expect at the end of any examined string - */ - public static org.hamcrest.Matcher endsWithIgnoringCase(java.lang.String suffix) { - return org.hamcrest.core.StringEndsWith.endsWithIgnoringCase(suffix); - } + /** + * Creates a matcher that matches if the examined object matches ALL of the specified matchers. + * For example: + *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
+ * @param the matchers type + * @param matchers the matchers to match + * @return the created matcher + */ + public static org.hamcrest.Matcher allOf(Iterable> matchers) { + return org.hamcrest.core.AllOf.allOf(matchers); + } + + /** + * Creates a matcher that matches if the examined object matches ALL of the specified matchers. + * For example: + *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
+ * @param the matchers type + * @param matchers the matchers to match + * @return the created matcher + */ + @SafeVarargs + public static org.hamcrest.Matcher allOf(org.hamcrest.Matcher... matchers) { + return org.hamcrest.core.AllOf.allOf(matchers); + } + + /** + * Creates a matcher that matches if the examined object matches ANY of the specified matchers. + * For example: + *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
+ * @param the matcher type + * @param matchers the matchers to match + * @return the created matcher + */ + public static org.hamcrest.core.AnyOf anyOf(Iterable> matchers) { + return org.hamcrest.core.AnyOf.anyOf(matchers); + } + + /** + * Creates a matcher that matches if the examined object matches ANY of the specified matchers. + * For example: + *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
+ * @param the matcher type + * @param matchers the matchers to match + * @return the created matcher + */ + @SafeVarargs + public static org.hamcrest.core.AnyOf anyOf(org.hamcrest.Matcher... matchers) { + return org.hamcrest.core.AnyOf.anyOf(matchers); + } + + /** + * Creates a matcher that matches when both of the specified matchers match the examined object. + * For example: + *
assertThat("fab", both(containsString("a")).and(containsString("b")))
+ * @param the matcher type + * @param matcher the matcher to match + * @return the created matcher + */ + public static org.hamcrest.core.CombinableMatcher.CombinableBothMatcher both(org.hamcrest.Matcher matcher) { + return org.hamcrest.core.CombinableMatcher.both(matcher); + } + + /** + * Creates a matcher that matches when either of the specified matchers match the examined object. + * For example: + *
assertThat("fan", either(containsString("a")).or(containsString("b")))
+ * @param the matcher type + * @param matcher the matcher to match + * @return the created matcher + */ + public static org.hamcrest.core.CombinableMatcher.CombinableEitherMatcher either(org.hamcrest.Matcher matcher) { + return org.hamcrest.core.CombinableMatcher.either(matcher); + } + + /** + * Wraps an existing matcher, overriding its description with that specified. All other functions are + * delegated to the decorated matcher, including its mismatch description. + * For example: + *
describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())
+ * + * @param the matcher type + * @param description + * the new description for the wrapped matcher + * @param matcher + * the matcher to wrap + * @param values + * optional values to insert into the tokenised description + * @return the created matcher + */ + public static org.hamcrest.Matcher describedAs(String description, org.hamcrest.Matcher matcher, Object... values) { + return org.hamcrest.core.DescribedAs.describedAs(description, matcher, values); + } + + /** + * Creates a matcher for {@link Iterable}s that only matches when a single pass over the + * examined {@link Iterable} yields items that are all matched by the specified + * itemMatcher. + * For example: + *
assertThat(Arrays.asList("bar", "baz"), everyItem(startsWith("ba")))
+ * + * @param the matcher type + * @param itemMatcher + * the matcher to apply to every item provided by the examined {@link Iterable} + * @return the created matcher + */ + public static org.hamcrest.Matcher> everyItem(org.hamcrest.Matcher itemMatcher) { + return org.hamcrest.core.Every.everyItem(itemMatcher); + } + + /** + * Decorates another Matcher, retaining its behaviour, but allowing tests + * to be slightly more expressive. + * For example: + *
assertThat(cheese, is(equalTo(smelly)))
+ * instead of: + *
assertThat(cheese, equalTo(smelly))
+ * @param the matcher type + * @param matcher the matcher to match + * @return the created matcher + */ + public static org.hamcrest.Matcher is(org.hamcrest.Matcher matcher) { + return org.hamcrest.core.Is.is(matcher); + } + + /** + * A shortcut to the frequently used is(equalTo(x)). + * For example: + *
assertThat(cheese, is(smelly))
+ * instead of: + *
assertThat(cheese, is(equalTo(smelly)))
+ * @param the matcher type + * @param value the value to match + * @return the created matcher + */ + public static org.hamcrest.Matcher is(T value) { + return org.hamcrest.core.Is.is(value); + } + + /** + * A shortcut to the frequently used is(instanceOf(SomeClass.class)). + * For example: + *
assertThat(cheese, isA(Cheddar.class))
+ * instead of: + *
assertThat(cheese, is(instanceOf(Cheddar.class)))
+ * @param the matcher type + * @param type the type to match + * @return the created matcher + */ + public static org.hamcrest.Matcher isA(Class type) { + return org.hamcrest.core.Is.isA(type); + } + + /** + * Creates a matcher that always matches, regardless of the examined object. + * @return the created matcher + */ + public static org.hamcrest.Matcher anything() { + return org.hamcrest.core.IsAnything.anything(); + } + + /** + * Creates a matcher that always matches, regardless of the examined object, but describes + * itself with the specified {@link String}. + * + * @param description + * a meaningful {@link String} used when describing itself + * @return the created matcher + */ + public static org.hamcrest.Matcher anything(String description) { + return org.hamcrest.core.IsAnything.anything(description); + } + + /** + * Creates a matcher for {@link Iterable}s that only matches when a single pass over the + * examined {@link Iterable} yields at least one item that is matched by the specified + * itemMatcher. Whilst matching, the traversal of the examined {@link Iterable} + * will stop as soon as a matching item is found. + * For example: + *
assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))
+ * + * @param the matcher type + * @param itemMatcher + * the matcher to apply to items provided by the examined {@link Iterable} + * @return the created matcher + */ + public static org.hamcrest.Matcher> hasItem(org.hamcrest.Matcher itemMatcher) { + return IsIterableContaining.hasItem(itemMatcher); + } + + /** + * Creates a matcher for {@link Iterable}s that only matches when a single pass over the + * examined {@link Iterable} yields at least one item that is equal to the specified + * item. Whilst matching, the traversal of the examined {@link Iterable} + * will stop as soon as a matching item is found. + * For example: + *
assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))
+ * + * @param the matcher type + * @param item + * the item to compare against the items provided by the examined {@link Iterable} + * @return the created matcher + */ + public static org.hamcrest.Matcher> hasItem(T item) { + return IsIterableContaining.hasItem(item); + } + + /** + * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the + * examined {@link Iterable} yield at least one item that is matched by the corresponding + * matcher from the specified itemMatchers. Whilst matching, each traversal of + * the examined {@link Iterable} will stop as soon as a matching item is found. + * For example: + *
assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))
+ * + * @param the matcher type + * @param itemMatchers + * the matchers to apply to items provided by the examined {@link Iterable} + * @return the created matcher + */ + @SafeVarargs + public static org.hamcrest.Matcher> hasItems(org.hamcrest.Matcher... itemMatchers) { + return IsIterableContaining.hasItems(itemMatchers); + } + + /** + * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the + * examined {@link Iterable} yield at least one item that is equal to the corresponding + * item from the specified items. Whilst matching, each traversal of the + * examined {@link Iterable} will stop as soon as a matching item is found. + * For example: + *
assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))
+ * + * @param the matcher type + * @param items + * the items to compare against the items provided by the examined {@link Iterable} + * @return the created matcher + */ + @SafeVarargs + public static org.hamcrest.Matcher> hasItems(T... items) { + return IsIterableContaining.hasItems(items); + } + + /** + * Creates a matcher that matches when the examined object is logically equal to the specified + * operand, as determined by calling the {@link java.lang.Object#equals} method on + * the examined object. + * + *

If the specified operand is null then the created matcher will only match if + * the examined object's equals method returns true when passed a + * null (which would be a violation of the equals contract), unless the + * examined object itself is null, in which case the matcher will return a positive + * match.

+ * + *

The created matcher provides a special behaviour when examining Arrays, whereby + * it will match if both the operand and the examined object are arrays of the same length and + * contain items that are equal to each other (according to the above rules) in the same + * indexes.

+ * For example: + *
+     * assertThat("foo", equalTo("foo"));
+     * assertThat(new String[] {"foo", "bar"}, equalTo(new String[] {"foo", "bar"}));
+     * 
+ * @param the matcher type + * @param operand the operand to match + * @return the created matcher + */ + public static org.hamcrest.Matcher equalTo(T operand) { + return org.hamcrest.core.IsEqual.equalTo(operand); + } + + /** + * Creates an {@link org.hamcrest.core.IsEqual} matcher that does not enforce the values being + * compared to be of the same static type. + * @param operand the operand to match + * @return the created matcher + */ + public static org.hamcrest.Matcher equalToObject(Object operand) { + return org.hamcrest.core.IsEqual.equalToObject(operand); + } + + /** + * Creates a matcher that matches when the examined object is an instance of the specified type, + * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the + * the examined object. + * + *

The created matcher forces a relationship between specified type and the examined object, and should be + * used when it is necessary to make generics conform, for example in the JMock clause + * with(any(Thing.class))

+ * For example: + *
assertThat(new Canoe(), instanceOf(Canoe.class));
+ * @param the matcher type + * @param type the type to match + * @return the created matcher + */ + public static org.hamcrest.Matcher any(Class type) { + return org.hamcrest.core.IsInstanceOf.any(type); + } + + /** + * Creates a matcher that matches when the examined object is an instance of the specified type, + * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the + * the examined object. + * + *

The created matcher assumes no relationship between specified type and the examined object.

+ * For example: + *
assertThat(new Canoe(), instanceOf(Paddlable.class));
+ * @param the matcher type + * @param type the type to match + * @return the created matcher + */ + public static org.hamcrest.Matcher instanceOf(Class type) { + return org.hamcrest.core.IsInstanceOf.instanceOf(type); + } + + /** + * Creates a matcher that wraps an existing matcher, but inverts the logic by which + * it will match. + * For example: + *
assertThat(cheese, is(not(equalTo(smelly))))
+ * + * @param the matcher type + * @param matcher the matcher to negate + * the matcher whose sense should be inverted + * @return the created matcher + */ + public static org.hamcrest.Matcher not(org.hamcrest.Matcher matcher) { + return org.hamcrest.core.IsNot.not(matcher); + } + + /** + * A shortcut to the frequently used not(equalTo(x)). + * For example: + *
assertThat(cheese, is(not(smelly)))
+ * instead of: + *
assertThat(cheese, is(not(equalTo(smelly))))
+ * + * @param the matcher type + * @param value + * the value that any examined object should not equal + * @return the created matcher + */ + public static org.hamcrest.Matcher not(T value) { + return org.hamcrest.core.IsNot.not(value); + } + + /** + * A shortcut to the frequently used not(nullValue()). + * For example: + *
assertThat(cheese, is(notNullValue()))
+ * instead of: + *
assertThat(cheese, is(not(nullValue())))
+ * @return the created matcher + */ + public static org.hamcrest.Matcher notNullValue() { + return org.hamcrest.core.IsNull.notNullValue(); + } + + /** + * A shortcut to the frequently used not(nullValue(X.class)). Accepts a + * single dummy argument to facilitate type inference.. + * For example: + *
assertThat(cheese, is(notNullValue(X.class)))
+ * instead of: + *
assertThat(cheese, is(not(nullValue(X.class))))
+ * + * @param the matcher type + * @param type + * dummy parameter used to infer the generic type of the returned matcher + * @return the created matcher + */ + public static org.hamcrest.Matcher notNullValue(Class type) { + return org.hamcrest.core.IsNull.notNullValue(type); + } + + /** + * Creates a matcher that matches if examined object is null. + * For example: + *
assertThat(cheese, is(nullValue())
+ * @return the created matcher + */ + public static org.hamcrest.Matcher nullValue() { + return org.hamcrest.core.IsNull.nullValue(); + } + + /** + * Creates a matcher that matches if examined object is null. Accepts a + * single dummy argument to facilitate type inference. + * For example: + *
assertThat(cheese, is(nullValue(Cheese.class))
+ * + * @param the matcher type + * @param type + * dummy parameter used to infer the generic type of the returned matcher + * @return the created matcher + */ + public static org.hamcrest.Matcher nullValue(Class type) { + return org.hamcrest.core.IsNull.nullValue(type); + } + + /** + * Creates a matcher that matches only when the examined object is the same instance as + * the specified target object. + * + * @param the matcher type + * @param target the target to match + * the target instance against which others should be assessed + * @return the created matcher + */ + public static org.hamcrest.Matcher sameInstance(T target) { + return org.hamcrest.core.IsSame.sameInstance(target); + } + + /** + * Creates a matcher that matches only when the examined object is the same instance as + * the specified target object. + * + * @param the matcher type + * @param target the target to match + * the target instance against which others should be assessed + * @return the created matcher + */ + public static org.hamcrest.Matcher theInstance(T target) { + return org.hamcrest.core.IsSame.theInstance(target); + } + + /** + * Creates a matcher that matches if the examined {@link String} contains the specified + * {@link String} anywhere. + * For example: + *
assertThat("myStringOfNote", containsString("ring"))
+ * + * @param substring + * the substring that the returned matcher will expect to find within any examined string + * @return the created matcher + */ + public static org.hamcrest.Matcher containsString(String substring) { + return org.hamcrest.core.StringContains.containsString(substring); + } + + /** + * Creates a matcher that matches if the examined {@link String} contains the specified + * {@link String} anywhere, ignoring case. + * For example: + *
assertThat("myStringOfNote", containsString("ring"))
+ * + * @param substring + * the substring that the returned matcher will expect to find within any examined string + * @return the created matcher + */ + public static org.hamcrest.Matcher containsStringIgnoringCase(String substring) { + return org.hamcrest.core.StringContains.containsStringIgnoringCase(substring); + } + + /** + *

+ * Creates a matcher that matches if the examined {@link String} starts with the specified + * {@link String}. + *

+ * For example: + *
assertThat("myStringOfNote", startsWith("my"))
+ * + * @param prefix + * the substring that the returned matcher will expect at the start of any examined string + * @return the created matcher + */ + public static org.hamcrest.Matcher startsWith(String prefix) { + return org.hamcrest.core.StringStartsWith.startsWith(prefix); + } + + /** + *

+ * Creates a matcher that matches if the examined {@link String} starts with the specified + * {@link String}, ignoring case + *

+ * For example: + *
assertThat("myStringOfNote", startsWith("my"))
+ * + * @param prefix + * the substring that the returned matcher will expect at the start of any examined string + * @return the created matcher + */ + public static org.hamcrest.Matcher startsWithIgnoringCase(String prefix) { + return org.hamcrest.core.StringStartsWith.startsWithIgnoringCase(prefix); + } + + /** + * Creates a matcher that matches if the examined {@link String} ends with the specified + * {@link String}. + * For example: + *
assertThat("myStringOfNote", endsWith("Note"))
+ * + * @param suffix + * the substring that the returned matcher will expect at the end of any examined string + * @return the created matcher + */ + public static org.hamcrest.Matcher endsWith(String suffix) { + return org.hamcrest.core.StringEndsWith.endsWith(suffix); + } + + /** + * Creates a matcher that matches if the examined {@link String} ends with the specified + * {@link String}, ignoring case. + * For example: + *
assertThat("myStringOfNote", endsWith("Note"))
+ * + * @param suffix + * the substring that the returned matcher will expect at the end of any examined string + * @return the created matcher + */ + public static org.hamcrest.Matcher endsWithIgnoringCase(String suffix) { + return org.hamcrest.core.StringEndsWith.endsWithIgnoringCase(suffix); + } } diff --git a/hamcrest/src/main/java/org/hamcrest/CustomMatcher.java b/hamcrest/src/main/java/org/hamcrest/CustomMatcher.java index 036a7640..257d9944 100644 --- a/hamcrest/src/main/java/org/hamcrest/CustomMatcher.java +++ b/hamcrest/src/main/java/org/hamcrest/CustomMatcher.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; /** @@ -16,9 +47,9 @@ * matchers. * * @author Neil Dunn - * @see CustomTypeSafeMatcher for a type safe variant of this class that you probably - * want to use. * @param The type of object being matched. + * @see CustomTypeSafeMatcher for a type safe variant of this class that you probably + * want to use. */ public abstract class CustomMatcher extends BaseMatcher { private final String fixedDescription; diff --git a/hamcrest/src/main/java/org/hamcrest/CustomTypeSafeMatcher.java b/hamcrest/src/main/java/org/hamcrest/CustomTypeSafeMatcher.java index 7c5c46ce..612af614 100644 --- a/hamcrest/src/main/java/org/hamcrest/CustomTypeSafeMatcher.java +++ b/hamcrest/src/main/java/org/hamcrest/CustomTypeSafeMatcher.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; diff --git a/hamcrest/src/main/java/org/hamcrest/Description.java b/hamcrest/src/main/java/org/hamcrest/Description.java index 73bfa385..340aadf3 100644 --- a/hamcrest/src/main/java/org/hamcrest/Description.java +++ b/hamcrest/src/main/java/org/hamcrest/Description.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; /** @@ -7,34 +38,52 @@ * @see Matcher#describeTo(Description) */ public interface Description { - /** - * A description that consumes input but does nothing. - */ - static final Description NONE = new NullDescription(); - + /** + * A description that consumes input but does nothing. + */ + static final Description NONE = new NullDescription(); + /** * Appends some plain text to the description. + * @param text the text to append + * @return the generated description */ Description appendText(String text); /** * Appends the description of a {@link SelfDescribing} value to this description. + * @param value the value to handle + * @return the generated description */ Description appendDescriptionOf(SelfDescribing value); /** * Appends an arbitrary value to the description. + * @param value the value to handle + * @return the generated description */ Description appendValue(Object value); /** * Appends a list of values to the description. + * @param the value type + * @param start the start + * @param separator the separator + * @param end the end + * @param values the values to handle + * @return the generated description */ Description appendValueList(String start, String separator, String end, T... values); /** * Appends a list of values to the description. + * @param the value type + * @param start the start + * @param separator the separator + * @param end the end + * @param values the values to handle + * @return the generated description */ Description appendValueList(String start, String separator, String end, Iterable values); @@ -42,48 +91,55 @@ Description appendValueList(String start, String separator, String end, /** * Appends a list of {@link org.hamcrest.SelfDescribing} objects * to the description. + * @param start the start + * @param separator the separator + * @param end the end + * @param values the values to handle + * @return the generated description */ Description appendList(String start, String separator, String end, Iterable values); - + /** + * A null description implementation. + */ public static final class NullDescription implements Description { - @Override - public Description appendDescriptionOf(SelfDescribing value) { - return this; - } + @Override + public Description appendDescriptionOf(SelfDescribing value) { + return this; + } - @Override - public Description appendList(String start, String separator, - String end, Iterable values) { - return this; - } + @Override + public Description appendList(String start, String separator, + String end, Iterable values) { + return this; + } - @Override - public Description appendText(String text) { - return this; - } + @Override + public Description appendText(String text) { + return this; + } - @Override - public Description appendValue(Object value) { - return this; - } + @Override + public Description appendValue(Object value) { + return this; + } - @Override - public Description appendValueList(String start, String separator, - String end, T... values) { - return this; - } + @Override + public Description appendValueList(String start, String separator, + String end, T... values) { + return this; + } - @Override - public Description appendValueList(String start, String separator, - String end, Iterable values) { - return this; - } + @Override + public Description appendValueList(String start, String separator, + String end, Iterable values) { + return this; + } - @Override + @Override public String toString() { - return ""; + return ""; } } } diff --git a/hamcrest/src/main/java/org/hamcrest/DiagnosingMatcher.java b/hamcrest/src/main/java/org/hamcrest/DiagnosingMatcher.java index f87de2df..5a44da9f 100644 --- a/hamcrest/src/main/java/org/hamcrest/DiagnosingMatcher.java +++ b/hamcrest/src/main/java/org/hamcrest/DiagnosingMatcher.java @@ -1,9 +1,40 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; /** * TODO(ngd): Document. * - * @param + * @param the matcher type */ public abstract class DiagnosingMatcher extends BaseMatcher { diff --git a/hamcrest/src/main/java/org/hamcrest/FeatureMatcher.java b/hamcrest/src/main/java/org/hamcrest/FeatureMatcher.java index 385cf999..2048f3fd 100644 --- a/hamcrest/src/main/java/org/hamcrest/FeatureMatcher.java +++ b/hamcrest/src/main/java/org/hamcrest/FeatureMatcher.java @@ -1,54 +1,85 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; import org.hamcrest.internal.ReflectiveTypeFinder; /** * Supporting class for matching a feature of an object. Implement featureValueOf() - * in a subclass to pull out the feature to be matched against. + * in a subclass to pull out the feature to be matched against. * * @param The type of the object to be matched * @param The type of the feature to be matched */ public abstract class FeatureMatcher extends TypeSafeDiagnosingMatcher { - private static final ReflectiveTypeFinder TYPE_FINDER = new ReflectiveTypeFinder("featureValueOf", 1, 0); - private final Matcher subMatcher; - private final String featureDescription; - private final String featureName; - - /** - * Constructor - * @param subMatcher The matcher to apply to the feature - * @param featureDescription Descriptive text to use in describeTo - * @param featureName Identifying text for mismatch message - */ - public FeatureMatcher(Matcher subMatcher, String featureDescription, String featureName) { - super(TYPE_FINDER); - this.subMatcher = subMatcher; - this.featureDescription = featureDescription; - this.featureName = featureName; - } - - /** - * Implement this to extract the interesting feature. - * @param actual the target object - * @return the feature to be matched - */ - protected abstract U featureValueOf(T actual); + private static final ReflectiveTypeFinder TYPE_FINDER = new ReflectiveTypeFinder("featureValueOf", 1, 0); + private final Matcher subMatcher; + private final String featureDescription; + private final String featureName; + + /** + * Constructor + * @param subMatcher The matcher to apply to the feature + * @param featureDescription Descriptive text to use in describeTo + * @param featureName Identifying text for mismatch message + */ + public FeatureMatcher(Matcher subMatcher, String featureDescription, String featureName) { + super(TYPE_FINDER); + this.subMatcher = subMatcher; + this.featureDescription = featureDescription; + this.featureName = featureName; + } - @Override - protected boolean matchesSafely(T actual, Description mismatch) { - final U featureValue = featureValueOf(actual); - if (!subMatcher.matches(featureValue)) { - mismatch.appendText(featureName).appendText(" "); - subMatcher.describeMismatch(featureValue, mismatch); - return false; + /** + * Implement this to extract the interesting feature. + * @param actual the target object + * @return the feature to be matched + */ + protected abstract U featureValueOf(T actual); + + @Override + protected boolean matchesSafely(T actual, Description mismatch) { + final U featureValue = featureValueOf(actual); + if (!subMatcher.matches(featureValue)) { + mismatch.appendText(featureName).appendText(" "); + subMatcher.describeMismatch(featureValue, mismatch); + return false; + } + return true; } - return true; - } - - @Override - public final void describeTo(Description description) { - description.appendText(featureDescription).appendText(" ") + + @Override + public final void describeTo(Description description) { + description.appendText(featureDescription).appendText(" ") .appendDescriptionOf(subMatcher); - } + } } diff --git a/hamcrest/src/main/java/org/hamcrest/Matcher.java b/hamcrest/src/main/java/org/hamcrest/Matcher.java index 77e09d5b..d8b41db5 100644 --- a/hamcrest/src/main/java/org/hamcrest/Matcher.java +++ b/hamcrest/src/main/java/org/hamcrest/Matcher.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; /** @@ -21,6 +52,7 @@ * N.B. Well designed matchers should be immutable. *

* + * @param the matcher type * @see BaseMatcher */ public interface Matcher extends SelfDescribing { @@ -39,12 +71,12 @@ public interface Matcher extends SelfDescribing { * @see BaseMatcher */ boolean matches(Object actual); - + /** * Generate a description of why the matcher has not accepted the item. * The description will be part of a larger description of why a matching - * failed, so it should be concise. - * This method assumes that matches(item) is false, but + * failed, so it should be concise. + * This method assumes that matches(item) is false, but * will not check this. * * @param actual The item that the Matcher has rejected. @@ -63,5 +95,7 @@ public interface Matcher extends SelfDescribing { * @deprecated to make */ @Deprecated + //CHECKSTYLE:OFF void _dont_implement_Matcher___instead_extend_BaseMatcher_(); + //CHECKSTYLE:ON } diff --git a/hamcrest/src/main/java/org/hamcrest/MatcherAssert.java b/hamcrest/src/main/java/org/hamcrest/MatcherAssert.java index 049e1df3..4ff71658 100644 --- a/hamcrest/src/main/java/org/hamcrest/MatcherAssert.java +++ b/hamcrest/src/main/java/org/hamcrest/MatcherAssert.java @@ -1,11 +1,46 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; - +/** + * A collection factory methods to create assertion matchers. + * @author richter + */ public class MatcherAssert { + public static void assertThat(T actual, Matcher matcher) { assertThat("", actual, matcher); } - + public static void assertThat(String reason, T actual, Matcher matcher) { if (!matcher.matches(actual)) { Description description = new StringDescription(); @@ -14,11 +49,11 @@ public static void assertThat(String reason, T actual, Matcher ma .appendDescriptionOf(matcher) .appendText("\n but: "); matcher.describeMismatch(actual, description); - + throw new AssertionError(description.toString()); } } - + public static void assertThat(String reason, boolean assertion) { if (!assertion) { throw new AssertionError(reason); diff --git a/hamcrest/src/main/java/org/hamcrest/Matchers.java b/hamcrest/src/main/java/org/hamcrest/Matchers.java index 30064b12..ab344e9f 100644 --- a/hamcrest/src/main/java/org/hamcrest/Matchers.java +++ b/hamcrest/src/main/java/org/hamcrest/Matchers.java @@ -1,1511 +1,1802 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; +import java.util.Collection; +import java.util.EventObject; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; import org.hamcrest.collection.ArrayMatching; import org.hamcrest.core.IsIterableContaining; import org.hamcrest.core.StringRegularExpression; import org.hamcrest.text.IsEqualCompressingWhiteSpace; -import java.util.regex.Pattern; +/** + * Factory methods for matchers. + */ +public class Matchers { + + /** + * Creates a matcher that matches if the examined object matches ALL of the specified matchers. + * For example: + *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
+ * @param the matcher type + * @param matchers the matchers to match + * @return the created matcher + */ + public static Matcher allOf(Iterable> matchers) { + return org.hamcrest.core.AllOf.allOf(matchers); + } + + /** + * Creates a matcher that matches if the examined object matches ALL of the specified matchers. + * For example: + *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
+ * @param the matcher type + * @param matchers the matchers to match + * @return the created matcher + */ + @SafeVarargs + public static Matcher allOf(Matcher... matchers) { + return org.hamcrest.core.AllOf.allOf(matchers); + } + + /** + * Creates a matcher that matches if the examined object matches ALL of the specified matchers. + * For example: + *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
+ * @param the matcher type + * @param first the first matcher to match + * @param second the second matcher to match + * @return the created matcher + */ + public static Matcher allOf(Matcher first, Matcher second) { + return org.hamcrest.core.AllOf.allOf(first, second); + } + + /** + * Creates a matcher that matches if the examined object matches ALL of the specified matchers. + * For example: + *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
+ * @param the matcher type + * @param first the first matcher to match + * @param second the second matcher to match + * @param third the third matcher to match + * @return the created matcher + */ + public static Matcher allOf(Matcher first, Matcher second, Matcher third) { + return org.hamcrest.core.AllOf.allOf(first, second, third); + } + + /** + * Creates a matcher that matches if the examined object matches ALL of the specified matchers. + * For example: + *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
+ * @param the matcher type + * @param first the first matcher to match + * @param second the second matcher to match + * @param third the third matcher to match + * @param fourth the forth matcher to match + * @return the created matcher + */ + public static Matcher allOf(Matcher first, Matcher second, Matcher third, Matcher fourth) { + return org.hamcrest.core.AllOf.allOf(first, second, third, fourth); + } + + /** + * Creates a matcher that matches if the examined object matches ALL of the specified matchers. + * For example: + *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
+ * @param the matcher type + * @param first the first matcher to match + * @param second the second matcher to match + * @param third the third matcher to match + * @param fourth the forth matcher to match + * @param fifth the fifth matcher to match + * @return the created matcher + */ + public static Matcher allOf(Matcher first, Matcher second, Matcher third, Matcher fourth, Matcher fifth) { + return org.hamcrest.core.AllOf.allOf(first, second, third, fourth, fifth); + } + + /** + * Creates a matcher that matches if the examined object matches ALL of the specified matchers. + * For example: + *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
+ * @param the matcher type + * @param first the first matcher to match + * @param second the second matcher to match + * @param third the third matcher to match + * @param fourth the forth matcher to match + * @param fifth the fifth matcher to match + * @param sixth the sixth matcher to match + * @return the created matcher + */ + public static Matcher allOf(Matcher first, Matcher second, Matcher third, Matcher fourth, Matcher fifth, Matcher sixth) { + return org.hamcrest.core.AllOf.allOf(first, second, third, fourth, fifth, sixth); + } + + /** + * Creates a matcher that matches if the examined object matches ANY of the specified matchers. + * For example: + *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
+ * @param the matcher type + * @param matchers the matchers to match + * @return the created matcher + */ + public static org.hamcrest.core.AnyOf anyOf(Iterable> matchers) { + return org.hamcrest.core.AnyOf.anyOf(matchers); + } + + /** + * Creates a matcher that matches if the examined object matches ANY of the specified matchers. + * For example: + *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
+ * @param the matcher type + * @param matchers the matchers to match + * @return the created matcher + */ + @SafeVarargs + public static org.hamcrest.core.AnyOf anyOf(Matcher... matchers) { + return org.hamcrest.core.AnyOf.anyOf(matchers); + } + + /** + * Creates a matcher that matches if the examined object matches ANY of the specified matchers. + * For example: + *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
+ * @param the matcher type + * @param first the first matcher to match + * @param second the second matcher to match + * @return the created matcher + */ + public static org.hamcrest.core.AnyOf anyOf(Matcher first, Matcher second) { + return org.hamcrest.core.AnyOf.anyOf(first, second); + } + + /** + * Creates a matcher that matches if the examined object matches ANY of the specified matchers. + * For example: + *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
+ * @param the matcher type + * @param first the first matcher to match + * @param second the second matcher to match + * @param third the third matcher to match + * @return the created matcher + */ + public static org.hamcrest.core.AnyOf anyOf(Matcher first, Matcher second, Matcher third) { + return org.hamcrest.core.AnyOf.anyOf(first, second, third); + } + + /** + * Creates a matcher that matches if the examined object matches ANY of the specified matchers. + * For example: + *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
+ * @param the matcher type + * @param first the first matcher to match + * @param second the second matcher to match + * @param third the third matcher to match + * @param fourth the forth matcher to match + * @return the created matcher + */ + public static org.hamcrest.core.AnyOf anyOf(Matcher first, Matcher second, Matcher third, Matcher fourth) { + return org.hamcrest.core.AnyOf.anyOf(first, second, third, fourth); + } + + /** + * Creates a matcher that matches if the examined object matches ANY of the specified matchers. + * For example: + *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
+ * @param the matcher type + * @param first the first matcher to match + * @param second the second matcher to match + * @param third the third matcher to match + * @param fourth the forth matcher to match + * @param fifth the fifth matcher to match + * @return the created matcher + */ + public static org.hamcrest.core.AnyOf anyOf(Matcher first, Matcher second, Matcher third, Matcher fourth, Matcher fifth) { + return org.hamcrest.core.AnyOf.anyOf(first, second, third, fourth, fifth); + } + + /** + * Creates a matcher that matches if the examined object matches ANY of the specified matchers. + * For example: + *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
+ * @param the matcher type + * @param first the first matcher to match + * @param second the second matcher to match + * @param third the third matcher to match + * @param fourth the forth matcher to match + * @param fifth the fifth matcher to match + * @param sixth the sixth matcher to match + * @return the created matcher + */ + public static org.hamcrest.core.AnyOf anyOf(Matcher first, Matcher second, Matcher third, Matcher fourth, Matcher fifth, Matcher sixth) { + return org.hamcrest.core.AnyOf.anyOf(first, second, third, fourth, fifth, sixth); + } + + /** + * Creates a matcher that matches when both of the specified matchers match the examined object. + * For example: + *
assertThat("fab", both(containsString("a")).and(containsString("b")))
+ * @param the matcher type + * @param matcher the matcher to match + * @return the created matcher + */ + public static org.hamcrest.core.CombinableMatcher.CombinableBothMatcher both(Matcher matcher) { + return org.hamcrest.core.CombinableMatcher.both(matcher); + } + + /** + * Creates a matcher that matches when either of the specified matchers match the examined object. + * For example: + *
assertThat("fan", either(containsString("a")).or(containsString("b")))
+ * @param the matcher type + * @param matcher the matcher to match + * @return the created matcher + */ + public static org.hamcrest.core.CombinableMatcher.CombinableEitherMatcher either(Matcher matcher) { + return org.hamcrest.core.CombinableMatcher.either(matcher); + } + + /** + * Wraps an existing matcher, overriding its description with that specified. All other functions are + * delegated to the decorated matcher, including its mismatch description. + * For example: + *
describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())
+ * + * @param the matcher type + * @param description + * the new description for the wrapped matcher + * @param matcher + * the matcher to wrap + * @param values + * optional values to insert into the tokenized description + * @return the created matcher + */ + public static Matcher describedAs(String description, Matcher matcher, Object... values) { + return org.hamcrest.core.DescribedAs.describedAs(description, matcher, values); + } + + /** + * Creates a matcher for {@link Iterable}s that only matches when a single pass over the + * examined {@link Iterable} yields items that are all matched by the specified + * itemMatcher. + * For example: + *
assertThat(Arrays.asList("bar", "baz"), everyItem(startsWith("ba")))
+ * + * @param the matcher type + * @param itemMatcher + * the matcher to apply to every item provided by the examined {@link Iterable} + * @return the created matcher + */ + public static Matcher> everyItem(Matcher itemMatcher) { + return org.hamcrest.core.Every.everyItem(itemMatcher); + } + + /** + * Decorates another Matcher, retaining its behaviour, but allowing tests + * to be slightly more expressive. + * For example: + *
assertThat(cheese, is(equalTo(smelly)))
+ * instead of: + *
assertThat(cheese, equalTo(smelly))
+ * @param the matcher type + * @param matcher the matcher to wrap + * @return the created matcher + */ + public static Matcher is(Matcher matcher) { + return org.hamcrest.core.Is.is(matcher); + } + + /** + * A shortcut to the frequently used is(equalTo(x)). + * For example: + *
assertThat(cheese, is(smelly))
+ * instead of: + *
assertThat(cheese, is(equalTo(smelly)))
+ * @param the matcher type + * @param value the value to match + * @return the created matcher + */ + public static Matcher is(T value) { + return org.hamcrest.core.Is.is(value); + } + + /** + * A shortcut to the frequently used is(instanceOf(SomeClass.class)). + * For example: + *
assertThat(cheese, isA(Cheddar.class))
+ * instead of: + *
assertThat(cheese, is(instanceOf(Cheddar.class)))
+ * @param the matcher type + * @param type the type to match + * @return the created matcher + */ + public static Matcher isA(Class type) { + return org.hamcrest.core.Is.isA(type); + } + + /** + * Creates a matcher that always matches, regardless of the examined object. + * @return the created matcher + */ + public static Matcher anything() { + return org.hamcrest.core.IsAnything.anything(); + } + + /** + * Creates a matcher that always matches, regardless of the examined object, but describes + * itself with the specified {@link String}. + * + * @param description + * a meaningful {@link String} used when describing itself + * @return the created matcher + */ + public static Matcher anything(String description) { + return org.hamcrest.core.IsAnything.anything(description); + } + + /** + * Creates a matcher for {@link Iterable}s that only matches when a single pass over the + * examined {@link Iterable} yields at least one item that is matched by the specified + * itemMatcher. Whilst matching, the traversal of the examined {@link Iterable} + * will stop as soon as a matching item is found. + * For example: + *
assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))
+ * + * @param the matcher type + * @param itemMatcher + * the matcher to apply to items provided by the examined {@link Iterable} + * @return the created matcher + */ + public static Matcher> hasItem(Matcher itemMatcher) { + return IsIterableContaining.hasItem(itemMatcher); + } + + /** + * Creates a matcher for {@link Iterable}s that only matches when a single pass over the + * examined {@link Iterable} yields at least one item that is equal to the specified + * item. Whilst matching, the traversal of the examined {@link Iterable} + * will stop as soon as a matching item is found. + * For example: + *
assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))
+ * + * @param the matcher type + * @param item + * the item to compare against the items provided by the examined {@link Iterable} + * @return the created matcher + */ + public static Matcher> hasItem(T item) { + return IsIterableContaining.hasItem(item); + } + + /** + * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the + * examined {@link Iterable} yield at least one item that is matched by the corresponding + * matcher from the specified itemMatchers. Whilst matching, each traversal of + * the examined {@link Iterable} will stop as soon as a matching item is found. + * For example: + *
assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))
+ * + * @param the matcher type + * @param itemMatchers + * the matchers to apply to items provided by the examined {@link Iterable} + * @return the created matcher + */ + @SafeVarargs + public static Matcher> hasItems(Matcher... itemMatchers) { + return IsIterableContaining.hasItems(itemMatchers); + } + + /** + * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the + * examined {@link Iterable} yield at least one item that is equal to the corresponding + * item from the specified items. Whilst matching, each traversal of the + * examined {@link Iterable} will stop as soon as a matching item is found. + * For example: + *
assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))
+ * + * @param the matcher type + * @param items + * the items to compare against the items provided by the examined {@link Iterable} + * @return the created matcher + */ + @SafeVarargs + public static Matcher> hasItems(T... items) { + return IsIterableContaining.hasItems(items); + } + + /** + * Creates a matcher that matches when the examined object is logically equal to the specified + * operand, as determined by calling the {@link java.lang.Object#equals} method on + * the examined object. + * + *

If the specified operand is null then the created matcher will only match if + * the examined object's equals method returns true when passed a + * null (which would be a violation of the equals contract), unless the + * examined object itself is null, in which case the matcher will return a positive + * match.

+ * + *

The created matcher provides a special behaviour when examining Arrays, whereby + * it will match if both the operand and the examined object are arrays of the same length and + * contain items that are equal to each other (according to the above rules) in the same + * indexes.

+ * For example: + *
+     * assertThat("foo", equalTo("foo"));
+     * assertThat(new String[] {"foo", "bar"}, equalTo(new String[] {"foo", "bar"}));
+     * 
+ * @param the matcher type + * @param operand the operand to match + * @return the created matcher + */ + public static Matcher equalTo(T operand) { + return org.hamcrest.core.IsEqual.equalTo(operand); + } + + /** + * Creates an {@link org.hamcrest.core.IsEqual} matcher that does not enforce the values being + * compared to be of the same static type. + * @param operand the operand to match + * @return the created matcher + */ + public static Matcher equalToObject(Object operand) { + return org.hamcrest.core.IsEqual.equalToObject(operand); + } + + /** + * Creates a matcher that matches when the examined object is an instance of the specified type, + * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the + * the examined object. + * + *

The created matcher forces a relationship between specified type and the examined object, and should be + * used when it is necessary to make generics conform, for example in the JMock clause + * with(any(Thing.class))

+ * For example: + *
assertThat(new Canoe(), instanceOf(Canoe.class));
+ * @param the matcher type + * @param type the type to match + * @return the created matcher + */ + public static Matcher any(Class type) { + return org.hamcrest.core.IsInstanceOf.any(type); + } + + /** + * Creates a matcher that matches when the examined object is an instance of the specified type, + * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the + * the examined object. + * + *

The created matcher assumes no relationship between specified type and the examined object.

+ * For example: + *
assertThat(new Canoe(), instanceOf(Paddlable.class));
+ * @param the matcher type + * @param type the type to match + * @return the created matcher + */ + public static Matcher instanceOf(Class type) { + return org.hamcrest.core.IsInstanceOf.instanceOf(type); + } + + /** + * Creates a matcher that wraps an existing matcher, but inverts the logic by which + * it will match. + * For example: + *
assertThat(cheese, is(not(equalTo(smelly))))
+ * + * @param the matcher type + * @param matcher + * the matcher whose sense should be inverted + * @return the created matcher + */ + public static Matcher not(Matcher matcher) { + return org.hamcrest.core.IsNot.not(matcher); + } + + /** + * A shortcut to the frequently used not(equalTo(x)). + * For example: + *
assertThat(cheese, is(not(smelly)))
+ * instead of: + *
assertThat(cheese, is(not(equalTo(smelly))))
+ * + * @param the matcher type + * @param value + * the value that any examined object should not equal + * @return the created matcher + */ + public static Matcher not(T value) { + return org.hamcrest.core.IsNot.not(value); + } + + /** + * A shortcut to the frequently used not(nullValue()). + * For example: + *
assertThat(cheese, is(notNullValue()))
+ * instead of: + *
assertThat(cheese, is(not(nullValue())))
+ * @return the created matcher + */ + public static Matcher notNullValue() { + return org.hamcrest.core.IsNull.notNullValue(); + } + + /** + * A shortcut to the frequently used not(nullValue(X.class)). Accepts a + * single dummy argument to facilitate type inference.. + * For example: + *
assertThat(cheese, is(notNullValue(X.class)))
+ * instead of: + *
assertThat(cheese, is(not(nullValue(X.class))))
+ * + * @param the matcher type + * @param type + * dummy parameter used to infer the generic type of the returned matcher + * @return the created matcher + */ + public static Matcher notNullValue(Class type) { + return org.hamcrest.core.IsNull.notNullValue(type); + } + + /** + * Creates a matcher that matches if examined object is null. + * For example: + *
assertThat(cheese, is(nullValue())
+ * @return the created matcher + */ + public static Matcher nullValue() { + return org.hamcrest.core.IsNull.nullValue(); + } + + /** + * Creates a matcher that matches if examined object is null. Accepts a + * single dummy argument to facilitate type inference. + * For example: + *
assertThat(cheese, is(nullValue(Cheese.class))
+ * + * @param the matcher type + * @param type + * dummy parameter used to infer the generic type of the returned matcher + * @return the created matcher + */ + public static Matcher nullValue(Class type) { + return org.hamcrest.core.IsNull.nullValue(type); + } + + /** + * Creates a matcher that matches only when the examined object is the same instance as + * the specified target object. + * + * @param the matcher type + * @param target + * the target instance against which others should be assessed + * @return the created matcher + */ + public static Matcher sameInstance(T target) { + return org.hamcrest.core.IsSame.sameInstance(target); + } + + /** + * Creates a matcher that matches only when the examined object is the same instance as + * the specified target object. + * + * @param the matcher type + * @param target + * the target instance against which others should be assessed + * @return the created matcher + */ + public static Matcher theInstance(T target) { + return org.hamcrest.core.IsSame.theInstance(target); + } + + /** + * Creates a matcher that matches if the examined {@link String} contains the specified + * {@link String} anywhere. + * For example: + *
assertThat("myStringOfNote", containsString("ring"))
+ * + * @param substring + * the substring that the returned matcher will expect to find within any examined string + * @return the created matcher + */ + public static Matcher containsString(String substring) { + return org.hamcrest.core.StringContains.containsString(substring); + } + + /** + * Creates a matcher that matches if the examined {@link String} contains the specified + * {@link String} anywhere, ignoring case. + * For example: + *
assertThat("myStringOfNote", containsStringIgnoringCase("Ring"))
+ * + * @param substring + * the substring that the returned matcher will expect to find within any examined string + * @return the created matcher + */ + public static Matcher containsStringIgnoringCase(String substring) { + return org.hamcrest.core.StringContains.containsStringIgnoringCase(substring); + } + + /** + *

+ * Creates a matcher that matches if the examined {@link String} starts with the specified + * {@link String}. + *

+ * For example: + *
assertThat("myStringOfNote", startsWith("my"))
+ * + * @param prefix + * the substring that the returned matcher will expect at the start of any examined string + * @return the created matcher + */ + public static Matcher startsWith(String prefix) { + return org.hamcrest.core.StringStartsWith.startsWith(prefix); + } + + /** + *

+ * Creates a matcher that matches if the examined {@link String} starts with the specified + * {@link String}, ignoring case + *

+ * For example: + *
assertThat("myStringOfNote", startsWithIgnoringCase("My"))
+ * + * @param prefix + * the substring that the returned matcher will expect at the start of any examined string + * @return the created matcher + */ + public static Matcher startsWithIgnoringCase(String prefix) { + return org.hamcrest.core.StringStartsWith.startsWithIgnoringCase(prefix); + } + + /** + * Creates a matcher that matches if the examined {@link String} ends with the specified + * {@link String}. + * For example: + *
assertThat("myStringOfNote", endsWith("Note"))
+ * + * @param suffix + * the substring that the returned matcher will expect at the end of any examined string + * @return the created matcher + */ + public static Matcher endsWith(String suffix) { + return org.hamcrest.core.StringEndsWith.endsWith(suffix); + } + + /** + * Creates a matcher that matches if the examined {@link String} ends with the specified + * {@link String}, ignoring case. + * For example: + *
assertThat("myStringOfNote", endsWithIgnoringCase("note"))
+ * + * @param suffix + * the substring that the returned matcher will expect at the end of any examined string + * @return the created matcher + */ + public static Matcher endsWithIgnoringCase(String suffix) { + return org.hamcrest.core.StringEndsWith.endsWithIgnoringCase(suffix); + } + + /** + * Validate a string with a {@link java.util.regex.Pattern}. + * + *
+     * assertThat("abc", matchesRegex(Pattern.compile("ˆ[a-z]$"));
+     * 
+ * + * @param pattern + * the pattern to be used. + * @return the created matcher + */ + public static Matcher matchesRegex(Pattern pattern) { + return StringRegularExpression.matchesRegex(pattern); + } + + /** + * Validate a string with a regex. + * + *
+     * assertThat("abc", matchesRegex("ˆ[a-z]+$"));
+     * 
+ * + * @param regex + * The regex to be used for the validation. + * @return the created matcher + */ + public static Matcher matchesRegex(String regex) { + return StringRegularExpression.matchesRegex(Pattern.compile(regex)); + } + + /** + * Creates a matcher that matches arrays whose elements are satisfied by the specified matchers. Matches + * positively only if the number of matchers specified is equal to the length of the examined array and + * each matcher[i] is satisfied by array[i]. + * For example: + *
assertThat(new Integer[]{1,2,3}, is(array(equalTo(1), equalTo(2), equalTo(3))))
+ * + * @param the matcher type + * @param elementMatchers + * the matchers that the elements of examined arrays should satisfy + * @return the created matcher + */ + @SafeVarargs + public static org.hamcrest.collection.IsArray array(Matcher... elementMatchers) { + return org.hamcrest.collection.IsArray.array(elementMatchers); + } + + /** + * Creates a matcher for arrays that matches when the examined array contains at least one item + * that is matched by the specified elementMatcher. Whilst matching, the traversal + * of the examined array will stop as soon as a matching element is found. + * For example: + *
assertThat(new String[] {"foo", "bar"}, hasItemInArray(startsWith("ba")))
+ * + * @param the matcher type + * @param elementMatcher + * the matcher to apply to elements in examined arrays + * @return the created matcher + */ + public static Matcher hasItemInArray(Matcher elementMatcher) { + return ArrayMatching.hasItemInArray(elementMatcher); + } + + /** + * A shortcut to the frequently used hasItemInArray(equalTo(x)). + * For example: + *
assertThat(hasItemInArray(x))
+ * instead of: + *
assertThat(hasItemInArray(equalTo(x)))
+ * + * @param the matcher type + * @param element + * the element that should be present in examined arrays + * @return the created matcher + */ + public static Matcher hasItemInArray(T element) { + return ArrayMatching.hasItemInArray(element); + } + + /** + * Creates a matcher for arrays that matches when each item in the examined array is + * logically equal to the corresponding item in the specified items. For a positive match, + * the examined array must be of the same length as the number of specified items. + * For example: + *
assertThat(new String[]{"foo", "bar"}, arrayContaining("foo", "bar"))
+ * + * @param the matcher type + * @param items + * the items that must equal the items within an examined array + * @return the created matcher + */ + @SafeVarargs + public static Matcher arrayContaining(T... items) { + return ArrayMatching.arrayContaining(items); + } + + /** + * Creates a matcher for arrays that matches when each item in the examined array satisfies the + * corresponding matcher in the specified matchers. For a positive match, the examined array + * must be of the same length as the number of specified matchers. + * For example: + *
assertThat(new String[]{"foo", "bar"}, arrayContaining(equalTo("foo"), equalTo("bar")))
+ * + * @param the matcher type + * @param itemMatchers + * the matchers that must be satisfied by the items in the examined array + * @return the created matcher + */ + @SafeVarargs + public static Matcher arrayContaining(Matcher... itemMatchers) { + return ArrayMatching.arrayContaining(itemMatchers); + } + + /** + * Creates a matcher for arrays that matches when each item in the examined array satisfies the + * corresponding matcher in the specified list of matchers. For a positive match, the examined array + * must be of the same length as the specified list of matchers. + * For example: + *
assertThat(new String[]{"foo", "bar"}, arrayContaining(Arrays.asList(equalTo("foo"), equalTo("bar"))))
+ * + * @param the matcher type + * @param itemMatchers + * a list of matchers, each of which must be satisfied by the corresponding item in an examined array + * @return the created matcher + */ + public static Matcher arrayContaining(List> itemMatchers) { + return ArrayMatching.arrayContaining(itemMatchers); + } + + /** + *

+ * Creates an order agnostic matcher for arrays that matches when each item in the + * examined array satisfies one matcher anywhere in the specified matchers. + * For a positive match, the examined array must be of the same length as the number of + * specified matchers. + *

+ *

+ * N.B. each of the specified matchers will only be used once during a given examination, so be + * careful when specifying matchers that may be satisfied by more than one entry in an examined + * array. + *

+ *

+ * For example: + *

+ *
assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(equalTo("bar"), equalTo("foo")))
+ * + * @param the matcher type + * @param itemMatchers + * a list of matchers, each of which must be satisfied by an entry in an examined array + * @return the created matcher + */ + @SafeVarargs + public static Matcher arrayContainingInAnyOrder(Matcher... itemMatchers) { + return ArrayMatching.arrayContainingInAnyOrder(itemMatchers); + } + + /** + *

+ * Creates an order agnostic matcher for arrays that matches when each item in the + * examined array satisfies one matcher anywhere in the specified collection of matchers. + * For a positive match, the examined array must be of the same length as the specified collection + * of matchers. + *

+ *

+ * N.B. each matcher in the specified collection will only be used once during a given + * examination, so be careful when specifying matchers that may be satisfied by more than + * one entry in an examined array. + *

+ *

+ * For example: + *

+ *
assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(Arrays.asList(equalTo("bar"), equalTo("foo"))))
+ * + * @param the matcher type + * @param itemMatchers + * a list of matchers, each of which must be satisfied by an item provided by an examined array + * @return the created matcher + */ + public static Matcher arrayContainingInAnyOrder(Collection> itemMatchers) { + return ArrayMatching.arrayContainingInAnyOrder(itemMatchers); + } + + /** + *

Creates an order agnostic matcher for arrays that matches when each item in the + * examined array is logically equal to one item anywhere in the specified items. + * For a positive match, the examined array must be of the same length as the number of + * specified items. + *

+ *

N.B. each of the specified items will only be used once during a given examination, so be + * careful when specifying items that may be equal to more than one entry in an examined + * array. + *

+ *

+ * For example: + *

+ *
assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder("bar", "foo"))
+ * + * @param the matcher type + * @param items + * the items that must equal the entries of an examined array, in any order + * @return the created matcher + */ + @SafeVarargs + public static Matcher arrayContainingInAnyOrder(T... items) { + return ArrayMatching.arrayContainingInAnyOrder(items); + } + + /** + * Creates a matcher for arrays that matches when the length of the array + * satisfies the specified matcher. + * For example: + *
assertThat(new String[]{"foo", "bar"}, arrayWithSize(equalTo(2)))
+ * + * @param the matcher type + * @param sizeMatcher + * a matcher for the length of an examined array + * @return the created matcher + */ + public static Matcher arrayWithSize(Matcher sizeMatcher) { + return org.hamcrest.collection.IsArrayWithSize.arrayWithSize(sizeMatcher); + } + + /** + * Creates a matcher for arrays that matches when the length of the array + * equals the specified size. + * For example: + *
assertThat(new String[]{"foo", "bar"}, arrayWithSize(2))
+ * + * @param the matcher type + * @param size + * the length that an examined array must have for a positive match + * @return the created matcher + */ + public static Matcher arrayWithSize(int size) { + return org.hamcrest.collection.IsArrayWithSize.arrayWithSize(size); + } + + /** + * Creates a matcher for arrays that matches when the length of the array + * is zero. + * For example: + *
assertThat(new String[0], emptyArray())
+ * @param the matcher type + * @return the created matcher + */ + public static Matcher emptyArray() { + return org.hamcrest.collection.IsArrayWithSize.emptyArray(); + } + + /** + * Creates a matcher for {@link java.util.Map}s that matches when the size() method returns + * a value that satisfies the specified matcher. + * For example: + *
assertThat(myMap, is(aMapWithSize(equalTo(2))))
+ * + * @param the map key type + * @param the map value type + * @param sizeMatcher + * a matcher for the size of an examined {@link java.util.Map} + * @return the created matcher + */ + public static Matcher> aMapWithSize(Matcher sizeMatcher) { + return org.hamcrest.collection.IsMapWithSize.aMapWithSize(sizeMatcher); + } + + /** + * Creates a matcher for {@link java.util.Map}s that matches when the size() method returns + * a value equal to the specified size. + * For example: + *
assertThat(myMap, is(aMapWithSize(2)))
+ * + * @param the map key type + * @param the map value type + * @param size + * the expected size of an examined {@link java.util.Map} + * @return the created matcher + */ + public static Matcher> aMapWithSize(int size) { + return org.hamcrest.collection.IsMapWithSize.aMapWithSize(size); + } + + /** + * Creates a matcher for {@link java.util.Map}s that matches when the size() method returns + * zero. + * For example: + *
assertThat(myMap, is(anEmptyMap()))
+ * @param the map key type + * @param the map value type + * @return the created matcher + */ + public static Matcher> anEmptyMap() { + return org.hamcrest.collection.IsMapWithSize.anEmptyMap(); + } + + /** + * Creates a matcher for {@link java.util.Collection}s that matches when the size() method returns + * a value that satisfies the specified matcher. + * For example: + *
assertThat(Arrays.asList("foo", "bar"), hasSize(equalTo(2)))
+ * + * @param the matcher type + * @param sizeMatcher + * a matcher for the size of an examined {@link java.util.Collection} + * @return the created matcher + */ + public static Matcher> hasSize(Matcher sizeMatcher) { + return org.hamcrest.collection.IsCollectionWithSize.hasSize(sizeMatcher); + } + + /** + * Creates a matcher for {@link java.util.Collection}s that matches when the size() method returns + * a value equal to the specified size. + * For example: + *
assertThat(Arrays.asList("foo", "bar"), hasSize(2))
+ * + * @param the matcher type + * @param size + * the expected size of an examined {@link java.util.Collection} + * @return the created matcher + */ + public static Matcher> hasSize(int size) { + return org.hamcrest.collection.IsCollectionWithSize.hasSize(size); + } + + /** + * Creates a matcher for {@link java.util.Collection}s matching examined collections whose isEmpty + * method returns true. + * For example: + *
assertThat(new ArrayList<String>(), is(empty()))
+ * @param the matcher type + * @return the created matcher + */ + public static Matcher> empty() { + return org.hamcrest.collection.IsEmptyCollection.empty(); + } + + /** + * Creates a matcher for {@link java.util.Collection}s matching examined collections whose isEmpty + * method returns true. + * For example: + *
assertThat(new ArrayList<String>(), is(emptyCollectionOf(String.class)))
+ * + * @param the matcher type + * @param unusedToForceReturnType + * the type of the collection's content + * @return the created matcher + */ + public static Matcher> emptyCollectionOf(Class unusedToForceReturnType) { + return org.hamcrest.collection.IsEmptyCollection.emptyCollectionOf(unusedToForceReturnType); + } + + /** + * Creates a matcher for {@link Iterable}s matching examined iterables that yield no items. + * For example: + *
assertThat(new ArrayList<String>(), is(emptyIterable()))
+ * @param the matcher type + * @return the created matcher + */ + public static Matcher> emptyIterable() { + return org.hamcrest.collection.IsEmptyIterable.emptyIterable(); + } + + /** + * Creates a matcher for {@link Iterable}s matching examined iterables that yield no items. + * For example: + *
assertThat(new ArrayList<String>(), is(emptyIterableOf(String.class)))
+ * + * @param the matcher type + * @param unusedToForceReturnType + * the type of the iterable's content + * @return the created matcher + */ + public static Matcher> emptyIterableOf(Class unusedToForceReturnType) { + return org.hamcrest.collection.IsEmptyIterable.emptyIterableOf(unusedToForceReturnType); + } + + /** + * Creates a matcher for {@link Iterable}s that matches when a single pass over the + * examined {@link Iterable} yields a series of items, each logically equal to the + * corresponding item in the specified items. For a positive match, the examined iterable + * must be of the same length as the number of specified items. + * For example: + *
assertThat(Arrays.asList("foo", "bar"), contains("foo", "bar"))
+ * + * @param the matcher type + * @param items + * the items that must equal the items provided by an examined {@link Iterable} + * @return the created matcher + */ + @SafeVarargs + public static Matcher> contains(T... items) { + return org.hamcrest.collection.IsIterableContainingInOrder.contains(items); + } + + /** + * Creates a matcher for {@link Iterable}s that matches when a single pass over the + * examined {@link Iterable} yields a single item that satisfies the specified matcher. + * For a positive match, the examined iterable must only yield one item. + * For example: + *
assertThat(Arrays.asList("foo"), contains(equalTo("foo")))
+ * + * @param the matcher type + * @param itemMatcher + * the matcher that must be satisfied by the single item provided by an + * examined {@link Iterable} + * @return the created matcher + */ + public static Matcher> contains(Matcher itemMatcher) { + return org.hamcrest.collection.IsIterableContainingInOrder.contains(itemMatcher); + } + + /** + * Creates a matcher for {@link Iterable}s that matches when a single pass over the + * examined {@link Iterable} yields a series of items, each satisfying the corresponding + * matcher in the specified matchers. For a positive match, the examined iterable + * must be of the same length as the number of specified matchers. + * For example: + *
assertThat(Arrays.asList("foo", "bar"), contains(equalTo("foo"), equalTo("bar")))
+ * + * @param the matcher type + * @param itemMatchers + * the matchers that must be satisfied by the items provided by an examined {@link Iterable} + * @return the created matcher + */ + @SafeVarargs + public static Matcher> contains(Matcher... itemMatchers) { + return org.hamcrest.collection.IsIterableContainingInOrder.contains(itemMatchers); + } + + /** + * Creates a matcher for {@link Iterable}s that matches when a single pass over the + * examined {@link Iterable} yields a series of items, each satisfying the corresponding + * matcher in the specified list of matchers. For a positive match, the examined iterable + * must be of the same length as the specified list of matchers. + * For example: + *
assertThat(Arrays.asList("foo", "bar"), contains(Arrays.asList(equalTo("foo"), equalTo("bar"))))
+ * + * @param the matcher type + * @param itemMatchers + * a list of matchers, each of which must be satisfied by the corresponding item provided by + * an examined {@link Iterable} + * @return the created matcher + */ + public static Matcher> contains(List> itemMatchers) { + return org.hamcrest.collection.IsIterableContainingInOrder.contains(itemMatchers); + } + + /** + *

+ * Creates an order agnostic matcher for {@link Iterable}s that matches when a single pass over + * the examined {@link Iterable} yields a series of items, each satisfying one matcher anywhere + * in the specified matchers. For a positive match, the examined iterable must be of the same + * length as the number of specified matchers. + *

+ *

+ * N.B. each of the specified matchers will only be used once during a given examination, so be + * careful when specifying matchers that may be satisfied by more than one entry in an examined + * iterable. + *

+ *

+ * For example: + *

+ *
assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder(equalTo("bar"), equalTo("foo")))
+ * + * @param the matcher type + * @param itemMatchers + * a list of matchers, each of which must be satisfied by an item provided by an examined {@link Iterable} + * @return the created matcher + */ + @SafeVarargs + public static Matcher> containsInAnyOrder(Matcher... itemMatchers) { + return org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder(itemMatchers); + } + + /** + *

+ * Creates an order agnostic matcher for {@link Iterable}s that matches when a single pass over + * the examined {@link Iterable} yields a series of items, each logically equal to one item + * anywhere in the specified items. For a positive match, the examined iterable + * must be of the same length as the number of specified items. + *

+ *

+ * N.B. each of the specified items will only be used once during a given examination, so be + * careful when specifying items that may be equal to more than one entry in an examined + * iterable. + *

+ *

+ * For example: + *

+ *
assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder("bar", "foo"))
+ * + * @param the matcher type + * @param items + * the items that must equal the items provided by an examined {@link Iterable} in any order + * @return the created matcher + */ + @SafeVarargs + public static Matcher> containsInAnyOrder(T... items) { + return org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder(items); + } + + /** + *

+ * Creates an order agnostic matcher for {@link Iterable}s that matches when a single pass over + * the examined {@link Iterable} yields a series of items, each satisfying one matcher anywhere + * in the specified collection of matchers. For a positive match, the examined iterable + * must be of the same length as the specified collection of matchers. + *

+ *

+ * N.B. each matcher in the specified collection will only be used once during a given + * examination, so be careful when specifying matchers that may be satisfied by more than + * one entry in an examined iterable. + *

+ *

For example:

+ *
assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder(Arrays.asList(equalTo("bar"), equalTo("foo"))))
+ * + * @param the matcher type + * @param itemMatchers + * a list of matchers, each of which must be satisfied by an item provided by an examined {@link Iterable} + * @return the created matcher + */ + public static Matcher> containsInAnyOrder(Collection> itemMatchers) { + return org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder(itemMatchers); + } + + /** + * Creates a matcher for {@link Iterable}s that matches when a single pass over the + * examined {@link Iterable} yields a series of items, that contains items logically equal to the + * corresponding item in the specified items, in the same relative order + * For example: + *
assertThat(Arrays.asList("a", "b", "c", "d", "e"), containsInRelativeOrder("b", "d"))
+ * + * @param the matcher type + * @param items + * the items that must be contained within items provided by an examined {@link Iterable} in the same relative order + * @return the created matcher + */ + @SafeVarargs + public static Matcher> containsInRelativeOrder(T... items) { + return org.hamcrest.collection.IsIterableContainingInRelativeOrder.containsInRelativeOrder(items); + } + + /** + * Creates a matcher for {@link Iterable}s that matches when a single pass over the + * examined {@link Iterable} yields a series of items, that each satisfying the corresponding + * matcher in the specified matchers, in the same relative order. + * For example: + *
assertThat(Arrays.asList("a", "b", "c", "d", "e"), containsInRelativeOrder(equalTo("b"), equalTo("d")))
+ * + * @param the matcher type + * @param itemMatchers + * the matchers that must be satisfied by the items provided by an examined {@link Iterable} in the same relative order + * @return the created matcher + */ + @SafeVarargs + public static Matcher> containsInRelativeOrder(Matcher... itemMatchers) { + return org.hamcrest.collection.IsIterableContainingInRelativeOrder.containsInRelativeOrder(itemMatchers); + } + + /** + * Creates a matcher for {@link Iterable}s that matches when a single pass over the + * examined {@link Iterable} yields a series of items, that contains items satisfying the corresponding + * matcher in the specified list of matchers, in the same relative order. + * For example: + *
assertThat(Arrays.asList("a", "b", "c", "d", "e"), contains(Arrays.asList(equalTo("b"), equalTo("d"))))
+ * + * @param the matcher type + * @param itemMatchers + * a list of matchers, each of which must be satisfied by the items provided by + * an examined {@link Iterable} in the same relative order + * @return the created matcher + */ + public static Matcher> containsInRelativeOrder(List> itemMatchers) { + return org.hamcrest.collection.IsIterableContainingInRelativeOrder.containsInRelativeOrder(itemMatchers); + } + + /** + * Creates a matcher for {@link Iterable}s that matches when a single pass over the + * examined {@link Iterable} yields an item count that satisfies the specified + * matcher. + * For example: + *
assertThat(Arrays.asList("foo", "bar"), iterableWithSize(equalTo(2)))
+ * + * @param the matcher type + * @param sizeMatcher + * a matcher for the number of items that should be yielded by an examined {@link Iterable} + * @return the created matcher + */ + public static Matcher> iterableWithSize(Matcher sizeMatcher) { + return org.hamcrest.collection.IsIterableWithSize.iterableWithSize(sizeMatcher); + } + + /** + * Creates a matcher for {@link Iterable}s that matches when a single pass over the + * examined {@link Iterable} yields an item count that is equal to the specified + * size argument. + * For example: + *
assertThat(Arrays.asList("foo", "bar"), iterableWithSize(2))
+ * + * @param the matcher type + * @param size + * the number of items that should be yielded by an examined {@link Iterable} + * @return the created matcher + */ + public static Matcher> iterableWithSize(int size) { + return org.hamcrest.collection.IsIterableWithSize.iterableWithSize(size); + } + + /** + * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains + * at least one entry whose key satisfies the specified keyMatcher and whose + * value satisfies the specified valueMatcher. + * For example: + *
assertThat(myMap, hasEntry(equalTo("bar"), equalTo("foo")))
+ * + * @param the map key type + * @param the map value type + * @param keyMatcher + * the key matcher that, in combination with the valueMatcher, must be satisfied by at least one entry + * @param valueMatcher + * the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entry + * @return the created matcher + */ + public static Matcher> hasEntry(Matcher keyMatcher, Matcher valueMatcher) { + return org.hamcrest.collection.IsMapContaining.hasEntry(keyMatcher, valueMatcher); + } -@SuppressWarnings({"unused", "WeakerAccess"}) -public class Matchers { + /** + * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains + * at least one entry whose key equals the specified key and whose value equals the + * specified value. + * For example: + *
assertThat(myMap, hasEntry("bar", "foo"))
+ * + * @param the map key type + * @param the map value type + * @param key + * the key that, in combination with the value, must be describe at least one entry + * @param value + * the value that, in combination with the key, must be describe at least one entry + * @return the created matcher + */ + public static Matcher> hasEntry(K key, V value) { + return org.hamcrest.collection.IsMapContaining.hasEntry(key, value); + } + + /** + * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains + * at least one key that satisfies the specified matcher. + * For example: + *
assertThat(myMap, hasKey(equalTo("bar")))
+ * + * @param the map key type + * @param keyMatcher + * the matcher that must be satisfied by at least one key + * @return the created matcher + */ + public static Matcher> hasKey(Matcher keyMatcher) { + return org.hamcrest.collection.IsMapContaining.hasKey(keyMatcher); + } + + /** + * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains + * at least one key that is equal to the specified key. + * For example: + *
assertThat(myMap, hasKey("bar"))
+ * + * @param the map key type + * @param key + * the key that satisfying maps must contain + * @return the created matcher + */ + public static Matcher> hasKey(K key) { + return org.hamcrest.collection.IsMapContaining.hasKey(key); + } + + /** + * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains + * at least one value that satisfies the specified valueMatcher. + * For example: + *
assertThat(myMap, hasValue(equalTo("foo")))
+ * + * @param the map value type + * @param valueMatcher + * the matcher that must be satisfied by at least one value + * @return the created matcher + */ + public static Matcher> hasValue(Matcher valueMatcher) { + return org.hamcrest.collection.IsMapContaining.hasValue(valueMatcher); + } + + /** + * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains + * at least one value that is equal to the specified value. + * For example: + *
assertThat(myMap, hasValue("foo"))
+ * + * @param the map value type + * @param value + * the value that satisfying maps must contain + * @return the created matcher + */ + public static Matcher> hasValue(V value) { + return org.hamcrest.collection.IsMapContaining.hasValue(value); + } + + /** + * Creates a matcher that matches when the examined object is found within the + * specified collection. + * For example: + *
assertThat("foo", is(in(Arrays.asList("bar", "foo"))))
+ * + * @param the matcher type + * @param collection + * the collection in which matching items must be found + * @return the created matcher + */ + public static Matcher in(java.util.Collection collection) { + return org.hamcrest.collection.IsIn.in(collection); + } + + /** + * Creates a matcher that matches when the examined object is found within the + * specified array. + * For example: + *
assertThat("foo", is(in(new String[]{"bar", "foo"})))
+ * + * @param the matcher type + * @param elements + * the array in which matching items must be found + * @return the created matcher + */ + public static Matcher in(T[] elements) { + return org.hamcrest.collection.IsIn.in(elements); + } + + /** + * Creates a matcher that matches when the examined object is found within the + * specified collection. + * For example: + *
assertThat("foo", isIn(Arrays.asList("bar", "foo")))
+ * + * @param the matcher type + * @deprecated use is(in(...)) instead + * @param collection + * the collection in which matching items must be found + * @return the created matcher + */ + @SuppressWarnings("deprecation") + public static Matcher isIn(java.util.Collection collection) { + return org.hamcrest.collection.IsIn.isIn(collection); + } + + /** + * Creates a matcher that matches when the examined object is found within the + * specified array. + * For example: + *
assertThat("foo", isIn(new String[]{"bar", "foo"}))
+ * + * @param the matcher type + * @deprecated use is(in(...)) instead + * @param elements + * the array in which matching items must be found + * @return the created matcher + */ + @SuppressWarnings("deprecation") + public static Matcher isIn(T[] elements) { + return org.hamcrest.collection.IsIn.isIn(elements); + } + + /** + * Creates a matcher that matches when the examined object is equal to one of the + * specified elements. + * For example: + *
assertThat("foo", isOneOf("bar", "foo"))
+ * + * @param the matcher type + * @deprecated use is(oneOf(...)) instead + * @param elements + * the elements amongst which matching items will be found + * @return the created matcher + */ + @SuppressWarnings("deprecation") + @SafeVarargs + public static Matcher isOneOf(T... elements) { + return org.hamcrest.collection.IsIn.isOneOf(elements); + } + + /** + * Creates a matcher that matches when the examined object is equal to one of the + * specified elements. + * For example: + *
assertThat("foo", is(oneOf("bar", "foo")))
+ * + * @param the matcher type + * @param elements + * the elements amongst which matching items will be found + * @return the created matcher + */ + @SafeVarargs + public static Matcher oneOf(T... elements) { + return org.hamcrest.collection.IsIn.oneOf(elements); + } + + /** + * Creates a matcher of {@link Double}s that matches when an examined double is equal + * to the specified operand, within a range of +/- error. + * For example: + *
assertThat(1.03, is(closeTo(1.0, 0.03)))
+ * + * @param operand + * the expected value of matching doubles + * @param error + * the delta (+/-) within which matches will be allowed + * @return the created matcher + */ + public static Matcher closeTo(double operand, double error) { + return org.hamcrest.number.IsCloseTo.closeTo(operand, error); + } + + /** + * Creates a matcher of {@link Double}s that matches when an examined double is not a number. + * For example: + *
assertThat(Double.NaN, is(notANumber()))
+ * @return the created matcher + */ + public static Matcher notANumber() { + return org.hamcrest.number.IsNaN.notANumber(); + } + + /** + * Creates a matcher of {@link java.math.BigDecimal}s that matches when an examined BigDecimal is equal + * to the specified operand, within a range of +/- error. The comparison for equality + * is done by BigDecimals {@link java.math.BigDecimal#compareTo(java.math.BigDecimal)} method. + * For example: + *
assertThat(new BigDecimal("1.03"), is(closeTo(new BigDecimal("1.0"), new BigDecimal("0.03"))))
+ * + * @param operand + * the expected value of matching BigDecimals + * @param error + * the delta (+/-) within which matches will be allowed + * @return the created matcher + */ + public static Matcher closeTo(java.math.BigDecimal operand, java.math.BigDecimal error) { + return org.hamcrest.number.BigDecimalCloseTo.closeTo(operand, error); + } + + /** + * Creates a matcher of {@link Comparable} object that matches when the examined object is + * equal to the specified value, as reported by the compareTo method of the + * examined object. + * For example: + *
assertThat(1, comparesEqualTo(1))
+ * + * @param the matcher type + * @param value the value which, when passed to the compareTo method of the examined object, should return zero + * @return the created matcher + */ + public static > Matcher comparesEqualTo(T value) { + return org.hamcrest.number.OrderingComparison.comparesEqualTo(value); + } + + /** + * Creates a matcher of {@link Comparable} object that matches when the examined object is + * greater than the specified value, as reported by the compareTo method of the + * examined object. + * For example: + *
assertThat(2, greaterThan(1))
+ * + * @param the matcher type + * @param value the value which, when passed to the compareTo method of the examined object, should return greater + * than zero + * @return the created matcher + */ + public static > Matcher greaterThan(T value) { + return org.hamcrest.number.OrderingComparison.greaterThan(value); + } + + /** + * Creates a matcher of {@link Comparable} object that matches when the examined object is + * greater than or equal to the specified value, as reported by the compareTo method + * of the examined object. + * For example: + *
assertThat(1, greaterThanOrEqualTo(1))
+ * + * @param the matcher type + * @param value the value which, when passed to the compareTo method of the examined object, should return greater + * than or equal to zero + * @return the created matcher + */ + public static > Matcher greaterThanOrEqualTo(T value) { + return org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo(value); + } + + /** + * Creates a matcher of {@link Comparable} object that matches when the examined object is + * less than the specified value, as reported by the compareTo method of the + * examined object. + * For example: + *
assertThat(1, lessThan(2))
+ * + * @param the matcher type + * @param value the value which, when passed to the compareTo method of the examined object, should return less + * than zero + * @return the created matcher + */ + public static > Matcher lessThan(T value) { + return org.hamcrest.number.OrderingComparison.lessThan(value); + } + + /** + * Creates a matcher of {@link Comparable} object that matches when the examined object is + * less than or equal to the specified value, as reported by the compareTo method + * of the examined object. + * For example: + *
assertThat(1, lessThanOrEqualTo(1))
+ * + * @param the matcher type + * @param value the value which, when passed to the compareTo method of the examined object, should return less + * than or equal to zero + * @return the created matcher + */ + public static > Matcher lessThanOrEqualTo(T value) { + return org.hamcrest.number.OrderingComparison.lessThanOrEqualTo(value); + } + + /** + * Creates a matcher of {@link String} that matches when the examined string is equal to + * the specified expectedString, ignoring case. + * For example: + *
assertThat("Foo", equalToIgnoringCase("FOO"))
+ * + * @param expectedString + * the expected value of matched strings + * @return the created matcher + */ + public static Matcher equalToIgnoringCase(String expectedString) { + return org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase(expectedString); + } + + /** + * @param expectedString + * the expected value of matched strings + * @return the created matcher + * @deprecated {@link #equalToCompressingWhiteSpace(String)} + */ + public static Matcher equalToIgnoringWhiteSpace(String expectedString) { + return equalToCompressingWhiteSpace(expectedString); + } + + /** + * Creates a matcher of {@link String} that matches when the examined string is equal to + * the specified expectedString, when whitespace differences are (mostly) ignored. To be + * exact, the following whitespace rules are applied: + *
    + *
  • all leading and trailing whitespace of both the expectedString and the examined string are ignored
  • + *
  • any remaining whitespace, appearing within either string, is collapsed to a single space before comparison
  • + *
+ * For example: + *
assertThat("   my\tfoo  bar ", equalToIgnoringWhiteSpace(" my  foo bar"))
+ * + * @param expectedString + * the expected value of matched strings + * @return the created matcher + */ + public static Matcher equalToCompressingWhiteSpace(String expectedString) { + return IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace(expectedString); + } + + /** + * Creates a matcher of {@link String} that matches when the examined string is null, or + * has zero length. + * For example: + *
assertThat(((String)null), is(emptyOrNullString()))
+ * @return the created matcher + */ + public static Matcher emptyOrNullString() { + return org.hamcrest.text.IsEmptyString.emptyOrNullString(); + } + + /** + * Creates a matcher of {@link String} that matches when the examined string has zero length. + * For example: + *
assertThat("", is(emptyString()))
+ * @return the created matcher + */ + public static Matcher emptyString() { + return org.hamcrest.text.IsEmptyString.emptyString(); + } + + /** + * Creates a matcher of {@link String} that matches when the examined string is null, or + * has zero length. + * For example: + *
assertThat(((String)null), isEmptyOrNullString())
+ * + * @deprecated use is(emptyOrNullString()) instead + * @return the created matcher + */ + @SuppressWarnings("deprecation") + public static Matcher isEmptyOrNullString() { + return org.hamcrest.text.IsEmptyString.isEmptyOrNullString(); + } + + /** + * Creates a matcher of {@link String} that matches when the examined string has zero length. + * For example: + *
assertThat("", isEmptyString())
+ * + * @deprecated use is(emptyString()) instead + * @return the created matcher + */ + @SuppressWarnings("deprecation") + public static Matcher isEmptyString() { + return org.hamcrest.text.IsEmptyString.isEmptyString(); + } + + /** + * Creates a matcher of {@link String} that matches when the examined string is null, or + * contains zero or more whitespace characters and nothing else. + * For example: + *
assertThat(((String)null), is(blankOrNullString()))
+ * @return the created matcher + */ + public static Matcher blankOrNullString() { + return org.hamcrest.text.IsBlankString.blankOrNullString(); + } + + /** + * Creates a matcher of {@link String} that matches when the examined string contains + * zero or more whitespace characters and nothing else. + * For example: + *
assertThat("  ", is(blankString()))
+ * @return the created matcher + */ + public static Matcher blankString() { + return org.hamcrest.text.IsBlankString.blankString(); + } + + /** + * Creates a matcher of {@link java.lang.String} that matches when the examined string + * exactly matches the given {@link java.util.regex.Pattern}. + * @param pattern the pattern to match + * @return the created matcher + */ + public static Matcher matchesPattern(java.util.regex.Pattern pattern) { + return org.hamcrest.text.MatchesPattern.matchesPattern(pattern); + } + + /** + * Creates a matcher of {@link java.lang.String} that matches when the examined string + * exactly matches the given regular expression, treated as a {@link java.util.regex.Pattern}. + * @param regex the pattern to match + * @return the created matcher + */ + public static Matcher matchesPattern(String regex) { + return org.hamcrest.text.MatchesPattern.matchesPattern(regex); + } - /** - * Creates a matcher that matches if the examined object matches ALL of the specified matchers. - * For example: - *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
- */ - public static org.hamcrest.Matcher allOf(java.lang.Iterable> matchers) { - return org.hamcrest.core.AllOf.allOf(matchers); - } - - /** - * Creates a matcher that matches if the examined object matches ALL of the specified matchers. - * For example: - *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
- */ - @SafeVarargs - public static org.hamcrest.Matcher allOf(org.hamcrest.Matcher... matchers) { - return org.hamcrest.core.AllOf.allOf(matchers); - } - - /** - * Creates a matcher that matches if the examined object matches ALL of the specified matchers. - * For example: - *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
- */ - public static org.hamcrest.Matcher allOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second) { - return org.hamcrest.core.AllOf.allOf(first, second); - } - - /** - * Creates a matcher that matches if the examined object matches ALL of the specified matchers. - * For example: - *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
- */ - public static org.hamcrest.Matcher allOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third) { - return org.hamcrest.core.AllOf.allOf(first, second, third); - } - - /** - * Creates a matcher that matches if the examined object matches ALL of the specified matchers. - * For example: - *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
- */ - public static org.hamcrest.Matcher allOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third, org.hamcrest.Matcher fourth) { - return org.hamcrest.core.AllOf.allOf(first, second, third, fourth); - } - - /** - * Creates a matcher that matches if the examined object matches ALL of the specified matchers. - * For example: - *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
- */ - public static org.hamcrest.Matcher allOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third, org.hamcrest.Matcher fourth, org.hamcrest.Matcher fifth) { - return org.hamcrest.core.AllOf.allOf(first, second, third, fourth, fifth); - } - - /** - * Creates a matcher that matches if the examined object matches ALL of the specified matchers. - * For example: - *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
- */ - public static org.hamcrest.Matcher allOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third, org.hamcrest.Matcher fourth, org.hamcrest.Matcher fifth, org.hamcrest.Matcher sixth) { - return org.hamcrest.core.AllOf.allOf(first, second, third, fourth, fifth, sixth); - } - - /** - * Creates a matcher that matches if the examined object matches ANY of the specified matchers. - * For example: - *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
- */ - public static org.hamcrest.core.AnyOf anyOf(java.lang.Iterable> matchers) { - return org.hamcrest.core.AnyOf.anyOf(matchers); - } - - /** - * Creates a matcher that matches if the examined object matches ANY of the specified matchers. - * For example: - *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
- */ - @SafeVarargs - public static org.hamcrest.core.AnyOf anyOf(org.hamcrest.Matcher... matchers) { - return org.hamcrest.core.AnyOf.anyOf(matchers); - } - - /** - * Creates a matcher that matches if the examined object matches ANY of the specified matchers. - * For example: - *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
- */ - public static org.hamcrest.core.AnyOf anyOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second) { - return org.hamcrest.core.AnyOf.anyOf(first, second); - } - - /** - * Creates a matcher that matches if the examined object matches ANY of the specified matchers. - * For example: - *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
- */ - public static org.hamcrest.core.AnyOf anyOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third) { - return org.hamcrest.core.AnyOf.anyOf(first, second, third); - } - - /** - * Creates a matcher that matches if the examined object matches ANY of the specified matchers. - * For example: - *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
- */ - public static org.hamcrest.core.AnyOf anyOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third, org.hamcrest.Matcher fourth) { - return org.hamcrest.core.AnyOf.anyOf(first, second, third, fourth); - } - - /** - * Creates a matcher that matches if the examined object matches ANY of the specified matchers. - * For example: - *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
- */ - public static org.hamcrest.core.AnyOf anyOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third, org.hamcrest.Matcher fourth, org.hamcrest.Matcher fifth) { - return org.hamcrest.core.AnyOf.anyOf(first, second, third, fourth, fifth); - } - - /** - * Creates a matcher that matches if the examined object matches ANY of the specified matchers. - * For example: - *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
- */ - public static org.hamcrest.core.AnyOf anyOf(org.hamcrest.Matcher first, org.hamcrest.Matcher second, org.hamcrest.Matcher third, org.hamcrest.Matcher fourth, org.hamcrest.Matcher fifth, org.hamcrest.Matcher sixth) { - return org.hamcrest.core.AnyOf.anyOf(first, second, third, fourth, fifth, sixth); - } - - /** - * Creates a matcher that matches when both of the specified matchers match the examined object. - * For example: - *
assertThat("fab", both(containsString("a")).and(containsString("b")))
- */ - public static org.hamcrest.core.CombinableMatcher.CombinableBothMatcher both(org.hamcrest.Matcher matcher) { - return org.hamcrest.core.CombinableMatcher.both(matcher); - } - - /** - * Creates a matcher that matches when either of the specified matchers match the examined object. - * For example: - *
assertThat("fan", either(containsString("a")).or(containsString("b")))
- */ - public static org.hamcrest.core.CombinableMatcher.CombinableEitherMatcher either(org.hamcrest.Matcher matcher) { - return org.hamcrest.core.CombinableMatcher.either(matcher); - } - - /** - * Wraps an existing matcher, overriding its description with that specified. All other functions are - * delegated to the decorated matcher, including its mismatch description. - * For example: - *
describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())
- * - * @param description - * the new description for the wrapped matcher - * @param matcher - * the matcher to wrap - * @param values - * optional values to insert into the tokenized description - */ - public static org.hamcrest.Matcher describedAs(java.lang.String description, org.hamcrest.Matcher matcher, java.lang.Object... values) { - return org.hamcrest.core.DescribedAs.describedAs(description, matcher, values); - } - - /** - * Creates a matcher for {@link Iterable}s that only matches when a single pass over the - * examined {@link Iterable} yields items that are all matched by the specified - * itemMatcher. - * For example: - *
assertThat(Arrays.asList("bar", "baz"), everyItem(startsWith("ba")))
- * - * @param itemMatcher - * the matcher to apply to every item provided by the examined {@link Iterable} - */ - public static org.hamcrest.Matcher> everyItem(org.hamcrest.Matcher itemMatcher) { - return org.hamcrest.core.Every.everyItem(itemMatcher); - } - - /** - * Decorates another Matcher, retaining its behaviour, but allowing tests - * to be slightly more expressive. - * For example: - *
assertThat(cheese, is(equalTo(smelly)))
- * instead of: - *
assertThat(cheese, equalTo(smelly))
- */ - public static org.hamcrest.Matcher is(org.hamcrest.Matcher matcher) { - return org.hamcrest.core.Is.is(matcher); - } - - /** - * A shortcut to the frequently used is(equalTo(x)). - * For example: - *
assertThat(cheese, is(smelly))
- * instead of: - *
assertThat(cheese, is(equalTo(smelly)))
- */ - public static org.hamcrest.Matcher is(T value) { - return org.hamcrest.core.Is.is(value); - } - - /** - * A shortcut to the frequently used is(instanceOf(SomeClass.class)). - * For example: - *
assertThat(cheese, isA(Cheddar.class))
- * instead of: - *
assertThat(cheese, is(instanceOf(Cheddar.class)))
- */ - public static org.hamcrest.Matcher isA(java.lang.Class type) { - return org.hamcrest.core.Is.isA(type); - } - - /** - * Creates a matcher that always matches, regardless of the examined object. - */ - public static org.hamcrest.Matcher anything() { - return org.hamcrest.core.IsAnything.anything(); - } - - /** - * Creates a matcher that always matches, regardless of the examined object, but describes - * itself with the specified {@link String}. - * - * @param description - * a meaningful {@link String} used when describing itself - */ - public static org.hamcrest.Matcher anything(java.lang.String description) { - return org.hamcrest.core.IsAnything.anything(description); - } - - /** - * Creates a matcher for {@link Iterable}s that only matches when a single pass over the - * examined {@link Iterable} yields at least one item that is matched by the specified - * itemMatcher. Whilst matching, the traversal of the examined {@link Iterable} - * will stop as soon as a matching item is found. - * For example: - *
assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))
- * - * @param itemMatcher - * the matcher to apply to items provided by the examined {@link Iterable} - */ - public static org.hamcrest.Matcher> hasItem(org.hamcrest.Matcher itemMatcher) { - return IsIterableContaining.hasItem(itemMatcher); - } - - /** - * Creates a matcher for {@link Iterable}s that only matches when a single pass over the - * examined {@link Iterable} yields at least one item that is equal to the specified - * item. Whilst matching, the traversal of the examined {@link Iterable} - * will stop as soon as a matching item is found. - * For example: - *
assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))
- * - * @param item - * the item to compare against the items provided by the examined {@link Iterable} - */ - public static org.hamcrest.Matcher> hasItem(T item) { - return IsIterableContaining.hasItem(item); - } - - /** - * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the - * examined {@link Iterable} yield at least one item that is matched by the corresponding - * matcher from the specified itemMatchers. Whilst matching, each traversal of - * the examined {@link Iterable} will stop as soon as a matching item is found. - * For example: - *
assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))
- * - * @param itemMatchers - * the matchers to apply to items provided by the examined {@link Iterable} - */ - @SafeVarargs - public static org.hamcrest.Matcher> hasItems(org.hamcrest.Matcher... itemMatchers) { - return IsIterableContaining.hasItems(itemMatchers); - } - - /** - * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the - * examined {@link Iterable} yield at least one item that is equal to the corresponding - * item from the specified items. Whilst matching, each traversal of the - * examined {@link Iterable} will stop as soon as a matching item is found. - * For example: - *
assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))
- * - * @param items - * the items to compare against the items provided by the examined {@link Iterable} - */ - @SafeVarargs - public static org.hamcrest.Matcher> hasItems(T... items) { - return IsIterableContaining.hasItems(items); - } - - /** - * Creates a matcher that matches when the examined object is logically equal to the specified - * operand, as determined by calling the {@link java.lang.Object#equals} method on - * the examined object. - * - *

If the specified operand is null then the created matcher will only match if - * the examined object's equals method returns true when passed a - * null (which would be a violation of the equals contract), unless the - * examined object itself is null, in which case the matcher will return a positive - * match.

- * - *

The created matcher provides a special behaviour when examining Arrays, whereby - * it will match if both the operand and the examined object are arrays of the same length and - * contain items that are equal to each other (according to the above rules) in the same - * indexes.

- * For example: - *
-   * assertThat("foo", equalTo("foo"));
-   * assertThat(new String[] {"foo", "bar"}, equalTo(new String[] {"foo", "bar"}));
-   * 
- */ - public static org.hamcrest.Matcher equalTo(T operand) { - return org.hamcrest.core.IsEqual.equalTo(operand); - } - - /** - * Creates an {@link org.hamcrest.core.IsEqual} matcher that does not enforce the values being - * compared to be of the same static type. - */ - public static org.hamcrest.Matcher equalToObject(java.lang.Object operand) { - return org.hamcrest.core.IsEqual.equalToObject(operand); - } - - /** - * Creates a matcher that matches when the examined object is an instance of the specified type, - * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the - * the examined object. - * - *

The created matcher forces a relationship between specified type and the examined object, and should be - * used when it is necessary to make generics conform, for example in the JMock clause - * with(any(Thing.class))

- * For example: - *
assertThat(new Canoe(), instanceOf(Canoe.class));
- */ - public static org.hamcrest.Matcher any(java.lang.Class type) { - return org.hamcrest.core.IsInstanceOf.any(type); - } - - /** - * Creates a matcher that matches when the examined object is an instance of the specified type, - * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the - * the examined object. - * - *

The created matcher assumes no relationship between specified type and the examined object.

- * For example: - *
assertThat(new Canoe(), instanceOf(Paddlable.class));
- */ - public static org.hamcrest.Matcher instanceOf(java.lang.Class type) { - return org.hamcrest.core.IsInstanceOf.instanceOf(type); - } - - /** - * Creates a matcher that wraps an existing matcher, but inverts the logic by which - * it will match. - * For example: - *
assertThat(cheese, is(not(equalTo(smelly))))
- * - * @param matcher - * the matcher whose sense should be inverted - */ - public static org.hamcrest.Matcher not(org.hamcrest.Matcher matcher) { - return org.hamcrest.core.IsNot.not(matcher); - } - - /** - * A shortcut to the frequently used not(equalTo(x)). - * For example: - *
assertThat(cheese, is(not(smelly)))
- * instead of: - *
assertThat(cheese, is(not(equalTo(smelly))))
- * - * @param value - * the value that any examined object should not equal - */ - public static org.hamcrest.Matcher not(T value) { - return org.hamcrest.core.IsNot.not(value); - } - - /** - * A shortcut to the frequently used not(nullValue()). - * For example: - *
assertThat(cheese, is(notNullValue()))
- * instead of: - *
assertThat(cheese, is(not(nullValue())))
- */ - public static org.hamcrest.Matcher notNullValue() { - return org.hamcrest.core.IsNull.notNullValue(); - } - - /** - * A shortcut to the frequently used not(nullValue(X.class)). Accepts a - * single dummy argument to facilitate type inference.. - * For example: - *
assertThat(cheese, is(notNullValue(X.class)))
- * instead of: - *
assertThat(cheese, is(not(nullValue(X.class))))
- * - * @param type - * dummy parameter used to infer the generic type of the returned matcher - */ - public static org.hamcrest.Matcher notNullValue(java.lang.Class type) { - return org.hamcrest.core.IsNull.notNullValue(type); - } - - /** - * Creates a matcher that matches if examined object is null. - * For example: - *
assertThat(cheese, is(nullValue())
- */ - public static org.hamcrest.Matcher nullValue() { - return org.hamcrest.core.IsNull.nullValue(); - } - - /** - * Creates a matcher that matches if examined object is null. Accepts a - * single dummy argument to facilitate type inference. - * For example: - *
assertThat(cheese, is(nullValue(Cheese.class))
- * - * @param type - * dummy parameter used to infer the generic type of the returned matcher - */ - public static org.hamcrest.Matcher nullValue(java.lang.Class type) { - return org.hamcrest.core.IsNull.nullValue(type); - } - - /** - * Creates a matcher that matches only when the examined object is the same instance as - * the specified target object. - * - * @param target - * the target instance against which others should be assessed - */ - public static org.hamcrest.Matcher sameInstance(T target) { - return org.hamcrest.core.IsSame.sameInstance(target); - } - - /** - * Creates a matcher that matches only when the examined object is the same instance as - * the specified target object. - * - * @param target - * the target instance against which others should be assessed - */ - public static org.hamcrest.Matcher theInstance(T target) { - return org.hamcrest.core.IsSame.theInstance(target); - } - - /** - * Creates a matcher that matches if the examined {@link String} contains the specified - * {@link String} anywhere. - * For example: - *
assertThat("myStringOfNote", containsString("ring"))
- * - * @param substring - * the substring that the returned matcher will expect to find within any examined string - */ - public static Matcher containsString(java.lang.String substring) { - return org.hamcrest.core.StringContains.containsString(substring); - } - - /** - * Creates a matcher that matches if the examined {@link String} contains the specified - * {@link String} anywhere, ignoring case. - * For example: - *
assertThat("myStringOfNote", containsStringIgnoringCase("Ring"))
- * - * @param substring - * the substring that the returned matcher will expect to find within any examined string - */ - public static Matcher containsStringIgnoringCase(java.lang.String substring) { - return org.hamcrest.core.StringContains.containsStringIgnoringCase(substring); - } - - /** - *

- * Creates a matcher that matches if the examined {@link String} starts with the specified - * {@link String}. - *

- * For example: - *
assertThat("myStringOfNote", startsWith("my"))
- * - * @param prefix - * the substring that the returned matcher will expect at the start of any examined string - */ - public static Matcher startsWith(java.lang.String prefix) { - return org.hamcrest.core.StringStartsWith.startsWith(prefix); - } - - /** - *

- * Creates a matcher that matches if the examined {@link String} starts with the specified - * {@link String}, ignoring case - *

- * For example: - *
assertThat("myStringOfNote", startsWithIgnoringCase("My"))
- * - * @param prefix - * the substring that the returned matcher will expect at the start of any examined string - */ - public static Matcher startsWithIgnoringCase(java.lang.String prefix) { - return org.hamcrest.core.StringStartsWith.startsWithIgnoringCase(prefix); - } - - /** - * Creates a matcher that matches if the examined {@link String} ends with the specified - * {@link String}. - * For example: - *
assertThat("myStringOfNote", endsWith("Note"))
- * - * @param suffix - * the substring that the returned matcher will expect at the end of any examined string - */ - public static Matcher endsWith(java.lang.String suffix) { - return org.hamcrest.core.StringEndsWith.endsWith(suffix); - } - - /** - * Creates a matcher that matches if the examined {@link String} ends with the specified - * {@link String}, ignoring case. - * For example: - *
assertThat("myStringOfNote", endsWithIgnoringCase("note"))
- * - * @param suffix - * the substring that the returned matcher will expect at the end of any examined string - */ - public static Matcher endsWithIgnoringCase(java.lang.String suffix) { - return org.hamcrest.core.StringEndsWith.endsWithIgnoringCase(suffix); - } - - /** - * Validate a string with a {@link java.util.regex.Pattern}. - * - *
-   * assertThat("abc", matchesRegex(Pattern.compile("ˆ[a-z]$"));
-   * 
- * - * @param pattern - * the pattern to be used. - * @return The matcher. - */ - public static Matcher matchesRegex(Pattern pattern) { - return StringRegularExpression.matchesRegex(pattern); - } - - /** - * Validate a string with a regex. - * - *
-   * assertThat("abc", matchesRegex("ˆ[a-z]+$"));
-   * 
- * - * @param regex - * The regex to be used for the validation. - * @return The matcher. - */ - public static Matcher matchesRegex(String regex) { - return StringRegularExpression.matchesRegex(Pattern.compile(regex)); - } - - /** - * Creates a matcher that matches arrays whose elements are satisfied by the specified matchers. Matches - * positively only if the number of matchers specified is equal to the length of the examined array and - * each matcher[i] is satisfied by array[i]. - * For example: - *
assertThat(new Integer[]{1,2,3}, is(array(equalTo(1), equalTo(2), equalTo(3))))
- * - * @param elementMatchers - * the matchers that the elements of examined arrays should satisfy - */ - @SafeVarargs - public static org.hamcrest.collection.IsArray array(org.hamcrest.Matcher... elementMatchers) { - return org.hamcrest.collection.IsArray.array(elementMatchers); - } - - /** - * Creates a matcher for arrays that matches when the examined array contains at least one item - * that is matched by the specified elementMatcher. Whilst matching, the traversal - * of the examined array will stop as soon as a matching element is found. - * For example: - *
assertThat(new String[] {"foo", "bar"}, hasItemInArray(startsWith("ba")))
- * - * @param elementMatcher - * the matcher to apply to elements in examined arrays - */ - public static org.hamcrest.Matcher hasItemInArray(org.hamcrest.Matcher elementMatcher) { - return ArrayMatching.hasItemInArray(elementMatcher); - } - - /** - * A shortcut to the frequently used hasItemInArray(equalTo(x)). - * For example: - *
assertThat(hasItemInArray(x))
- * instead of: - *
assertThat(hasItemInArray(equalTo(x)))
- * - * @param element - * the element that should be present in examined arrays - */ - public static org.hamcrest.Matcher hasItemInArray(T element) { - return ArrayMatching.hasItemInArray(element); - } - - /** - * Creates a matcher for arrays that matches when each item in the examined array is - * logically equal to the corresponding item in the specified items. For a positive match, - * the examined array must be of the same length as the number of specified items. - * For example: - *
assertThat(new String[]{"foo", "bar"}, arrayContaining("foo", "bar"))
- * - * @param items - * the items that must equal the items within an examined array - */ - @SafeVarargs - public static org.hamcrest.Matcher arrayContaining(E... items) { - return ArrayMatching.arrayContaining(items); - } - - /** - * Creates a matcher for arrays that matches when each item in the examined array satisfies the - * corresponding matcher in the specified matchers. For a positive match, the examined array - * must be of the same length as the number of specified matchers. - * For example: - *
assertThat(new String[]{"foo", "bar"}, arrayContaining(equalTo("foo"), equalTo("bar")))
- * - * @param itemMatchers - * the matchers that must be satisfied by the items in the examined array - */ - @SafeVarargs - public static org.hamcrest.Matcher arrayContaining(org.hamcrest.Matcher... itemMatchers) { - return ArrayMatching.arrayContaining(itemMatchers); - } - - /** - * Creates a matcher for arrays that matches when each item in the examined array satisfies the - * corresponding matcher in the specified list of matchers. For a positive match, the examined array - * must be of the same length as the specified list of matchers. - * For example: - *
assertThat(new String[]{"foo", "bar"}, arrayContaining(Arrays.asList(equalTo("foo"), equalTo("bar"))))
- * - * @param itemMatchers - * a list of matchers, each of which must be satisfied by the corresponding item in an examined array - */ - public static org.hamcrest.Matcher arrayContaining(java.util.List> itemMatchers) { - return ArrayMatching.arrayContaining(itemMatchers); - } - - /** - *

- * Creates an order agnostic matcher for arrays that matches when each item in the - * examined array satisfies one matcher anywhere in the specified matchers. - * For a positive match, the examined array must be of the same length as the number of - * specified matchers. - *

- *

- * N.B. each of the specified matchers will only be used once during a given examination, so be - * careful when specifying matchers that may be satisfied by more than one entry in an examined - * array. - *

- *

- * For example: - *

- *
assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(equalTo("bar"), equalTo("foo")))
- * - * @param itemMatchers - * a list of matchers, each of which must be satisfied by an entry in an examined array - */ - @SafeVarargs - public static org.hamcrest.Matcher arrayContainingInAnyOrder(org.hamcrest.Matcher... itemMatchers) { - return ArrayMatching.arrayContainingInAnyOrder(itemMatchers); - } - - /** - *

- * Creates an order agnostic matcher for arrays that matches when each item in the - * examined array satisfies one matcher anywhere in the specified collection of matchers. - * For a positive match, the examined array must be of the same length as the specified collection - * of matchers. - *

- *

- * N.B. each matcher in the specified collection will only be used once during a given - * examination, so be careful when specifying matchers that may be satisfied by more than - * one entry in an examined array. - *

- *

- * For example: - *

- *
assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(Arrays.asList(equalTo("bar"), equalTo("foo"))))
- * - * @param itemMatchers - * a list of matchers, each of which must be satisfied by an item provided by an examined array - */ - public static org.hamcrest.Matcher arrayContainingInAnyOrder(java.util.Collection> itemMatchers) { - return ArrayMatching.arrayContainingInAnyOrder(itemMatchers); - } - - /** - *

Creates an order agnostic matcher for arrays that matches when each item in the - * examined array is logically equal to one item anywhere in the specified items. - * For a positive match, the examined array must be of the same length as the number of - * specified items. - *

- *

N.B. each of the specified items will only be used once during a given examination, so be - * careful when specifying items that may be equal to more than one entry in an examined - * array. - *

- *

- * For example: - *

- *
assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder("bar", "foo"))
- * - * @param items - * the items that must equal the entries of an examined array, in any order - */ - @SafeVarargs - public static org.hamcrest.Matcher arrayContainingInAnyOrder(E... items) { - return ArrayMatching.arrayContainingInAnyOrder(items); - } - - /** - * Creates a matcher for arrays that matches when the length of the array - * satisfies the specified matcher. - * For example: - *
assertThat(new String[]{"foo", "bar"}, arrayWithSize(equalTo(2)))
- * - * @param sizeMatcher - * a matcher for the length of an examined array - */ - public static org.hamcrest.Matcher arrayWithSize(org.hamcrest.Matcher sizeMatcher) { - return org.hamcrest.collection.IsArrayWithSize.arrayWithSize(sizeMatcher); - } - - /** - * Creates a matcher for arrays that matches when the length of the array - * equals the specified size. - * For example: - *
assertThat(new String[]{"foo", "bar"}, arrayWithSize(2))
- * - * @param size - * the length that an examined array must have for a positive match - */ - public static org.hamcrest.Matcher arrayWithSize(int size) { - return org.hamcrest.collection.IsArrayWithSize.arrayWithSize(size); - } - - /** - * Creates a matcher for arrays that matches when the length of the array - * is zero. - * For example: - *
assertThat(new String[0], emptyArray())
- */ - public static org.hamcrest.Matcher emptyArray() { - return org.hamcrest.collection.IsArrayWithSize.emptyArray(); - } - - /** - * Creates a matcher for {@link java.util.Map}s that matches when the size() method returns - * a value that satisfies the specified matcher. - * For example: - *
assertThat(myMap, is(aMapWithSize(equalTo(2))))
- * - * @param sizeMatcher - * a matcher for the size of an examined {@link java.util.Map} - */ - public static org.hamcrest.Matcher> aMapWithSize(org.hamcrest.Matcher sizeMatcher) { - return org.hamcrest.collection.IsMapWithSize.aMapWithSize(sizeMatcher); - } - - /** - * Creates a matcher for {@link java.util.Map}s that matches when the size() method returns - * a value equal to the specified size. - * For example: - *
assertThat(myMap, is(aMapWithSize(2)))
- * - * @param size - * the expected size of an examined {@link java.util.Map} - */ - public static org.hamcrest.Matcher> aMapWithSize(int size) { - return org.hamcrest.collection.IsMapWithSize.aMapWithSize(size); - } - - /** - * Creates a matcher for {@link java.util.Map}s that matches when the size() method returns - * zero. - * For example: - *
assertThat(myMap, is(anEmptyMap()))
- */ - public static org.hamcrest.Matcher> anEmptyMap() { - return org.hamcrest.collection.IsMapWithSize.anEmptyMap(); - } - - /** - * Creates a matcher for {@link java.util.Collection}s that matches when the size() method returns - * a value that satisfies the specified matcher. - * For example: - *
assertThat(Arrays.asList("foo", "bar"), hasSize(equalTo(2)))
- * - * @param sizeMatcher - * a matcher for the size of an examined {@link java.util.Collection} - */ - public static org.hamcrest.Matcher> hasSize(org.hamcrest.Matcher sizeMatcher) { - return org.hamcrest.collection.IsCollectionWithSize.hasSize(sizeMatcher); - } - - /** - * Creates a matcher for {@link java.util.Collection}s that matches when the size() method returns - * a value equal to the specified size. - * For example: - *
assertThat(Arrays.asList("foo", "bar"), hasSize(2))
- * - * @param size - * the expected size of an examined {@link java.util.Collection} - */ - public static org.hamcrest.Matcher> hasSize(int size) { - return org.hamcrest.collection.IsCollectionWithSize.hasSize(size); - } - - /** - * Creates a matcher for {@link java.util.Collection}s matching examined collections whose isEmpty - * method returns true. - * For example: - *
assertThat(new ArrayList<String>(), is(empty()))
- */ - public static org.hamcrest.Matcher> empty() { - return org.hamcrest.collection.IsEmptyCollection.empty(); - } - - /** - * Creates a matcher for {@link java.util.Collection}s matching examined collections whose isEmpty - * method returns true. - * For example: - *
assertThat(new ArrayList<String>(), is(emptyCollectionOf(String.class)))
- * - * @param unusedToForceReturnType - * the type of the collection's content - */ - public static org.hamcrest.Matcher> emptyCollectionOf(java.lang.Class unusedToForceReturnType) { - return org.hamcrest.collection.IsEmptyCollection.emptyCollectionOf(unusedToForceReturnType); - } - - /** - * Creates a matcher for {@link Iterable}s matching examined iterables that yield no items. - * For example: - *
assertThat(new ArrayList<String>(), is(emptyIterable()))
- */ - public static org.hamcrest.Matcher> emptyIterable() { - return org.hamcrest.collection.IsEmptyIterable.emptyIterable(); - } - - /** - * Creates a matcher for {@link Iterable}s matching examined iterables that yield no items. - * For example: - *
assertThat(new ArrayList<String>(), is(emptyIterableOf(String.class)))
- * - * @param unusedToForceReturnType - * the type of the iterable's content - */ - public static org.hamcrest.Matcher> emptyIterableOf(java.lang.Class unusedToForceReturnType) { - return org.hamcrest.collection.IsEmptyIterable.emptyIterableOf(unusedToForceReturnType); - } - - /** - * Creates a matcher for {@link Iterable}s that matches when a single pass over the - * examined {@link Iterable} yields a series of items, each logically equal to the - * corresponding item in the specified items. For a positive match, the examined iterable - * must be of the same length as the number of specified items. - * For example: - *
assertThat(Arrays.asList("foo", "bar"), contains("foo", "bar"))
- * - * @param items - * the items that must equal the items provided by an examined {@link Iterable} - */ - @SafeVarargs - public static org.hamcrest.Matcher> contains(E... items) { - return org.hamcrest.collection.IsIterableContainingInOrder.contains(items); - } - - /** - * Creates a matcher for {@link Iterable}s that matches when a single pass over the - * examined {@link Iterable} yields a single item that satisfies the specified matcher. - * For a positive match, the examined iterable must only yield one item. - * For example: - *
assertThat(Arrays.asList("foo"), contains(equalTo("foo")))
- * - * @param itemMatcher - * the matcher that must be satisfied by the single item provided by an - * examined {@link Iterable} - */ - public static org.hamcrest.Matcher> contains(org.hamcrest.Matcher itemMatcher) { - return org.hamcrest.collection.IsIterableContainingInOrder.contains(itemMatcher); - } - - /** - * Creates a matcher for {@link Iterable}s that matches when a single pass over the - * examined {@link Iterable} yields a series of items, each satisfying the corresponding - * matcher in the specified matchers. For a positive match, the examined iterable - * must be of the same length as the number of specified matchers. - * For example: - *
assertThat(Arrays.asList("foo", "bar"), contains(equalTo("foo"), equalTo("bar")))
- * - * @param itemMatchers - * the matchers that must be satisfied by the items provided by an examined {@link Iterable} - */ - @SafeVarargs - public static org.hamcrest.Matcher> contains(org.hamcrest.Matcher... itemMatchers) { - return org.hamcrest.collection.IsIterableContainingInOrder.contains(itemMatchers); - } - - /** - * Creates a matcher for {@link Iterable}s that matches when a single pass over the - * examined {@link Iterable} yields a series of items, each satisfying the corresponding - * matcher in the specified list of matchers. For a positive match, the examined iterable - * must be of the same length as the specified list of matchers. - * For example: - *
assertThat(Arrays.asList("foo", "bar"), contains(Arrays.asList(equalTo("foo"), equalTo("bar"))))
- * - * @param itemMatchers - * a list of matchers, each of which must be satisfied by the corresponding item provided by - * an examined {@link Iterable} - */ - public static org.hamcrest.Matcher> contains(java.util.List> itemMatchers) { - return org.hamcrest.collection.IsIterableContainingInOrder.contains(itemMatchers); - } - - /** - *

- * Creates an order agnostic matcher for {@link Iterable}s that matches when a single pass over - * the examined {@link Iterable} yields a series of items, each satisfying one matcher anywhere - * in the specified matchers. For a positive match, the examined iterable must be of the same - * length as the number of specified matchers. - *

- *

- * N.B. each of the specified matchers will only be used once during a given examination, so be - * careful when specifying matchers that may be satisfied by more than one entry in an examined - * iterable. - *

- *

- * For example: - *

- *
assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder(equalTo("bar"), equalTo("foo")))
- * - * @param itemMatchers - * a list of matchers, each of which must be satisfied by an item provided by an examined {@link Iterable} - */ - @SafeVarargs - public static org.hamcrest.Matcher> containsInAnyOrder(org.hamcrest.Matcher... itemMatchers) { - return org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder(itemMatchers); - } - - /** - *

- * Creates an order agnostic matcher for {@link Iterable}s that matches when a single pass over - * the examined {@link Iterable} yields a series of items, each logically equal to one item - * anywhere in the specified items. For a positive match, the examined iterable - * must be of the same length as the number of specified items. - *

- *

- * N.B. each of the specified items will only be used once during a given examination, so be - * careful when specifying items that may be equal to more than one entry in an examined - * iterable. - *

- *

- * For example: - *

- *
assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder("bar", "foo"))
- * - * @param items - * the items that must equal the items provided by an examined {@link Iterable} in any order - */ - @SafeVarargs - public static org.hamcrest.Matcher> containsInAnyOrder(T... items) { - return org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder(items); - } - - /** - *

- * Creates an order agnostic matcher for {@link Iterable}s that matches when a single pass over - * the examined {@link Iterable} yields a series of items, each satisfying one matcher anywhere - * in the specified collection of matchers. For a positive match, the examined iterable - * must be of the same length as the specified collection of matchers. - *

- *

- * N.B. each matcher in the specified collection will only be used once during a given - * examination, so be careful when specifying matchers that may be satisfied by more than - * one entry in an examined iterable. - *

- *

For example:

- *
assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder(Arrays.asList(equalTo("bar"), equalTo("foo"))))
- * - * @param itemMatchers - * a list of matchers, each of which must be satisfied by an item provided by an examined {@link Iterable} - */ - public static org.hamcrest.Matcher> containsInAnyOrder(java.util.Collection> itemMatchers) { - return org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder(itemMatchers); - } - - /** - * Creates a matcher for {@link Iterable}s that matches when a single pass over the - * examined {@link Iterable} yields a series of items, that contains items logically equal to the - * corresponding item in the specified items, in the same relative order - * For example: - *
assertThat(Arrays.asList("a", "b", "c", "d", "e"), containsInRelativeOrder("b", "d"))
- * - * @param items - * the items that must be contained within items provided by an examined {@link Iterable} in the same relative order - */ - @SafeVarargs - public static org.hamcrest.Matcher> containsInRelativeOrder(E... items) { - return org.hamcrest.collection.IsIterableContainingInRelativeOrder.containsInRelativeOrder(items); - } - - /** - * Creates a matcher for {@link Iterable}s that matches when a single pass over the - * examined {@link Iterable} yields a series of items, that each satisfying the corresponding - * matcher in the specified matchers, in the same relative order. - * For example: - *
assertThat(Arrays.asList("a", "b", "c", "d", "e"), containsInRelativeOrder(equalTo("b"), equalTo("d")))
- * - * @param itemMatchers - * the matchers that must be satisfied by the items provided by an examined {@link Iterable} in the same relative order - */ - @SafeVarargs - public static org.hamcrest.Matcher> containsInRelativeOrder(org.hamcrest.Matcher... itemMatchers) { - return org.hamcrest.collection.IsIterableContainingInRelativeOrder.containsInRelativeOrder(itemMatchers); - } - - /** - * Creates a matcher for {@link Iterable}s that matches when a single pass over the - * examined {@link Iterable} yields a series of items, that contains items satisfying the corresponding - * matcher in the specified list of matchers, in the same relative order. - * For example: - *
assertThat(Arrays.asList("a", "b", "c", "d", "e"), contains(Arrays.asList(equalTo("b"), equalTo("d"))))
- * - * @param itemMatchers - * a list of matchers, each of which must be satisfied by the items provided by - * an examined {@link Iterable} in the same relative order - */ - public static org.hamcrest.Matcher> containsInRelativeOrder(java.util.List> itemMatchers) { - return org.hamcrest.collection.IsIterableContainingInRelativeOrder.containsInRelativeOrder(itemMatchers); - } - - /** - * Creates a matcher for {@link Iterable}s that matches when a single pass over the - * examined {@link Iterable} yields an item count that satisfies the specified - * matcher. - * For example: - *
assertThat(Arrays.asList("foo", "bar"), iterableWithSize(equalTo(2)))
- * - * @param sizeMatcher - * a matcher for the number of items that should be yielded by an examined {@link Iterable} - */ - public static org.hamcrest.Matcher> iterableWithSize(org.hamcrest.Matcher sizeMatcher) { - return org.hamcrest.collection.IsIterableWithSize.iterableWithSize(sizeMatcher); - } - - /** - * Creates a matcher for {@link Iterable}s that matches when a single pass over the - * examined {@link Iterable} yields an item count that is equal to the specified - * size argument. - * For example: - *
assertThat(Arrays.asList("foo", "bar"), iterableWithSize(2))
- * - * @param size - * the number of items that should be yielded by an examined {@link Iterable} - */ - public static org.hamcrest.Matcher> iterableWithSize(int size) { - return org.hamcrest.collection.IsIterableWithSize.iterableWithSize(size); - } - - /** - * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains - * at least one entry whose key satisfies the specified keyMatcher and whose - * value satisfies the specified valueMatcher. - * For example: - *
assertThat(myMap, hasEntry(equalTo("bar"), equalTo("foo")))
- * - * @param keyMatcher - * the key matcher that, in combination with the valueMatcher, must be satisfied by at least one entry - * @param valueMatcher - * the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entry - */ - public static org.hamcrest.Matcher> hasEntry(org.hamcrest.Matcher keyMatcher, org.hamcrest.Matcher valueMatcher) { - return org.hamcrest.collection.IsMapContaining.hasEntry(keyMatcher, valueMatcher); - } - - /** - * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains - * at least one entry whose key equals the specified key and whose value equals the - * specified value. - * For example: - *
assertThat(myMap, hasEntry("bar", "foo"))
- * - * @param key - * the key that, in combination with the value, must be describe at least one entry - * @param value - * the value that, in combination with the key, must be describe at least one entry - */ - public static org.hamcrest.Matcher> hasEntry(K key, V value) { - return org.hamcrest.collection.IsMapContaining.hasEntry(key, value); - } - - /** - * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains - * at least one key that satisfies the specified matcher. - * For example: - *
assertThat(myMap, hasKey(equalTo("bar")))
- * - * @param keyMatcher - * the matcher that must be satisfied by at least one key - */ - public static org.hamcrest.Matcher> hasKey(org.hamcrest.Matcher keyMatcher) { - return org.hamcrest.collection.IsMapContaining.hasKey(keyMatcher); - } - - /** - * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains - * at least one key that is equal to the specified key. - * For example: - *
assertThat(myMap, hasKey("bar"))
- * - * @param key - * the key that satisfying maps must contain - */ - public static org.hamcrest.Matcher> hasKey(K key) { - return org.hamcrest.collection.IsMapContaining.hasKey(key); - } - - /** - * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains - * at least one value that satisfies the specified valueMatcher. - * For example: - *
assertThat(myMap, hasValue(equalTo("foo")))
- * - * @param valueMatcher - * the matcher that must be satisfied by at least one value - */ - public static org.hamcrest.Matcher> hasValue(org.hamcrest.Matcher valueMatcher) { - return org.hamcrest.collection.IsMapContaining.hasValue(valueMatcher); - } - - /** - * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains - * at least one value that is equal to the specified value. - * For example: - *
assertThat(myMap, hasValue("foo"))
- * - * @param value - * the value that satisfying maps must contain - */ - public static org.hamcrest.Matcher> hasValue(V value) { - return org.hamcrest.collection.IsMapContaining.hasValue(value); - } - - /** - * Creates a matcher that matches when the examined object is found within the - * specified collection. - * For example: - *
assertThat("foo", is(in(Arrays.asList("bar", "foo"))))
- * - * @param collection - * the collection in which matching items must be found - */ - public static org.hamcrest.Matcher in(java.util.Collection collection) { - return org.hamcrest.collection.IsIn.in(collection); - } - - /** - * Creates a matcher that matches when the examined object is found within the - * specified array. - * For example: - *
assertThat("foo", is(in(new String[]{"bar", "foo"})))
- * - * @param elements - * the array in which matching items must be found - */ - public static org.hamcrest.Matcher in(T[] elements) { - return org.hamcrest.collection.IsIn.in(elements); - } - - /** - * Creates a matcher that matches when the examined object is found within the - * specified collection. - * For example: - *
assertThat("foo", isIn(Arrays.asList("bar", "foo")))
- * - * @deprecated use is(in(...)) instead - * @param collection - * the collection in which matching items must be found - */ - @SuppressWarnings("deprecation") - public static org.hamcrest.Matcher isIn(java.util.Collection collection) { - return org.hamcrest.collection.IsIn.isIn(collection); - } - - /** - * Creates a matcher that matches when the examined object is found within the - * specified array. - * For example: - *
assertThat("foo", isIn(new String[]{"bar", "foo"}))
- * - * @deprecated use is(in(...)) instead - * @param elements - * the array in which matching items must be found - */ - @SuppressWarnings("deprecation") - public static org.hamcrest.Matcher isIn(T[] elements) { - return org.hamcrest.collection.IsIn.isIn(elements); - } - - /** - * Creates a matcher that matches when the examined object is equal to one of the - * specified elements. - * For example: - *
assertThat("foo", isOneOf("bar", "foo"))
- * - * @deprecated use is(oneOf(...)) instead - * @param elements - * the elements amongst which matching items will be found - */ - @SuppressWarnings("deprecation") - @SafeVarargs - public static org.hamcrest.Matcher isOneOf(T... elements) { - return org.hamcrest.collection.IsIn.isOneOf(elements); - } - - /** - * Creates a matcher that matches when the examined object is equal to one of the - * specified elements. - * For example: - *
assertThat("foo", is(oneOf("bar", "foo")))
- * - * @param elements - * the elements amongst which matching items will be found - */ - @SafeVarargs - public static org.hamcrest.Matcher oneOf(T... elements) { - return org.hamcrest.collection.IsIn.oneOf(elements); - } - - /** - * Creates a matcher of {@link Double}s that matches when an examined double is equal - * to the specified operand, within a range of +/- error. - * For example: - *
assertThat(1.03, is(closeTo(1.0, 0.03)))
- * - * @param operand - * the expected value of matching doubles - * @param error - * the delta (+/-) within which matches will be allowed - */ - public static org.hamcrest.Matcher closeTo(double operand, double error) { - return org.hamcrest.number.IsCloseTo.closeTo(operand, error); - } - - /** - * Creates a matcher of {@link Double}s that matches when an examined double is not a number. - * For example: - *
assertThat(Double.NaN, is(notANumber()))
- */ - public static org.hamcrest.Matcher notANumber() { - return org.hamcrest.number.IsNaN.notANumber(); - } - - /** - * Creates a matcher of {@link java.math.BigDecimal}s that matches when an examined BigDecimal is equal - * to the specified operand, within a range of +/- error. The comparison for equality - * is done by BigDecimals {@link java.math.BigDecimal#compareTo(java.math.BigDecimal)} method. - * For example: - *
assertThat(new BigDecimal("1.03"), is(closeTo(new BigDecimal("1.0"), new BigDecimal("0.03"))))
- * - * @param operand - * the expected value of matching BigDecimals - * @param error - * the delta (+/-) within which matches will be allowed - */ - public static org.hamcrest.Matcher closeTo(java.math.BigDecimal operand, java.math.BigDecimal error) { - return org.hamcrest.number.BigDecimalCloseTo.closeTo(operand, error); - } - - /** - * Creates a matcher of {@link Comparable} object that matches when the examined object is - * equal to the specified value, as reported by the compareTo method of the - * examined object. - * For example: - *
assertThat(1, comparesEqualTo(1))
- * - * @param value the value which, when passed to the compareTo method of the examined object, should return zero - */ - public static > org.hamcrest.Matcher comparesEqualTo(T value) { - return org.hamcrest.number.OrderingComparison.comparesEqualTo(value); - } - - /** - * Creates a matcher of {@link Comparable} object that matches when the examined object is - * greater than the specified value, as reported by the compareTo method of the - * examined object. - * For example: - *
assertThat(2, greaterThan(1))
- * - * @param value the value which, when passed to the compareTo method of the examined object, should return greater - * than zero - */ - public static > org.hamcrest.Matcher greaterThan(T value) { - return org.hamcrest.number.OrderingComparison.greaterThan(value); - } - - /** - * Creates a matcher of {@link Comparable} object that matches when the examined object is - * greater than or equal to the specified value, as reported by the compareTo method - * of the examined object. - * For example: - *
assertThat(1, greaterThanOrEqualTo(1))
- * - * @param value the value which, when passed to the compareTo method of the examined object, should return greater - * than or equal to zero - */ - public static > org.hamcrest.Matcher greaterThanOrEqualTo(T value) { - return org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo(value); - } - - /** - * Creates a matcher of {@link Comparable} object that matches when the examined object is - * less than the specified value, as reported by the compareTo method of the - * examined object. - * For example: - *
assertThat(1, lessThan(2))
- * - * @param value the value which, when passed to the compareTo method of the examined object, should return less - * than zero - */ - public static > org.hamcrest.Matcher lessThan(T value) { - return org.hamcrest.number.OrderingComparison.lessThan(value); - } - - /** - * Creates a matcher of {@link Comparable} object that matches when the examined object is - * less than or equal to the specified value, as reported by the compareTo method - * of the examined object. - * For example: - *
assertThat(1, lessThanOrEqualTo(1))
- * - * @param value the value which, when passed to the compareTo method of the examined object, should return less - * than or equal to zero - */ - public static > org.hamcrest.Matcher lessThanOrEqualTo(T value) { - return org.hamcrest.number.OrderingComparison.lessThanOrEqualTo(value); - } - - /** - * Creates a matcher of {@link String} that matches when the examined string is equal to - * the specified expectedString, ignoring case. - * For example: - *
assertThat("Foo", equalToIgnoringCase("FOO"))
- * - * @param expectedString - * the expected value of matched strings - */ - public static Matcher equalToIgnoringCase(java.lang.String expectedString) { - return org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase(expectedString); - } - - /** - * @deprecated {@link #equalToCompressingWhiteSpace(String)} - * @param expectedString - * the expected value of matched strings - */ - public static Matcher equalToIgnoringWhiteSpace(java.lang.String expectedString) { - return equalToCompressingWhiteSpace(expectedString); - } - - /** - * Creates a matcher of {@link String} that matches when the examined string is equal to - * the specified expectedString, when whitespace differences are (mostly) ignored. To be - * exact, the following whitespace rules are applied: - *
    - *
  • all leading and trailing whitespace of both the expectedString and the examined string are ignored
  • - *
  • any remaining whitespace, appearing within either string, is collapsed to a single space before comparison
  • - *
- * For example: - *
assertThat("   my\tfoo  bar ", equalToIgnoringWhiteSpace(" my  foo bar"))
- * - * @param expectedString - * the expected value of matched strings - */ - public static Matcher equalToCompressingWhiteSpace(java.lang.String expectedString) { - return IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace(expectedString); - } - - /** - * Creates a matcher of {@link String} that matches when the examined string is null, or - * has zero length. - * For example: - *
assertThat(((String)null), is(emptyOrNullString()))
- */ - public static Matcher emptyOrNullString() { - return org.hamcrest.text.IsEmptyString.emptyOrNullString(); - } - - /** - * Creates a matcher of {@link String} that matches when the examined string has zero length. - * For example: - *
assertThat("", is(emptyString()))
- */ - public static Matcher emptyString() { - return org.hamcrest.text.IsEmptyString.emptyString(); - } - - /** - * Creates a matcher of {@link String} that matches when the examined string is null, or - * has zero length. - * For example: - *
assertThat(((String)null), isEmptyOrNullString())
- * - * @deprecated use is(emptyOrNullString()) instead - */ - @SuppressWarnings("deprecation") - public static Matcher isEmptyOrNullString() { - return org.hamcrest.text.IsEmptyString.isEmptyOrNullString(); - } - - /** - * Creates a matcher of {@link String} that matches when the examined string has zero length. - * For example: - *
assertThat("", isEmptyString())
- * - * @deprecated use is(emptyString()) instead - */ - @SuppressWarnings("deprecation") - public static Matcher isEmptyString() { - return org.hamcrest.text.IsEmptyString.isEmptyString(); - } - - /** - * Creates a matcher of {@link String} that matches when the examined string is null, or - * contains zero or more whitespace characters and nothing else. - * For example: - *
assertThat(((String)null), is(blankOrNullString()))
- */ - public static Matcher blankOrNullString() { - return org.hamcrest.text.IsBlankString.blankOrNullString(); - } - - /** - * Creates a matcher of {@link String} that matches when the examined string contains - * zero or more whitespace characters and nothing else. - * For example: - *
assertThat("  ", is(blankString()))
- */ - public static Matcher blankString() { - return org.hamcrest.text.IsBlankString.blankString(); - } - - /** - * Creates a matcher of {@link java.lang.String} that matches when the examined string - * exactly matches the given {@link java.util.regex.Pattern}. - */ - public static Matcher matchesPattern(java.util.regex.Pattern pattern) { - return org.hamcrest.text.MatchesPattern.matchesPattern(pattern); - } - - /** - * Creates a matcher of {@link java.lang.String} that matches when the examined string - * exactly matches the given regular expression, treated as a {@link java.util.regex.Pattern}. - */ - public static Matcher matchesPattern(java.lang.String regex) { - return org.hamcrest.text.MatchesPattern.matchesPattern(regex); - } - - /** - * Creates a matcher of {@link String} that matches when the examined string contains all of - * the specified substrings, considering the order of their appearance. - * For example: - *
assertThat("myfoobarbaz", stringContainsInOrder(Arrays.asList("bar", "foo")))
- * fails as "foo" occurs before "bar" in the string "myfoobarbaz" - * - * @param substrings - * the substrings that must be contained within matching strings - */ - public static Matcher stringContainsInOrder(java.lang.Iterable substrings) { - return org.hamcrest.text.StringContainsInOrder.stringContainsInOrder(substrings); - } - - /** - * Creates a matcher of {@link String} that matches when the examined string contains all of - * the specified substrings, considering the order of their appearance. - * For example: - *
assertThat("myfoobarbaz", stringContainsInOrder("bar", "foo"))
- * fails as "foo" occurs before "bar" in the string "myfoobarbaz" - * - * @param substrings - * the substrings that must be contained within matching strings - */ - public static Matcher stringContainsInOrder(java.lang.String... substrings) { - return org.hamcrest.text.StringContainsInOrder.stringContainsInOrder(substrings); - } + /** + * Creates a matcher of {@link String} that matches when the examined string contains all of + * the specified substrings, considering the order of their appearance. + * For example: + *
assertThat("myfoobarbaz", stringContainsInOrder(Arrays.asList("bar", "foo")))
+ * fails as "foo" occurs before "bar" in the string "myfoobarbaz" + * + * @param substrings + * the substrings that must be contained within matching strings + * @return the created matcher + */ + public static Matcher stringContainsInOrder(Iterable substrings) { + return org.hamcrest.text.StringContainsInOrder.stringContainsInOrder(substrings); + } + + /** + * Creates a matcher of {@link String} that matches when the examined string contains all of + * the specified substrings, considering the order of their appearance. + * For example: + *
assertThat("myfoobarbaz", stringContainsInOrder("bar", "foo"))
+ * fails as "foo" occurs before "bar" in the string "myfoobarbaz" + * + * @param substrings + * the substrings that must be contained within matching strings + * @return the created matcher + */ + public static Matcher stringContainsInOrder(String... substrings) { + return org.hamcrest.text.StringContainsInOrder.stringContainsInOrder(substrings); + } /** * Creates a matcher of {@link CharSequence} that matches when a char sequence has the length @@ -1517,185 +1808,202 @@ public static Matcher stringContainsInOrder(java.lang.String.. * * * @param length the expected length of the string + * @return the created matcher */ public static Matcher hasLength(int length) { return org.hamcrest.text.CharSequenceLength.hasLength(length); } - /** - * Creates a matcher that matches any examined object whose toString method - * returns a value that satisfies the specified matcher. - * For example: - *
assertThat(true, hasToString(equalTo("TRUE")))
- * - * @param toStringMatcher - * the matcher used to verify the toString result - */ - public static org.hamcrest.Matcher hasToString(org.hamcrest.Matcher toStringMatcher) { - return org.hamcrest.object.HasToString.hasToString(toStringMatcher); - } - - /** - * Creates a matcher that matches any examined object whose toString method - * returns a value equalTo the specified string. - * For example: - *
assertThat(true, hasToString("TRUE"))
- * - * @param expectedToString - * the expected toString result - */ - public static org.hamcrest.Matcher hasToString(java.lang.String expectedToString) { - return org.hamcrest.object.HasToString.hasToString(expectedToString); - } - - /** - * Creates a matcher of {@link Class} that matches when the specified baseType is - * assignable from the examined class. - * For example: - *
assertThat(Integer.class, typeCompatibleWith(Number.class))
- * - * @param baseType - * the base class to examine classes against - */ - public static org.hamcrest.Matcher> typeCompatibleWith(java.lang.Class baseType) { - return org.hamcrest.object.IsCompatibleType.typeCompatibleWith(baseType); - } - - /** - * Creates a matcher of {@link java.util.EventObject} that matches any object - * derived from eventClass announced by source. - * For example: - *
assertThat(myEvent, is(eventFrom(PropertyChangeEvent.class, myBean)))
- * - * @param eventClass - * the class of the event to match on - * @param source - * the source of the event - */ - public static org.hamcrest.Matcher eventFrom(java.lang.Class eventClass, java.lang.Object source) { - return org.hamcrest.object.IsEventFrom.eventFrom(eventClass, source); - } - - /** - * Creates a matcher of {@link java.util.EventObject} that matches any EventObject - * announced by source. - * For example: - *
assertThat(myEvent, is(eventFrom(myBean)))
- * - * @param source - * the source of the event - */ - public static org.hamcrest.Matcher eventFrom(java.lang.Object source) { - return org.hamcrest.object.IsEventFrom.eventFrom(source); - } - - /** - * Creates a matcher that matches when the examined object has a JavaBean property - * with the specified name. - * For example: - *
assertThat(myBean, hasProperty("foo"))
- * - * @param propertyName - * the name of the JavaBean property that examined beans should possess - */ - public static org.hamcrest.Matcher hasProperty(java.lang.String propertyName) { - return org.hamcrest.beans.HasProperty.hasProperty(propertyName); - } - - /** - * Creates a matcher that matches when the examined object has a JavaBean property - * with the specified name whose value satisfies the specified matcher. - * For example: - *
assertThat(myBean, hasProperty("foo", equalTo("bar"))
- * - * @param propertyName - * the name of the JavaBean property that examined beans should possess - * @param valueMatcher - * a matcher for the value of the specified property of the examined bean - */ - public static org.hamcrest.Matcher hasProperty(java.lang.String propertyName, org.hamcrest.Matcher valueMatcher) { - return org.hamcrest.beans.HasPropertyWithValue.hasProperty(propertyName, valueMatcher); - } - - /** - * Creates a matcher that matches when the examined object has values for all of - * its JavaBean properties that are equal to the corresponding values of the - * specified bean. If any properties are marked as ignored, they will be dropped from - * both the expected and actual bean. Note that the ignored properties use JavaBean - * display names, for example
age
rather than method names such as
getAge
. - * For example: - *
assertThat(myBean, samePropertyValuesAs(myExpectedBean))
- *
assertThat(myBean, samePropertyValuesAs(myExpectedBean), "age", "height")
- * - * @param expectedBean - * the bean against which examined beans are compared - * @param ignoredProperties - * do not check any of these named properties. - */ - public static Matcher samePropertyValuesAs(B expectedBean, String... ignoredProperties) { - return org.hamcrest.beans.SamePropertyValuesAs.samePropertyValuesAs(expectedBean, ignoredProperties); - } - - /** - * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node has a value at the - * specified xPath that satisfies the specified valueMatcher. - * For example: - *
assertThat(xml, hasXPath("/root/something[2]/cheese", equalTo("Cheddar")))
- * - * @param xPath - * the target xpath - * @param valueMatcher - * matcher for the value at the specified xpath - */ - public static org.hamcrest.Matcher hasXPath(java.lang.String xPath, Matcher valueMatcher) { - return org.hamcrest.xml.HasXPath.hasXPath(xPath, valueMatcher); - } - - /** - * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node has a value at the - * specified xPath, within the specified namespaceContext, that satisfies - * the specified valueMatcher. - * For example: - *
assertThat(xml, hasXPath("/root/something[2]/cheese", myNs, equalTo("Cheddar")))
- * - * @param xPath - * the target xpath - * @param namespaceContext - * the namespace for matching nodes - * @param valueMatcher - * matcher for the value at the specified xpath - */ - public static org.hamcrest.Matcher hasXPath(java.lang.String xPath, javax.xml.namespace.NamespaceContext namespaceContext, Matcher valueMatcher) { - return org.hamcrest.xml.HasXPath.hasXPath(xPath, namespaceContext, valueMatcher); - } - - /** - * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node contains a node - * at the specified xPath, with any content. - * For example: - *
assertThat(xml, hasXPath("/root/something[2]/cheese"))
- * - * @param xPath - * the target xpath - */ - public static org.hamcrest.Matcher hasXPath(java.lang.String xPath) { - return org.hamcrest.xml.HasXPath.hasXPath(xPath); - } - - /** - * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node contains a node - * at the specified xPath within the specified namespace context, with any content. - * For example: - *
assertThat(xml, hasXPath("/root/something[2]/cheese", myNs))
- * - * @param xPath - * the target xpath - * @param namespaceContext - * the namespace for matching nodes - */ - public static org.hamcrest.Matcher hasXPath(java.lang.String xPath, javax.xml.namespace.NamespaceContext namespaceContext) { - return org.hamcrest.xml.HasXPath.hasXPath(xPath, namespaceContext); - } + /** + * Creates a matcher that matches any examined object whose toString method + * returns a value that satisfies the specified matcher. + * For example: + *
assertThat(true, hasToString(equalTo("TRUE")))
+ * + * @param the matcher type + * @param toStringMatcher + * the matcher used to verify the toString result + * @return the created matcher + */ + public static Matcher hasToString(Matcher toStringMatcher) { + return org.hamcrest.object.HasToString.hasToString(toStringMatcher); + } + + /** + * Creates a matcher that matches any examined object whose toString method + * returns a value equalTo the specified string. + * For example: + *
assertThat(true, hasToString("TRUE"))
+ * + * @param the matcher type + * @param expectedToString + * the expected toString result + * @return the created matcher + */ + public static Matcher hasToString(String expectedToString) { + return org.hamcrest.object.HasToString.hasToString(expectedToString); + } + + /** + * Creates a matcher of {@link Class} that matches when the specified baseType is + * assignable from the examined class. + * For example: + *
assertThat(Integer.class, typeCompatibleWith(Number.class))
+ * + * @param the matcher type + * @param baseType + * the base class to examine classes against + * @return the created matcher + */ + public static Matcher> typeCompatibleWith(Class baseType) { + return org.hamcrest.object.IsCompatibleType.typeCompatibleWith(baseType); + } + + /** + * Creates a matcher of {@link java.util.EventObject} that matches any object + * derived from eventClass announced by source. + * For example: + *
assertThat(myEvent, is(eventFrom(PropertyChangeEvent.class, myBean)))
+ * + * @param eventClass + * the class of the event to match on + * @param source + * the source of the event + * @return the created matcher + */ + public static Matcher eventFrom(Class eventClass, Object source) { + return org.hamcrest.object.IsEventFrom.eventFrom(eventClass, source); + } + + /** + * Creates a matcher of {@link java.util.EventObject} that matches any EventObject + * announced by source. + * For example: + *
assertThat(myEvent, is(eventFrom(myBean)))
+ * + * @param source + * the source of the event + * @return the created matcher + */ + public static Matcher eventFrom(Object source) { + return org.hamcrest.object.IsEventFrom.eventFrom(source); + } + + /** + * Creates a matcher that matches when the examined object has a JavaBean property + * with the specified name. + * For example: + *
assertThat(myBean, hasProperty("foo"))
+ * + * @param the matcher type + * @param propertyName + * the name of the JavaBean property that examined beans should possess + * @return the created matcher + */ + public static Matcher hasProperty(String propertyName) { + return org.hamcrest.beans.HasProperty.hasProperty(propertyName); + } + + /** + * Creates a matcher that matches when the examined object has a JavaBean property + * with the specified name whose value satisfies the specified matcher. + * For example: + *
assertThat(myBean, hasProperty("foo", equalTo("bar"))
+ * + * @param the matcher type + * @param propertyName + * the name of the JavaBean property that examined beans should possess + * @param valueMatcher + * a matcher for the value of the specified property of the examined bean + * @return the created matcher + */ + public static Matcher hasProperty(String propertyName, Matcher valueMatcher) { + return org.hamcrest.beans.HasPropertyWithValue.hasProperty(propertyName, valueMatcher); + } + + /** + * Creates a matcher that matches when the examined object has values for all of + * its JavaBean properties that are equal to the corresponding values of the + * specified bean. If any properties are marked as ignored, they will be dropped from + * both the expected and actual bean. Note that the ignored properties use JavaBean + * display names, for example
age
rather than method names such as
getAge
. + * For example: + *
assertThat(myBean, samePropertyValuesAs(myExpectedBean))
+ *
assertThat(myBean, samePropertyValuesAs(myExpectedBean), "age", "height")
+ * + * @param the matcher type + * @param expectedBean + * the bean against which examined beans are compared + * @param ignoredProperties + * do not check any of these named properties. + * @return the created matcher + */ + public static Matcher samePropertyValuesAs(T expectedBean, String... ignoredProperties) { + return org.hamcrest.beans.SamePropertyValuesAs.samePropertyValuesAs(expectedBean); + } + + /** + * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node has a value at the + * specified xPath that satisfies the specified valueMatcher. + * For example: + *
assertThat(xml, hasXPath("/root/something[2]/cheese", equalTo("Cheddar")))
+ * + * @param xPath + * the target xpath + * @param valueMatcher + * matcher for the value at the specified xpath + * @return the created matcher + */ + public static Matcher hasXPath(String xPath, Matcher valueMatcher) { + return org.hamcrest.xml.HasXPath.hasXPath(xPath, valueMatcher); + } + + /** + * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node has a value at the + * specified xPath, within the specified namespaceContext, that satisfies + * the specified valueMatcher. + * For example: + *
assertThat(xml, hasXPath("/root/something[2]/cheese", myNs, equalTo("Cheddar")))
+ * + * @param xPath + * the target xpath + * @param namespaceContext + * the namespace for matching nodes + * @param valueMatcher + * matcher for the value at the specified xpath + * @return the created matcher + */ + public static Matcher hasXPath(String xPath, javax.xml.namespace.NamespaceContext namespaceContext, Matcher valueMatcher) { + return org.hamcrest.xml.HasXPath.hasXPath(xPath, namespaceContext, valueMatcher); + } + /** + * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node contains a node + * at the specified xPath, with any content. + * For example: + *
assertThat(xml, hasXPath("/root/something[2]/cheese"))
+ * + * @param xPath + * the target xpath + * @return the created matcher + */ + public static Matcher hasXPath(String xPath) { + return org.hamcrest.xml.HasXPath.hasXPath(xPath); + } + /** + * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node contains a node + * at the specified xPath within the specified namespace context, with any content. + * For example: + *
assertThat(xml, hasXPath("/root/something[2]/cheese", myNs))
+ * + * @param xPath + * the target xpath + * @param namespaceContext + * the namespace for matching nodes + * @return the created matcher + */ + public static Matcher hasXPath(String xPath, javax.xml.namespace.NamespaceContext namespaceContext) { + return org.hamcrest.xml.HasXPath.hasXPath(xPath, namespaceContext); + } } diff --git a/hamcrest/src/main/java/org/hamcrest/SelfDescribing.java b/hamcrest/src/main/java/org/hamcrest/SelfDescribing.java index 06b361d2..5cfe5594 100644 --- a/hamcrest/src/main/java/org/hamcrest/SelfDescribing.java +++ b/hamcrest/src/main/java/org/hamcrest/SelfDescribing.java @@ -1,14 +1,46 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; /** * The ability of an object to describe itself. */ public interface SelfDescribing { + /** * Generates a description of the object. The description may be part of a - * a description of a larger object of which this is just a component, so it + * a description of a larger object of which this is just a component, so it * should be worded appropriately. - * + * * @param description * The description to be built or appended to. */ diff --git a/hamcrest/src/main/java/org/hamcrest/StringDescription.java b/hamcrest/src/main/java/org/hamcrest/StringDescription.java index 813c1782..2023c74e 100644 --- a/hamcrest/src/main/java/org/hamcrest/StringDescription.java +++ b/hamcrest/src/main/java/org/hamcrest/StringDescription.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; import java.io.IOException; @@ -15,10 +46,10 @@ public StringDescription() { public StringDescription(Appendable out) { this.out = out; } - + /** * Return the description of a {@link SelfDescribing} object as a String. - * + * * @param selfDescribing * The object to be described. * @return @@ -30,6 +61,8 @@ public static String toString(SelfDescribing selfDescribing) { /** * Alias for {@link #toString(SelfDescribing)}. + * @param selfDescribing the string to represent + * @return the generated string */ public static String asString(SelfDescribing selfDescribing) { return toString(selfDescribing); @@ -52,7 +85,7 @@ protected void append(char c) { throw new RuntimeException("Could not write description", e); } } - + /** * Returns the description as a string. */ diff --git a/hamcrest/src/main/java/org/hamcrest/TypeSafeDiagnosingMatcher.java b/hamcrest/src/main/java/org/hamcrest/TypeSafeDiagnosingMatcher.java index 03efa9db..ff4774d3 100644 --- a/hamcrest/src/main/java/org/hamcrest/TypeSafeDiagnosingMatcher.java +++ b/hamcrest/src/main/java/org/hamcrest/TypeSafeDiagnosingMatcher.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; import org.hamcrest.internal.ReflectiveTypeFinder; @@ -6,16 +37,16 @@ /** * Convenient base class for Matchers that require a non-null value of a specific type * and that will report why the received value has been rejected. - * This implements the null check, checks the type and then casts. - * To use, implement
matchesSafely()
. + * This implements the null check, checks the type and then casts. + * To use, implement
matchesSafely()
. * - * @param * @author Neil Dunn * @author Nat Pryce * @author Steve Freeman + * @param the matcher type */ public abstract class TypeSafeDiagnosingMatcher extends BaseMatcher { - private static final ReflectiveTypeFinder TYPE_FINDER = new ReflectiveTypeFinder("matchesSafely", 2, 0); + private static final ReflectiveTypeFinder TYPE_FINDER = new ReflectiveTypeFinder("matchesSafely", 2, 0); private final Class expectedType; /** @@ -25,50 +56,50 @@ public abstract class TypeSafeDiagnosingMatcher extends BaseMatcher { protected abstract boolean matchesSafely(T item, Description mismatchDescription); /** - * Use this constructor if the subclass that implements matchesSafely - * is not the class that binds <T> to a type. + * Use this constructor if the subclass that implements matchesSafely + * is not the class that binds <T> to a type. * @param expectedType The expectedType of the actual value. */ protected TypeSafeDiagnosingMatcher(Class expectedType) { - this.expectedType = expectedType; + this.expectedType = expectedType; } /** - * Use this constructor if the subclass that implements matchesSafely - * is not the class that binds <T> to a type. + * Use this constructor if the subclass that implements matchesSafely + * is not the class that binds <T> to a type. * @param typeFinder A type finder to extract the type */ protected TypeSafeDiagnosingMatcher(ReflectiveTypeFinder typeFinder) { - this.expectedType = typeFinder.findExpectedType(getClass()); + this.expectedType = typeFinder.findExpectedType(getClass()); } /** * The default constructor for simple sub types */ protected TypeSafeDiagnosingMatcher() { - this(TYPE_FINDER); + this(TYPE_FINDER); } @Override @SuppressWarnings("unchecked") public final boolean matches(Object item) { return item != null - && expectedType.isInstance(item) - && matchesSafely((T) item, new Description.NullDescription()); + && expectedType.isInstance(item) + && matchesSafely((T) item, new Description.NullDescription()); } @SuppressWarnings("unchecked") @Override public final void describeMismatch(Object item, Description mismatchDescription) { - if (item == null) { - mismatchDescription.appendText("was null"); - } else if (!expectedType.isInstance(item)) { - mismatchDescription.appendText("was ") - .appendText(item.getClass().getSimpleName()) - .appendText(" ") - .appendValue(item); - } else { - matchesSafely((T) item, mismatchDescription); - } + if (item == null) { + mismatchDescription.appendText("was null"); + } else if (!expectedType.isInstance(item)) { + mismatchDescription.appendText("was ") + .appendText(item.getClass().getSimpleName()) + .appendText(" ") + .appendValue(item); + } else { + matchesSafely((T) item, mismatchDescription); + } } } diff --git a/hamcrest/src/main/java/org/hamcrest/TypeSafeMatcher.java b/hamcrest/src/main/java/org/hamcrest/TypeSafeMatcher.java index 08dfce8b..a58783a2 100644 --- a/hamcrest/src/main/java/org/hamcrest/TypeSafeMatcher.java +++ b/hamcrest/src/main/java/org/hamcrest/TypeSafeMatcher.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; import org.hamcrest.internal.ReflectiveTypeFinder; @@ -9,10 +40,11 @@ * @author Joe Walnes * @author Steve Freeman * @author Nat Pryce + * @param the matcher type */ public abstract class TypeSafeMatcher extends BaseMatcher { private static final ReflectiveTypeFinder TYPE_FINDER = new ReflectiveTypeFinder("matchesSafely", 1, 0); - + final private Class expectedType; /** @@ -21,43 +53,48 @@ public abstract class TypeSafeMatcher extends BaseMatcher { protected TypeSafeMatcher() { this(TYPE_FINDER); } - + /** - * Use this constructor if the subclass that implements matchesSafely - * is not the class that binds <T> to a type. + * Use this constructor if the subclass that implements matchesSafely + * is not the class that binds <T> to a type. * @param expectedType The expectedType of the actual value. */ protected TypeSafeMatcher(Class expectedType) { this.expectedType = expectedType; } - + /** - * Use this constructor if the subclass that implements matchesSafely - * is not the class that binds <T> to a type. + * Use this constructor if the subclass that implements matchesSafely + * is not the class that binds <T> to a type. * @param typeFinder A type finder to extract the type */ protected TypeSafeMatcher(ReflectiveTypeFinder typeFinder) { - this.expectedType = typeFinder.findExpectedType(getClass()); + this.expectedType = typeFinder.findExpectedType(getClass()); } - + /** * Subclasses should implement this. The item will already have been checked for * the specific type and will never be null. + * @param item the item to match */ protected abstract boolean matchesSafely(T item); - + /** * Subclasses should override this. The item will already have been checked for * the specific type and will never be null. + * @param item the item to match + * @param mismatchDescription the description of an eventual mismatch */ protected void describeMismatchSafely(T item, Description mismatchDescription) { super.describeMismatch(item, mismatchDescription); } - + /** * Methods made final to prevent accidental override. * If you need to override this, there's no point on extending TypeSafeMatcher. * Instead, extend the {@link BaseMatcher}. + * @param item the item to match + * @return {@code true} it {@code item} matches, {@code false} otherwise */ @Override @SuppressWarnings({"unchecked"}) @@ -66,7 +103,7 @@ public final boolean matches(Object item) { && expectedType.isInstance(item) && matchesSafely((T) item); } - + @SuppressWarnings("unchecked") @Override final public void describeMismatch(Object item, Description description) { diff --git a/hamcrest/src/main/java/org/hamcrest/beans/HasProperty.java b/hamcrest/src/main/java/org/hamcrest/beans/HasProperty.java index 320a49ef..a16e3b80 100644 --- a/hamcrest/src/main/java/org/hamcrest/beans/HasProperty.java +++ b/hamcrest/src/main/java/org/hamcrest/beans/HasProperty.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.beans; import org.hamcrest.Description; @@ -12,9 +43,9 @@ * @author Iain McGinniss * @author Nat Pryce * @author Steve Freeman + * @param the matcher type */ public class HasProperty extends TypeSafeMatcher { - private final String propertyName; public HasProperty(String propertyName) { @@ -45,12 +76,13 @@ public void describeTo(Description description) { * with the specified name. * For example: *
assertThat(myBean, hasProperty("foo"))
- * + * + * @param the matcher type * @param propertyName * the name of the JavaBean property that examined beans should possess + * @return the created matcher */ public static Matcher hasProperty(String propertyName) { return new HasProperty(propertyName); } - } diff --git a/hamcrest/src/main/java/org/hamcrest/beans/HasPropertyWithValue.java b/hamcrest/src/main/java/org/hamcrest/beans/HasPropertyWithValue.java index 29b299b8..7b3c89f5 100644 --- a/hamcrest/src/main/java/org/hamcrest/beans/HasPropertyWithValue.java +++ b/hamcrest/src/main/java/org/hamcrest/beans/HasPropertyWithValue.java @@ -1,19 +1,48 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.beans; -import org.hamcrest.Condition; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeDiagnosingMatcher; - import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; import java.util.ListIterator; - +import org.hamcrest.Condition; import static org.hamcrest.Condition.matched; import static org.hamcrest.Condition.notMatched; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeDiagnosingMatcher; import static org.hamcrest.beans.PropertyUtil.NO_ARGUMENTS; /** @@ -37,7 +66,7 @@ * return name; * } * } - * + * * And that these person objects are generated within a piece of code under test * (a class named PersonGenerator). This object is sent to one of our mock objects * which overrides the PersonGenerationListener interface: @@ -45,14 +74,14 @@ * public interface PersonGenerationListener { * public void personGenerated(Person person); * } - * + * * In order to check that the code under test generates a person with name * "Iain" we would do the following: *
  * Mock personGenListenerMock = mock(PersonGenerationListener.class);
  * personGenListenerMock.expects(once()).method("personGenerated").with(and(isA(Person.class), hasProperty("Name", eq("Iain")));
  * PersonGenerationListener listener = (PersonGenerationListener)personGenListenerMock.proxy();
- * + * *

If an exception is thrown by the getter method for a property, the property * does not exist, is not readable, or a reflection related exception is thrown * when trying to invoke it then this is treated as an evaluation failure and @@ -68,6 +97,7 @@ * @author Nat Pryce * @author Steve Freeman * @author cristcost at github + * @param the matcher type */ public class HasPropertyWithValue extends TypeSafeDiagnosingMatcher { private static final Condition.Step WITH_READ_METHOD = withReadMethod(); @@ -117,10 +147,10 @@ public Condition apply(Method readMethod, Description mismatch) { return matched(readMethod.invoke(bean, NO_ARGUMENTS), mismatch); } catch (InvocationTargetException e) { mismatch - .appendText("Calling '") - .appendText(readMethod.toString()) - .appendText("': ") - .appendValue(e.getTargetException().getMessage()); + .appendText("Calling '") + .appendText(readMethod.toString()) + .appendText("': ") + .appendValue(e.getTargetException().getMessage()); return notMatched(); } catch (Exception e) { throw new IllegalStateException( @@ -154,11 +184,13 @@ public Condition apply(PropertyDescriptor property, Description mismatch * with the specified name whose value satisfies the specified matcher. * For example: *
assertThat(myBean, hasProperty("foo", equalTo("bar"))
- * + * + * @param the matcher type * @param propertyName * the name of the JavaBean property that examined beans should possess * @param valueMatcher * a matcher for the value of the specified property of the examined bean + * @return the created matcher */ public static Matcher hasProperty(String propertyName, Matcher valueMatcher) { return new HasPropertyWithValue<>(propertyName, valueMatcher); @@ -172,21 +204,23 @@ public static Matcher hasProperty(String propertyName, Matcher valueMa * For example: *
assertThat(myBean, hasProperty("foo.bar.baz", equalTo("a property value"))
* + * @param the matcher type * @param path * the dot-separated path from the examined object to the JavaBean property * @param valueMatcher * a matcher for the value of the specified property of the examined bean + * @return the created matcher */ public static Matcher hasPropertyAtPath(String path, Matcher valueMatcher) { List properties = Arrays.asList(path.split("\\.")); - ListIterator iterator = + ListIterator iterator = properties.listIterator(properties.size()); - Matcher ret = valueMatcher; - while (iterator.hasPrevious()) { - ret = new HasPropertyWithValue<>(iterator.previous(), ret, "%s."); - } - return ret; + Matcher ret = valueMatcher; + while (iterator.hasPrevious()) { + ret = new HasPropertyWithValue<>(iterator.previous(), ret, "%s."); + } + return ret; } } diff --git a/hamcrest/src/main/java/org/hamcrest/beans/PropertyUtil.java b/hamcrest/src/main/java/org/hamcrest/beans/PropertyUtil.java index 946c4f84..5f29f17a 100644 --- a/hamcrest/src/main/java/org/hamcrest/beans/PropertyUtil.java +++ b/hamcrest/src/main/java/org/hamcrest/beans/PropertyUtil.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.beans; import java.beans.IntrospectionException; @@ -14,10 +45,13 @@ * @since 1.1.0 */ public class PropertyUtil { + /** * Returns the description of the property with the provided * name on the provided object's interface. * + * @param propertyName the property name + * @param fromObj the object source * @return the descriptor of the property, or null if the property does not exist. * @throws IllegalArgumentException if there's a introspection failure */ @@ -33,18 +67,18 @@ public static PropertyDescriptor getPropertyDescriptor(String propertyName, Obje /** * Returns all the property descriptors for the class associated with the given object - * + * * @param fromObj Use the class of this object * @param stopClass Don't include any properties from this ancestor class upwards. * @return Property descriptors * @throws IllegalArgumentException if there's a introspection failure */ public static PropertyDescriptor[] propertyDescriptorsFor(Object fromObj, Class stopClass) throws IllegalArgumentException { - try { - return Introspector.getBeanInfo(fromObj.getClass(), stopClass).getPropertyDescriptors(); - } catch (IntrospectionException e) { - throw new IllegalArgumentException("Could not get property descriptors for " + fromObj.getClass(), e); - } + try { + return Introspector.getBeanInfo(fromObj.getClass(), stopClass).getPropertyDescriptors(); + } catch (IntrospectionException e) { + throw new IllegalArgumentException("Could not get property descriptors for " + fromObj.getClass(), e); + } } public static final Object[] NO_ARGUMENTS = new Object[0]; diff --git a/hamcrest/src/main/java/org/hamcrest/beans/SamePropertyValuesAs.java b/hamcrest/src/main/java/org/hamcrest/beans/SamePropertyValuesAs.java index 4799aeaa..e5b7317c 100644 --- a/hamcrest/src/main/java/org/hamcrest/beans/SamePropertyValuesAs.java +++ b/hamcrest/src/main/java/org/hamcrest/beans/SamePropertyValuesAs.java @@ -1,18 +1,54 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.beans; -import org.hamcrest.Description; -import org.hamcrest.DiagnosingMatcher; -import org.hamcrest.Matcher; - import java.beans.PropertyDescriptor; import java.lang.reflect.Method; -import java.util.*; - +import java.util.ArrayList; import static java.util.Arrays.asList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.hamcrest.Description; +import org.hamcrest.DiagnosingMatcher; +import org.hamcrest.Matcher; import static org.hamcrest.beans.PropertyUtil.NO_ARGUMENTS; import static org.hamcrest.beans.PropertyUtil.propertyDescriptorsFor; import static org.hamcrest.core.IsEqual.equalTo; +/** + * A matcher that matches identical property values. + * @param the matcher type + */ public class SamePropertyValuesAs extends DiagnosingMatcher { private final T expectedBean; private final Set propertyNames; @@ -147,12 +183,14 @@ private static Object readProperty(Method method, Object target) { *
assertThat(myBean, samePropertyValuesAs(myExpectedBean))
*
assertThat(myBean, samePropertyValuesAs(myExpectedBean), "age", "height")
* + * @param the matcher type * @param expectedBean * the bean against which examined beans are compared * @param ignoredProperties * do not check any of these named properties. + * @return the created matcher */ - public static Matcher samePropertyValuesAs(B expectedBean, String... ignoredProperties) { + public static Matcher samePropertyValuesAs(T expectedBean, String... ignoredProperties) { return new SamePropertyValuesAs<>(expectedBean, asList(ignoredProperties)); } diff --git a/hamcrest/src/main/java/org/hamcrest/collection/ArrayAsIterableMatcher.java b/hamcrest/src/main/java/org/hamcrest/collection/ArrayAsIterableMatcher.java index a841a2c9..3aef696a 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/ArrayAsIterableMatcher.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/ArrayAsIterableMatcher.java @@ -1,45 +1,73 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; +import static java.util.Arrays.asList; +import java.util.Collection; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; import org.hamcrest.TypeSafeMatcher; -import java.util.Collection; - -import static java.util.Arrays.asList; - /** * @author Steve Freeman 2016 http://www.hamcrest.com + * @param the matcher type */ public class ArrayAsIterableMatcher extends TypeSafeMatcher { - protected final TypeSafeDiagnosingMatcher> iterableMatcher; - private final String message; - protected final Collection> matchers; + protected final TypeSafeDiagnosingMatcher> iterableMatcher; + private final String message; + protected final Collection> matchers; - public ArrayAsIterableMatcher( - TypeSafeDiagnosingMatcher> iterableMatcher, - Collection> matchers, - String message) - { - this.matchers = matchers; - this.iterableMatcher = iterableMatcher; - this.message = message; - } + public ArrayAsIterableMatcher(TypeSafeDiagnosingMatcher> iterableMatcher, + Collection> matchers, + String message) { + this.matchers = matchers; + this.iterableMatcher = iterableMatcher; + this.message = message; + } - @Override - public boolean matchesSafely(E[] item) { - return iterableMatcher.matches(asList(item)); - } + @Override + public boolean matchesSafely(E[] item) { + return iterableMatcher.matches(asList(item)); + } - @Override - public void describeMismatchSafely(E[] item, Description mismatchDescription) { - iterableMatcher.describeMismatch(asList(item), mismatchDescription); - } + @Override + public void describeMismatchSafely(E[] item, Description mismatchDescription) { + iterableMatcher.describeMismatch(asList(item), mismatchDescription); + } - @Override - public void describeTo(Description description) { - description.appendList("[", ", ", "]", matchers) - .appendText(" ").appendText(message); - } + @Override + public void describeTo(Description description) { + description.appendList("[", ", ", "]", matchers) + .appendText(" ").appendText(message); + } } diff --git a/hamcrest/src/main/java/org/hamcrest/collection/ArrayMatching.java b/hamcrest/src/main/java/org/hamcrest/collection/ArrayMatching.java index fc968e0b..a1a76267 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/ArrayMatching.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/ArrayMatching.java @@ -1,175 +1,220 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; -import org.hamcrest.Matcher; -import org.hamcrest.internal.NullSafety; - import java.util.ArrayList; +import static java.util.Arrays.asList; import java.util.Collection; import java.util.List; - -import static java.util.Arrays.asList; +import org.hamcrest.Matcher; import static org.hamcrest.core.IsEqual.equalTo; +import org.hamcrest.internal.NullSafety; /** - * @author Steve Freeman 2016 http://www.hamcrest.com * Collected helper code for converting matchers between lists and iterables. + * @author Steve Freeman 2016 http://www.hamcrest.com */ public class ArrayMatching { + /** + * Creates a matcher for arrays that matches when the examined array contains at least one item + * that is matched by the specified elementMatcher. Whilst matching, the traversal + * of the examined array will stop as soon as a matching element is found. + * For example: + *
assertThat(new String[] {"foo", "bar"}, hasItemInArray(startsWith("ba")))
+ * + * @param the matcher type + * @param elementMatcher + * the matcher to apply to elements in examined arrays + * @return the created matcher + */ + public static Matcher hasItemInArray(Matcher elementMatcher) { + return new HasItemInArray<>(elementMatcher); + } - /** - * Creates a matcher for arrays that matches when the examined array contains at least one item - * that is matched by the specified elementMatcher. Whilst matching, the traversal - * of the examined array will stop as soon as a matching element is found. - * For example: - *
assertThat(new String[] {"foo", "bar"}, hasItemInArray(startsWith("ba")))
- * - * @param elementMatcher - * the matcher to apply to elements in examined arrays - */ - public static Matcher hasItemInArray(Matcher elementMatcher) { - return new HasItemInArray<>(elementMatcher); - } + /** + * A shortcut to the frequently used hasItemInArray(equalTo(x)). + * For example: + *
assertThat(hasItemInArray(x))
+ * instead of: + *
assertThat(hasItemInArray(equalTo(x)))
+ * + * @param the matcher type + * @param element + * the element that should be present in examined arrays + * @return the created matcher + */ + public static Matcher hasItemInArray(T element) { + return hasItemInArray(equalTo(element)); + } - /** - * A shortcut to the frequently used hasItemInArray(equalTo(x)). - * For example: - *
assertThat(hasItemInArray(x))
- * instead of: - *
assertThat(hasItemInArray(equalTo(x)))
- * - * @param element - * the element that should be present in examined arrays - */ - public static Matcher hasItemInArray(T element) { - return hasItemInArray(equalTo(element)); - } + /** + *

+ * Creates an order agnostic matcher for arrays that matches when each item in the + * examined array satisfies one matcher anywhere in the specified matchers. + * For a positive match, the examined array must be of the same length as the number of + * specified matchers. + *

+ *

+ * N.B. each of the specified matchers will only be used once during a given examination, so be + * careful when specifying matchers that may be satisfied by more than one entry in an examined + * array. + *

+ *

+ * For example: + *

+ *
assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(equalTo("bar"), equalTo("foo")))
+ * + * @param the matcher type + * @param itemMatchers + * a list of matchers, each of which must be satisfied by an entry in an examined array + * @return the created matcher + */ + @SafeVarargs + public static Matcher arrayContainingInAnyOrder(Matcher... itemMatchers) { + return arrayContainingInAnyOrder(asList(itemMatchers)); + } - /** - *

- * Creates an order agnostic matcher for arrays that matches when each item in the - * examined array satisfies one matcher anywhere in the specified matchers. - * For a positive match, the examined array must be of the same length as the number of - * specified matchers. - *

- *

- * N.B. each of the specified matchers will only be used once during a given examination, so be - * careful when specifying matchers that may be satisfied by more than one entry in an examined - * array. - *

- *

- * For example: - *

- *
assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(equalTo("bar"), equalTo("foo")))
- * - * @param itemMatchers - * a list of matchers, each of which must be satisfied by an entry in an examined array - */ - @SafeVarargs - public static Matcher arrayContainingInAnyOrder(Matcher... itemMatchers) { - return arrayContainingInAnyOrder(asList(itemMatchers)); - } + /** + *

+ * Creates an order agnostic matcher for arrays that matches when each item in the + * examined array satisfies one matcher anywhere in the specified collection of matchers. + * For a positive match, the examined array must be of the same length as the specified collection + * of matchers. + *

+ *

+ * N.B. each matcher in the specified collection will only be used once during a given + * examination, so be careful when specifying matchers that may be satisfied by more than + * one entry in an examined array. + *

+ *

+ * For example: + *

+ *
assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(Arrays.asList(equalTo("bar"), equalTo("foo"))))
+ * + * @param the matcher type + * @param itemMatchers + * a list of matchers, each of which must be satisfied by an item provided by an examined array + * @return the created matcher + */ + public static Matcher arrayContainingInAnyOrder(Collection> itemMatchers) { + return new ArrayAsIterableMatcher<>(new IsIterableContainingInAnyOrder<>(itemMatchers), itemMatchers, "in any order"); + } - /** - *

- * Creates an order agnostic matcher for arrays that matches when each item in the - * examined array satisfies one matcher anywhere in the specified collection of matchers. - * For a positive match, the examined array must be of the same length as the specified collection - * of matchers. - *

- *

- * N.B. each matcher in the specified collection will only be used once during a given - * examination, so be careful when specifying matchers that may be satisfied by more than - * one entry in an examined array. - *

- *

- * For example: - *

- *
assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(Arrays.asList(equalTo("bar"), equalTo("foo"))))
- * - * @param itemMatchers - * a list of matchers, each of which must be satisfied by an item provided by an examined array - */ - public static Matcher arrayContainingInAnyOrder(Collection> itemMatchers) { - return new ArrayAsIterableMatcher<>(new IsIterableContainingInAnyOrder<>(itemMatchers), itemMatchers, "in any order"); - } + /** + *

Creates an order agnostic matcher for arrays that matches when each item in the + * examined array is logically equal to one item anywhere in the specified items. + * For a positive match, the examined array must be of the same length as the number of + * specified items. + *

+ *

N.B. each of the specified items will only be used once during a given examination, so be + * careful when specifying items that may be equal to more than one entry in an examined + * array. + *

+ *

+ * For example: + *

+ *
assertThat(new String[]{"foo", "bar"}, containsInAnyOrder("bar", "foo"))
+ * + * @param the matcher type + * @param items + * the items that must equal the entries of an examined array, in any order + * @return the created matcher + */ + @SafeVarargs + public static Matcher arrayContainingInAnyOrder(T... items) { + return arrayContainingInAnyOrder(asEqualMatchers(items)); + } - /** - *

Creates an order agnostic matcher for arrays that matches when each item in the - * examined array is logically equal to one item anywhere in the specified items. - * For a positive match, the examined array must be of the same length as the number of - * specified items. - *

- *

N.B. each of the specified items will only be used once during a given examination, so be - * careful when specifying items that may be equal to more than one entry in an examined - * array. - *

- *

- * For example: - *

- *
assertThat(new String[]{"foo", "bar"}, containsInAnyOrder("bar", "foo"))
- * - * @param items - * the items that must equal the entries of an examined array, in any order - */ - @SafeVarargs - public static Matcher arrayContainingInAnyOrder(E... items) { - return arrayContainingInAnyOrder(asEqualMatchers(items)); - } + /** + * Creates a matcher for arrays that matches when each item in the examined array is + * logically equal to the corresponding item in the specified items. For a positive match, + * the examined array must be of the same length as the number of specified items. + * For example: + *
assertThat(new String[]{"foo", "bar"}, contains("foo", "bar"))
+ * + * @param the matcher type + * @param items + * the items that must equal the items within an examined array + * @return the created matcher + */ + @SafeVarargs + public static Matcher arrayContaining(T... items) { + return arrayContaining(asEqualMatchers(items)); + } - /** - * Creates a matcher for arrays that matches when each item in the examined array is - * logically equal to the corresponding item in the specified items. For a positive match, - * the examined array must be of the same length as the number of specified items. - * For example: - *
assertThat(new String[]{"foo", "bar"}, contains("foo", "bar"))
- * - * @param items - * the items that must equal the items within an examined array - */ - @SafeVarargs - public static Matcher arrayContaining(E... items) { - return arrayContaining(asEqualMatchers(items)); - } - /** - * Creates a matcher for arrays that matches when each item in the examined array satisfies the - * corresponding matcher in the specified matchers. For a positive match, the examined array - * must be of the same length as the number of specified matchers. - * For example: - *
assertThat(new String[]{"foo", "bar"}, arrayContaining(equalTo("foo"), equalTo("bar")))
- * - * @param itemMatchers - * the matchers that must be satisfied by the items in the examined array - */ - @SafeVarargs - public static Matcher arrayContaining(Matcher... itemMatchers) { - //required for JDK 1.6 - //noinspection RedundantTypeArguments - final List> nullSafeWithExplicitTypeMatchers = NullSafety.nullSafe(itemMatchers); + /** + * Creates a matcher for arrays that matches when each item in the examined array satisfies the + * corresponding matcher in the specified matchers. For a positive match, the examined array + * must be of the same length as the number of specified matchers. + * For example: + *
assertThat(new String[]{"foo", "bar"}, arrayContaining(equalTo("foo"), equalTo("bar")))
+ * + * @param the matcher type + * @param itemMatchers + * the matchers that must be satisfied by the items in the examined array + * @return the created matcher + */ + @SafeVarargs + public static Matcher arrayContaining(Matcher... itemMatchers) { + //required for JDK 1.6 + //noinspection RedundantTypeArguments + final List> nullSafeWithExplicitTypeMatchers = NullSafety.nullSafe(itemMatchers); - return arrayContaining(nullSafeWithExplicitTypeMatchers); - } + return arrayContaining(nullSafeWithExplicitTypeMatchers); + } - /** - * Creates a matcher for arrays that matches when each item in the examined array satisfies the - * corresponding matcher in the specified list of matchers. For a positive match, the examined array - * must be of the same length as the specified list of matchers. - * For example: - *
assertThat(new String[]{"foo", "bar"}, arrayContaining(Arrays.asList(equalTo("foo"), equalTo("bar"))))
- * - * @param itemMatchers - * a list of matchers, each of which must be satisfied by the corresponding item in an examined array - */ - public static Matcher arrayContaining(List> itemMatchers) { - return new ArrayAsIterableMatcher<>(new IsIterableContainingInOrder<>(itemMatchers), itemMatchers, ""); - } + /** + * Creates a matcher for arrays that matches when each item in the examined array satisfies the + * corresponding matcher in the specified list of matchers. For a positive match, the examined array + * must be of the same length as the specified list of matchers. + * For example: + *
assertThat(new String[]{"foo", "bar"}, arrayContaining(Arrays.asList(equalTo("foo"), equalTo("bar"))))
+ * + * @param the matcher type + * @param itemMatchers + * a list of matchers, each of which must be satisfied by the corresponding item in an examined array + * @return the created matcher + */ + public static Matcher arrayContaining(List> itemMatchers) { + return new ArrayAsIterableMatcher<>(new IsIterableContainingInOrder<>(itemMatchers), itemMatchers, ""); + } - public static List> asEqualMatchers(E[] items) { - final List> matchers = new ArrayList<>(); - for (E item : items) { - matchers.add(equalTo(item)); + public static List> asEqualMatchers(E[] items) { + final List> matchers = new ArrayList<>(); + for (E item : items) { + matchers.add(equalTo(item)); + } + return matchers; } - return matchers; - } } diff --git a/hamcrest/src/main/java/org/hamcrest/collection/HasItemInArray.java b/hamcrest/src/main/java/org/hamcrest/collection/HasItemInArray.java index 5c0513c1..dcc56e82 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/HasItemInArray.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/HasItemInArray.java @@ -1,15 +1,46 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; +import static java.util.Arrays.asList; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; import org.hamcrest.TypeSafeMatcher; import org.hamcrest.core.IsIterableContaining; -import static java.util.Arrays.asList; - /** * Matches if an array contains an item satisfying a nested matcher. + * @param the matcher type */ public class HasItemInArray extends TypeSafeMatcher { private final Matcher elementMatcher; @@ -24,7 +55,7 @@ public HasItemInArray(Matcher elementMatcher) { public boolean matchesSafely(T[] actual) { return collectionMatcher.matches(asList(actual)); } - + @Override public void describeMismatchSafely(T[] actual, Description mismatchDescription) { collectionMatcher.describeMismatch(asList(actual), mismatchDescription); diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsArray.java b/hamcrest/src/main/java/org/hamcrest/collection/IsArray.java index 38f5d915..9204c5d4 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsArray.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsArray.java @@ -1,30 +1,65 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; +import java.util.Arrays; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; -import java.util.Arrays; - /** * Matcher for array whose elements satisfy a sequence of matchers. * The array size must equal the number of element matchers. + * @param the matcher type */ public class IsArray extends TypeSafeMatcher { private final Matcher[] elementMatchers; - + public IsArray(Matcher[] elementMatchers) { this.elementMatchers = elementMatchers.clone(); } - + @Override public boolean matchesSafely(T[] array) { - if (array.length != elementMatchers.length) return false; - + if (array.length != elementMatchers.length) { + return false; + } + for (int i = 0; i < array.length; i++) { - if (!elementMatchers[i].matches(array[i])) return false; + if (!elementMatchers[i].matches(array[i])) { + return false; + } } - + return true; } @@ -46,15 +81,18 @@ public void describeMismatchSafely(T[] actual, Description mismatchDescription) @Override @SuppressWarnings("unchecked") public void describeTo(Description description) { - description.appendList(descriptionStart(), descriptionSeparator(), descriptionEnd(), - Arrays.asList(elementMatchers)); + description.appendList(descriptionStart(), + descriptionSeparator(), + descriptionEnd(), + Arrays.asList(elementMatchers)); } - + /** * Returns the string that starts the description. - * + * * Can be overridden in subclasses to customise how the matcher is * described. + * @return the description start */ protected String descriptionStart() { return "["; @@ -62,9 +100,10 @@ protected String descriptionStart() { /** * Returns the string that separates the elements in the description. - * + * * Can be overridden in subclasses to customise how the matcher is * described. + * @return the description separator */ protected String descriptionSeparator() { return ", "; @@ -72,26 +111,28 @@ protected String descriptionSeparator() { /** * Returns the string that ends the description. - * + * * Can be overridden in subclasses to customise how the matcher is * described. + * @return the description end */ protected String descriptionEnd() { return "]"; } - + /** * Creates a matcher that matches arrays whose elements are satisfied by the specified matchers. Matches * positively only if the number of matchers specified is equal to the length of the examined array and * each matcher[i] is satisfied by array[i]. * For example: *
assertThat(new Integer[]{1,2,3}, is(array(equalTo(1), equalTo(2), equalTo(3))))
- * + * + * @param the matcher type * @param elementMatchers * the matchers that the elements of examined arrays should satisfy + * @return the created matcher */ public static IsArray array(Matcher... elementMatchers) { - return new IsArray(elementMatchers); + return new IsArray<>(elementMatchers); } - } diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsArrayContainingInAnyOrder.java b/hamcrest/src/main/java/org/hamcrest/collection/IsArrayContainingInAnyOrder.java index 7e72a622..f069f95f 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsArrayContainingInAnyOrder.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsArrayContainingInAnyOrder.java @@ -1,17 +1,47 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; - +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; import static org.hamcrest.core.IsEqual.equalTo; /** + * @param the matcher type * @deprecated As of release 2.1, replaced by {@link ArrayMatching}. */ @Deprecated @@ -28,11 +58,11 @@ public IsArrayContainingInAnyOrder(Collection> matchers) { public boolean matchesSafely(E[] item) { return iterableMatcher.matches(Arrays.asList(item)); } - + @Override public void describeMismatchSafely(E[] item, Description mismatchDescription) { - iterableMatcher.describeMismatch(Arrays.asList(item), mismatchDescription); - }; + iterableMatcher.describeMismatch(Arrays.asList(item), mismatchDescription); + } @Override public void describeTo(Description description) { @@ -53,10 +83,11 @@ public void describeTo(Description description) { * For example: *
assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(equalTo("bar"), equalTo("foo")))
* - * @deprecated As of version 2.1, use {@link ArrayMatching#arrayContainingInAnyOrder(Matcher[])}. - * * @param itemMatchers * a list of matchers, each of which must be satisfied by an entry in an examined array + * @param the matcher type + * @return the created matcher + * @deprecated As of version 2.1, use {@link ArrayMatching#arrayContainingInAnyOrder(Matcher[])}. */ public static Matcher arrayContainingInAnyOrder(Matcher... itemMatchers) { return arrayContainingInAnyOrder(Arrays.asList(itemMatchers)); @@ -75,10 +106,11 @@ public static Matcher arrayContainingInAnyOrder(Matcher... i * For example: *
assertThat(new String[]{"foo", "bar"}, arrayContainingInAnyOrder(Arrays.asList(equalTo("bar"), equalTo("foo"))))
* - * @deprecated As of version 2.1, use {@link ArrayMatching#arrayContainingInAnyOrder(Collection)}. - * * @param itemMatchers * a list of matchers, each of which must be satisfied by an item provided by an examined array + * @param the matcher type + * @return the created matcher + * @deprecated As of version 2.1, use {@link ArrayMatching#arrayContainingInAnyOrder(Collection)}. */ public static Matcher arrayContainingInAnyOrder(Collection> itemMatchers) { return new IsArrayContainingInAnyOrder(itemMatchers); @@ -97,16 +129,17 @@ public static Matcher arrayContainingInAnyOrder(CollectionassertThat(new String[]{"foo", "bar"}, containsInAnyOrder("bar", "foo")) * - * @deprecated As of version 2.1, use {@link ArrayMatching#arrayContainingInAnyOrder(Object[])}. - * * @param items * the items that must equal the entries of an examined array, in any order + * @param the matcher type + * @return the created matcher + * @deprecated As of version 2.1, use {@link ArrayMatching#arrayContainingInAnyOrder(Object[])}. */ public static Matcher arrayContainingInAnyOrder(E... items) { - List> matchers = new ArrayList>(); - for (E item : items) { - matchers.add(equalTo(item)); - } - return new IsArrayContainingInAnyOrder(matchers); + List> matchers = new ArrayList>(); + for (E item : items) { + matchers.add(equalTo(item)); + } + return new IsArrayContainingInAnyOrder(matchers); } } diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsArrayContainingInOrder.java b/hamcrest/src/main/java/org/hamcrest/collection/IsArrayContainingInOrder.java index c046914f..27cf4f85 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsArrayContainingInOrder.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsArrayContainingInOrder.java @@ -1,17 +1,47 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; - import java.util.ArrayList; +import static java.util.Arrays.asList; import java.util.Collection; import java.util.List; - -import static java.util.Arrays.asList; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; import static org.hamcrest.core.IsEqual.equalTo; /** + * @param the matcher type * @deprecated As of release 2.1, replaced by {@link ArrayMatching}. */ public class IsArrayContainingInOrder extends TypeSafeMatcher { @@ -27,10 +57,10 @@ public IsArrayContainingInOrder(List> matchers) { public boolean matchesSafely(E[] item) { return iterableMatcher.matches(asList(item)); } - + @Override public void describeMismatchSafely(E[] item, Description mismatchDescription) { - iterableMatcher.describeMismatch(asList(item), mismatchDescription); + iterableMatcher.describeMismatch(asList(item), mismatchDescription); } @Override @@ -46,10 +76,11 @@ public void describeTo(Description description) { * For example: *
assertThat(new String[]{"foo", "bar"}, contains("foo", "bar"))
* - * @deprecated As of version 2.1, use {@link ArrayMatching#arrayContaining(Object[])}. - * * @param items * the items that must equal the items within an examined array + * @param the matcher type + * @return the created matcher + * @deprecated As of version 2.1, use {@link ArrayMatching#arrayContaining(Object[])}. */ public static Matcher arrayContaining(E... items) { List> matchers = new ArrayList>(); @@ -67,10 +98,11 @@ public static Matcher arrayContaining(E... items) { * For example: *
assertThat(new String[]{"foo", "bar"}, contains(equalTo("foo"), equalTo("bar")))
* - * @deprecated As of version 2.1, use {@link ArrayMatching#arrayContaining(Matcher[])}. - * * @param itemMatchers * the matchers that must be satisfied by the items in the examined array + * @param the matcher type + * @return the created matcher + * @deprecated As of version 2.1, use {@link ArrayMatching#arrayContaining(Matcher[])}. */ public static Matcher arrayContaining(Matcher... itemMatchers) { return arrayContaining(asList(itemMatchers)); @@ -84,10 +116,11 @@ public static Matcher arrayContaining(Matcher... itemMatcher * For example: *
assertThat(new String[]{"foo", "bar"}, contains(Arrays.asList(equalTo("foo"), equalTo("bar"))))
* - * @deprecated As of version 2.1, use {@link ArrayMatching#arrayContaining(List)}. - * * @param itemMatchers * a list of matchers, each of which must be satisfied by the corresponding item in an examined array + * @param the matcher type + * @return the created matcher + * @deprecated As of version 2.1, use {@link ArrayMatching#arrayContaining(List)}. */ public static Matcher arrayContaining(List> itemMatchers) { return new IsArrayContainingInOrder(itemMatchers); diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsArrayWithSize.java b/hamcrest/src/main/java/org/hamcrest/collection/IsArrayWithSize.java index 4ae7235e..758edc3a 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsArrayWithSize.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsArrayWithSize.java @@ -1,22 +1,54 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; import org.hamcrest.FeatureMatcher; import org.hamcrest.Matcher; - import static org.hamcrest.core.DescribedAs.describedAs; import static org.hamcrest.core.IsEqual.equalTo; /** * Matches if array size satisfies a nested matcher. + * @param the matcher type */ public class IsArrayWithSize extends FeatureMatcher { + public IsArrayWithSize(Matcher sizeMatcher) { super(sizeMatcher, "an array with size","array size"); } @Override protected Integer featureValueOf(E[] actual) { - return actual.length; + return actual.length; } /** @@ -24,9 +56,11 @@ protected Integer featureValueOf(E[] actual) { * satisfies the specified matcher. * For example: *
assertThat(new String[]{"foo", "bar"}, arrayWithSize(equalTo(2)))
- * + * + * @param the matcher type * @param sizeMatcher * a matcher for the length of an examined array + * @return the created matcher */ public static Matcher arrayWithSize(Matcher sizeMatcher) { return new IsArrayWithSize<>(sizeMatcher); @@ -37,11 +71,13 @@ public static Matcher arrayWithSize(Matcher sizeMatche * equals the specified size. * For example: *
assertThat(new String[]{"foo", "bar"}, arrayWithSize(2))
- * + * + * @param the matcher type * @param size * the length that an examined array must have for a positive match + * @return the created matcher */ - public static Matcher arrayWithSize(int size) { + public static Matcher arrayWithSize(int size) { return arrayWithSize(equalTo(size)); } @@ -50,9 +86,11 @@ public static Matcher arrayWithSize(int size) { * is zero. * For example: *
assertThat(new String[0], emptyArray())
- * + * + * @param the matcher type + * @return the created matcher */ - public static Matcher emptyArray() { - return describedAs("an empty array", IsArrayWithSize.arrayWithSize(0)); + public static Matcher emptyArray() { + return describedAs("an empty array", IsArrayWithSize.arrayWithSize(0)); } } diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsCollectionWithSize.java b/hamcrest/src/main/java/org/hamcrest/collection/IsCollectionWithSize.java index f12f57c4..d912ee2a 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsCollectionWithSize.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsCollectionWithSize.java @@ -1,23 +1,54 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; +import java.util.Collection; import org.hamcrest.FeatureMatcher; import org.hamcrest.Matcher; - -import java.util.Collection; - import static org.hamcrest.core.IsEqual.equalTo; /** * Matches if collection size satisfies a nested matcher. + * @param the matcher type */ public class IsCollectionWithSize extends FeatureMatcher, Integer> { + public IsCollectionWithSize(Matcher sizeMatcher) { - super(sizeMatcher, "a collection with size", "collection size"); + super(sizeMatcher, "a collection with size", "collection size"); } @Override protected Integer featureValueOf(Collection actual) { - return actual.size(); + return actual.size(); } /** @@ -25,12 +56,14 @@ protected Integer featureValueOf(Collection actual) { * a value that satisfies the specified matcher. * For example: *
assertThat(Arrays.asList("foo", "bar"), hasSize(equalTo(2)))
- * + * + * @param the matcher type * @param sizeMatcher * a matcher for the size of an examined {@link java.util.Collection} + * @return the created matcher */ public static Matcher> hasSize(Matcher sizeMatcher) { - return new IsCollectionWithSize(sizeMatcher); + return new IsCollectionWithSize<>(sizeMatcher); } /** @@ -38,13 +71,14 @@ public static Matcher> hasSize(Matchersize. * For example: *
assertThat(Arrays.asList("foo", "bar"), hasSize(2))
- * + * + * @param the matcher type * @param size * the expected size of an examined {@link java.util.Collection} + * @return the createdd matcher */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static Matcher> hasSize(int size) { - return (Matcher)IsCollectionWithSize.hasSize(equalTo(size)); + return (Matcher)IsCollectionWithSize.hasSize(equalTo(size)); } - } diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsEmptyCollection.java b/hamcrest/src/main/java/org/hamcrest/collection/IsEmptyCollection.java index 481b08c3..da00d83f 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsEmptyCollection.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsEmptyCollection.java @@ -1,13 +1,44 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; +import java.util.Collection; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; -import java.util.Collection; - /** * Tests if collection is empty. + * @param the matcher type */ public class IsEmptyCollection extends TypeSafeMatcher> { @@ -18,7 +49,7 @@ public boolean matchesSafely(Collection item) { @Override public void describeMismatchSafely(Collection item, Description mismatchDescription) { - mismatchDescription.appendValue(item); + mismatchDescription.appendValue(item); } @Override @@ -31,10 +62,12 @@ public void describeTo(Description description) { * method returns true. * For example: *
assertThat(new ArrayList<String>(), is(empty()))
- * + * + * @param the matcher type + * @return the created matcher */ - public static Matcher> empty() { - return new IsEmptyCollection(); + public static Matcher> empty() { + return new IsEmptyCollection<>(); } /** @@ -42,12 +75,14 @@ public static Matcher> empty() { * method returns true. * For example: *
assertThat(new ArrayList<String>(), is(emptyCollectionOf(String.class)))
- * + * + * @param the matcher type * @param unusedToForceReturnType * the type of the collection's content + * @return the created matcher */ @SuppressWarnings({"unchecked", "UnusedParameters"}) - public static Matcher> emptyCollectionOf(Class unusedToForceReturnType) { - return (Matcher)empty(); + public static Matcher> emptyCollectionOf(Class unusedToForceReturnType) { + return (Matcher)empty(); } } diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsEmptyIterable.java b/hamcrest/src/main/java/org/hamcrest/collection/IsEmptyIterable.java index 047e670c..fad45e3b 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsEmptyIterable.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsEmptyIterable.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; import org.hamcrest.Description; @@ -6,6 +37,7 @@ /** * Tests if collection is empty. + * @param the matcher type */ public class IsEmptyIterable extends TypeSafeMatcher> { @@ -27,22 +59,26 @@ public void describeTo(Description description) { * Creates a matcher for {@link Iterable}s matching examined iterables that yield no items. * For example: *
assertThat(new ArrayList<String>(), is(emptyIterable()))
- * + * + * @param the matcher type + * @return the created matcher */ - public static Matcher> emptyIterable() { - return new IsEmptyIterable(); + public static Matcher> emptyIterable() { + return new IsEmptyIterable<>(); } /** * Creates a matcher for {@link Iterable}s matching examined iterables that yield no items. * For example: *
assertThat(new ArrayList<String>(), is(emptyIterableOf(String.class)))
- * + * + * @param the matcher type * @param unusedToForceReturnType * the type of the iterable's content + * @return the created matcher */ @SuppressWarnings({"unchecked", "UnusedParameters"}) - public static Matcher> emptyIterableOf(Class unusedToForceReturnType) { - return (Matcher)emptyIterable(); + public static Matcher> emptyIterableOf(Class unusedToForceReturnType) { + return (Matcher)emptyIterable(); } } diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsIn.java b/hamcrest/src/main/java/org/hamcrest/collection/IsIn.java index 84098110..bd997484 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsIn.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsIn.java @@ -1,23 +1,57 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; +import java.util.Arrays; +import java.util.Collection; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; -import java.util.Arrays; -import java.util.Collection; - +/** + * A matcher testing that items are contained in a collection. + * @param the matcher type + */ public class IsIn extends BaseMatcher { private final Collection collection; public IsIn(Collection collection) { this.collection = collection; } - + public IsIn(T[] elements) { collection = Arrays.asList(elements); } - + @SuppressWarnings("SuspiciousMethodCalls") @Override public boolean matches(Object o) { @@ -29,33 +63,34 @@ public void describeTo(Description buffer) { buffer.appendText("one of "); buffer.appendValueList("{", ", ", "}", collection); } - + /** * Creates a matcher that matches when the examined object is found within the * specified collection. * For example: *
assertThat("foo", isIn(Arrays.asList("bar", "foo")))
- * + * + * @param the matcher type * @deprecated use is(in(...)) instead - * * @param collection * the collection in which matching items must be found - * + * @return the created matcher */ @Deprecated public static Matcher isIn(Collection collection) { return in(collection); } - + /** * Creates a matcher that matches when the examined object is found within the * specified collection. * For example: *
assertThat("foo", is(in(Arrays.asList("bar", "foo"))))
- * + * + * @param the matcher type * @param collection * the collection in which matching items must be found - * + * @return the created matcher */ public static Matcher in(Collection collection) { return new IsIn<>(collection); @@ -66,59 +101,61 @@ public static Matcher in(Collection collection) { * specified array. * For example: *
assertThat("foo", isIn(new String[]{"bar", "foo"}))
- * - * @deprecated use is(in(...)) instead - * + * + * @param the matcher type * @param elements * the array in which matching items must be found - * + * @return the created matcher + * @deprecated use is(in(...)) instead */ @Deprecated public static Matcher isIn(T[] elements) { return in(elements); } - + /** * Creates a matcher that matches when the examined object is found within the * specified array. * For example: *
assertThat("foo", is(in(new String[]{"bar", "foo"})))
- * + * + * @param the matcher type * @param elements * the array in which matching items must be found - * + * @return the created matcher */ public static Matcher in(T[] elements) { return new IsIn<>(elements); } - + /** * Creates a matcher that matches when the examined object is equal to one of the * specified elements. * For example: *
assertThat("foo", isOneOf("bar", "foo"))
- * + * + * @param the matcher type * @deprecated use is(oneOf(...)) instead - * * @param elements - * the elements amongst which matching items will be found - * + * the elements amongst which matching items will be found + * @return the created matcher */ @SafeVarargs @Deprecated public static Matcher isOneOf(T... elements) { return oneOf(elements); } - + /** * Creates a matcher that matches when the examined object is equal to one of the * specified elements. * For example: *
assertThat("foo", is(oneOf("bar", "foo")))
- * + * + * @param the matcher type * @param elements - * the elements amongst which matching items will be found - * + * the elements amongst which matching items will be found + * @return the created matcher */ @SafeVarargs public static Matcher oneOf(T... elements) { diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInAnyOrder.java b/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInAnyOrder.java index d6a9a33d..02ffc7e9 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInAnyOrder.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInAnyOrder.java @@ -1,79 +1,112 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeDiagnosingMatcher; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; - +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeDiagnosingMatcher; import static org.hamcrest.core.IsEqual.equalTo; +/** + * A matcher testing that items are contained in a collection in order. + * @param the matcher type + */ public class IsIterableContainingInAnyOrder extends TypeSafeDiagnosingMatcher> { private final Collection> matchers; public IsIterableContainingInAnyOrder(Collection> matchers) { this.matchers = matchers; } - + @Override protected boolean matchesSafely(Iterable items, Description mismatchDescription) { - final Matching matching = new Matching<>(matchers, mismatchDescription); - for (T item : items) { - if (! matching.matches(item)) { - return false; + final Matching matching = new Matching<>(matchers, mismatchDescription); + for (T item : items) { + if (! matching.matches(item)) { + return false; + } } - } - - return matching.isFinished(items); + + return matching.isFinished(items); } - + @Override public void describeTo(Description description) { - description.appendText("iterable with items ") - .appendList("[", ", ", "]", matchers) - .appendText(" in any order"); + description.appendText("iterable with items ") + .appendList("[", ", ", "]", matchers) + .appendText(" in any order"); } private static class Matching { - private final Collection> matchers; - private final Description mismatchDescription; - - public Matching(Collection> matchers, Description mismatchDescription) { - this.matchers = new ArrayList<>(matchers); - this.mismatchDescription = mismatchDescription; - } - - public boolean matches(S item) { - if (matchers.isEmpty()) { - mismatchDescription.appendText("no match for: ").appendValue(item); - return false; + private final Collection> matchers; + private final Description mismatchDescription; + + public Matching(Collection> matchers, Description mismatchDescription) { + this.matchers = new ArrayList<>(matchers); + this.mismatchDescription = mismatchDescription; } - return isMatched(item); - } - public boolean isFinished(Iterable items) { - if (matchers.isEmpty()) { - return true; + public boolean matches(S item) { + if (matchers.isEmpty()) { + mismatchDescription.appendText("no match for: ").appendValue(item); + return false; + } + return isMatched(item); } - mismatchDescription - .appendText("no item matches: ").appendList("", ", ", "", matchers) - .appendText(" in ").appendValueList("[", ", ", "]", items); - return false; - } - - private boolean isMatched(S item) { - for (Matcher matcher : matchers) { - if (matcher.matches(item)) { - matchers.remove(matcher); - return true; - } + + public boolean isFinished(Iterable items) { + if (matchers.isEmpty()) { + return true; + } + mismatchDescription + .appendText("no item matches: ").appendList("", ", ", "", matchers) + .appendText(" in ").appendValueList("[", ", ", "]", items); + return false; + } + + private boolean isMatched(S item) { + for (Matcher matcher : matchers) { + if (matcher.matches(item)) { + matchers.remove(matcher); + return true; + } + } + mismatchDescription.appendText("not matched: ").appendValue(item); + return false; } - mismatchDescription.appendText("not matched: ").appendValue(item); - return false; - } } /** @@ -92,9 +125,11 @@ private boolean isMatched(S item) { * For example: *

*
assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder(equalTo("bar"), equalTo("foo")))
- * + * + * @param the matcher type * @param itemMatchers * a list of matchers, each of which must be satisfied by an item provided by an examined {@link Iterable} + * @return the created matcher */ @SafeVarargs public static Matcher> containsInAnyOrder(Matcher... itemMatchers) { @@ -117,9 +152,11 @@ public static Matcher> containsInAnyOrder(Matcher *
assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder("bar", "foo"))
- * + * + * @param the matcher type * @param items * the items that must equal the items provided by an examined {@link Iterable} in any order + * @return the created matcher */ @SafeVarargs public static Matcher> containsInAnyOrder(T... items) { @@ -127,7 +164,7 @@ public static Matcher> containsInAnyOrder(T... items) for (T item : items) { matchers.add(equalTo(item)); } - + return new IsIterableContainingInAnyOrder<>(matchers); } @@ -145,9 +182,11 @@ public static Matcher> containsInAnyOrder(T... items) *

*

For example:

*
assertThat(Arrays.asList("foo", "bar"), containsInAnyOrder(Arrays.asList(equalTo("bar"), equalTo("foo"))))
- * + * + * @param the matcher type * @param itemMatchers * a list of matchers, each of which must be satisfied by an item provided by an examined {@link Iterable} + * @return the created matcher */ public static Matcher> containsInAnyOrder(Collection> itemMatchers) { return new IsIterableContainingInAnyOrder<>(itemMatchers); diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.java b/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.java index 221bd47b..9621d196 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInOrder.java @@ -1,27 +1,60 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; +import java.util.ArrayList; +import static java.util.Collections.singletonList; +import java.util.List; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; -import org.hamcrest.internal.NullSafety; - -import java.util.ArrayList; -import java.util.List; - -import static java.util.Collections.singletonList; import static org.hamcrest.collection.ArrayMatching.asEqualMatchers; +import org.hamcrest.internal.NullSafety; -public class IsIterableContainingInOrder extends TypeSafeDiagnosingMatcher> { - private final List> matchers; +/** + * A matcher testing that items are contained in a collection. + * @param the matcher type + */ +public class IsIterableContainingInOrder extends TypeSafeDiagnosingMatcher> { + private final List> matchers; - public IsIterableContainingInOrder(List> matchers) { + public IsIterableContainingInOrder(List> matchers) { this.matchers = matchers; } @Override - protected boolean matchesSafely(Iterable iterable, Description mismatchDescription) { - final MatchSeries matchSeries = new MatchSeries<>(matchers, mismatchDescription); - for (E item : iterable) { + protected boolean matchesSafely(Iterable iterable, Description mismatchDescription) { + final MatchSeries matchSeries = new MatchSeries<>(matchers, mismatchDescription); + for (T item : iterable) { if (!matchSeries.matches(item)) { return false; } @@ -49,12 +82,12 @@ public MatchSeries(List> matchers, Description mismatchDescri } public boolean matches(F item) { - if (matchers.size() <= nextMatchIx) { - mismatchDescription.appendText("not matched: ").appendValue(item); - return false; - } + if (matchers.size() <= nextMatchIx) { + mismatchDescription.appendText("not matched: ").appendValue(item); + return false; + } - return isMatched(item); + return isMatched(item); } public boolean isFinished() { @@ -75,7 +108,7 @@ private boolean isMatched(F item) { return true; } - private void describeMismatch(Matcher matcher, F item) { + private void describeMismatch(Matcher matcher, F item) { mismatchDescription.appendText("item " + nextMatchIx + ": "); matcher.describeMismatch(item, mismatchDescription); } @@ -88,12 +121,14 @@ private void describeMismatch(Matcher matcher, F item) { * must be of the same length as the number of specified items. * For example: *
assertThat(Arrays.asList("foo", "bar"), contains("foo", "bar"))
- * + * + * @param the matcher type * @param items * the items that must equal the items provided by an examined {@link Iterable} + * @return the created matcher */ @SafeVarargs - public static Matcher> contains(E... items) { + public static Matcher> contains(T... items) { return contains(asEqualMatchers(items)); } @@ -103,14 +138,16 @@ public static Matcher> contains(E... items) { * For a positive match, the examined iterable must only yield one item. * For example: *
assertThat(Arrays.asList("foo"), contains(equalTo("foo")))
- * + * + * @param the matcher type * @param itemMatcher * the matcher that must be satisfied by the single item provided by an * examined {@link Iterable} + * @return the created matcher */ @SuppressWarnings("unchecked") - public static Matcher> contains(final Matcher itemMatcher) { - return contains(new ArrayList>(singletonList(itemMatcher))); + public static Matcher> contains(final Matcher itemMatcher) { + return contains(new ArrayList>(singletonList(itemMatcher))); } /** @@ -120,16 +157,18 @@ public static Matcher> contains(final MatcherassertThat(Arrays.asList("foo", "bar"), contains(equalTo("foo"), equalTo("bar"))) - * + * + * @param the matcher type * @param itemMatchers * the matchers that must be satisfied by the items provided by an examined {@link Iterable} + * @return the created matcher */ @SafeVarargs - public static Matcher> contains(Matcher... itemMatchers) { + public static Matcher> contains(Matcher... itemMatchers) { // required for JDK 1.6 //noinspection RedundantTypeArguments - final List> nullSafeWithExplicitTypeMatchers = NullSafety.nullSafe(itemMatchers); - return contains(nullSafeWithExplicitTypeMatchers); + final List> nullSafeWithExplicitTypeMatchers = NullSafety.nullSafe(itemMatchers); + return contains(nullSafeWithExplicitTypeMatchers); } /** @@ -139,12 +178,14 @@ public static Matcher> contains(Matcher... * must be of the same length as the specified list of matchers. * For example: *
assertThat(Arrays.asList("foo", "bar"), contains(Arrays.asList(equalTo("foo"), equalTo("bar"))))
- * + * + * @param the matcher type * @param itemMatchers * a list of matchers, each of which must be satisfied by the corresponding item provided by * an examined {@link Iterable} + * @return the created matcher */ - public static Matcher> contains(List> itemMatchers) { + public static Matcher> contains(List> itemMatchers) { return new IsIterableContainingInOrder<>(itemMatchers); } } diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInRelativeOrder.java b/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInRelativeOrder.java index 06577685..cca45ac5 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInRelativeOrder.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsIterableContainingInRelativeOrder.java @@ -1,25 +1,58 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; +import java.util.ArrayList; +import static java.util.Arrays.asList; +import java.util.List; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; - -import java.util.ArrayList; -import java.util.List; - -import static java.util.Arrays.asList; import static org.hamcrest.core.IsEqual.equalTo; -public class IsIterableContainingInRelativeOrder extends TypeSafeDiagnosingMatcher> { - private final List> matchers; +/** + * A matcher testing that items are contained in a collection in relative order. + * @param the matcher type + */ +public class IsIterableContainingInRelativeOrder extends TypeSafeDiagnosingMatcher> { + private final List> matchers; - public IsIterableContainingInRelativeOrder(List> matchers) { + public IsIterableContainingInRelativeOrder(List> matchers) { this.matchers = matchers; } @Override - protected boolean matchesSafely(Iterable iterable, Description mismatchDescription) { - MatchSeriesInRelativeOrder matchSeriesInRelativeOrder = new MatchSeriesInRelativeOrder<>(matchers, mismatchDescription); + protected boolean matchesSafely(Iterable iterable, Description mismatchDescription) { + MatchSeriesInRelativeOrder matchSeriesInRelativeOrder = new MatchSeriesInRelativeOrder<>(matchers, mismatchDescription); matchSeriesInRelativeOrder.processItems(iterable); return matchSeriesInRelativeOrder.isFinished(); } @@ -73,14 +106,16 @@ public boolean isFinished() { * corresponding item in the specified items, in the same relative order * For example: *
assertThat(Arrays.asList("a", "b", "c", "d", "e"), containsInRelativeOrder("b", "d"))
- * + * + * @param the matcher type * @param items * the items that must be contained within items provided by an examined {@link Iterable} in the same relative order + * @return the created matcher */ @SafeVarargs - public static Matcher> containsInRelativeOrder(E... items) { - List> matchers = new ArrayList<>(); - for (E item : items) { + public static Matcher> containsInRelativeOrder(T... items) { + List> matchers = new ArrayList<>(); + for (T item : items) { matchers.add(equalTo(item)); } @@ -93,12 +128,14 @@ public static Matcher> containsInRelativeOrder(E... it * matcher in the specified matchers, in the same relative order. * For example: *
assertThat(Arrays.asList("a", "b", "c", "d", "e"), containsInRelativeOrder(equalTo("b"), equalTo("d")))
- * + * + * @param the matcher type * @param itemMatchers * the matchers that must be satisfied by the items provided by an examined {@link Iterable} in the same relative order + * @return the created matcher */ @SafeVarargs - public static Matcher> containsInRelativeOrder(Matcher... itemMatchers) { + public static Matcher> containsInRelativeOrder(Matcher... itemMatchers) { return containsInRelativeOrder(asList(itemMatchers)); } @@ -108,12 +145,14 @@ public static Matcher> containsInRelativeOrder(Matcher * matcher in the specified list of matchers, in the same relative order. * For example: *
assertThat(Arrays.asList("a", "b", "c", "d", "e"), contains(Arrays.asList(equalTo("b"), equalTo("d"))))
- * + * + * @param the matcher type * @param itemMatchers * a list of matchers, each of which must be satisfied by the items provided by * an examined {@link Iterable} in the same relative order + * @return the created matcher */ - public static Matcher> containsInRelativeOrder(List> itemMatchers) { + public static Matcher> containsInRelativeOrder(List> itemMatchers) { return new IsIterableContainingInRelativeOrder<>(itemMatchers); } } diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsIterableWithSize.java b/hamcrest/src/main/java/org/hamcrest/collection/IsIterableWithSize.java index 0a1535fe..75db06e3 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsIterableWithSize.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsIterableWithSize.java @@ -1,26 +1,58 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; +import java.util.Iterator; import org.hamcrest.FeatureMatcher; import org.hamcrest.Matcher; - -import java.util.Iterator; - import static org.hamcrest.core.IsEqual.equalTo; +/** + * A matcher to check the size of an {@link Iterable}. + * @param the matcher type + */ public class IsIterableWithSize extends FeatureMatcher, Integer> { public IsIterableWithSize(Matcher sizeMatcher) { super(sizeMatcher, "an iterable with size", "iterable size"); } - @Override protected Integer featureValueOf(Iterable actual) { - int size = 0; - for (Iterator iterator = actual.iterator(); iterator.hasNext(); iterator.next()) { - size++; - } - return size; + int size = 0; + for (Iterator iterator = actual.iterator(); iterator.hasNext(); iterator.next()) { + size++; + } + return size; } /** @@ -29,12 +61,14 @@ protected Integer featureValueOf(Iterable actual) { * matcher. * For example: *
assertThat(Arrays.asList("foo", "bar"), iterableWithSize(equalTo(2)))
- * + * + * @param the matcher type * @param sizeMatcher * a matcher for the number of items that should be yielded by an examined {@link Iterable} + * @return the created matcher */ - public static Matcher> iterableWithSize(Matcher sizeMatcher) { - return new IsIterableWithSize(sizeMatcher); + public static Matcher> iterableWithSize(Matcher sizeMatcher) { + return new IsIterableWithSize<>(sizeMatcher); } /** @@ -43,11 +77,13 @@ public static Matcher> iterableWithSize(Matcher * size argument. * For example: *
assertThat(Arrays.asList("foo", "bar"), iterableWithSize(2))
- * + * + * @param the matcher type * @param size * the number of items that should be yielded by an examined {@link Iterable} + * @return the created matcher */ - public static Matcher> iterableWithSize(int size) { + public static Matcher> iterableWithSize(int size) { return iterableWithSize(equalTo(size)); } } diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsMapContaining.java b/hamcrest/src/main/java/org/hamcrest/collection/IsMapContaining.java index 4ed45392..7f0c377e 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsMapContaining.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsMapContaining.java @@ -1,15 +1,48 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; +import java.util.Map; +import java.util.Map.Entry; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; - -import java.util.Map; -import java.util.Map.Entry; - import static org.hamcrest.core.IsAnything.anything; import static org.hamcrest.core.IsEqual.equalTo; - +/** + * A matcher testing that items are contained in a map. + * @param the map key type + * @param the map value type + */ public class IsMapContaining extends TypeSafeMatcher> { private final Matcher keyMatcher; private final Matcher valueMatcher; @@ -31,16 +64,16 @@ public boolean matchesSafely(Map map) { @Override public void describeMismatchSafely(Map map, Description mismatchDescription) { - mismatchDescription.appendText("map was ").appendValueList("[", ", ", "]", map.entrySet()); + mismatchDescription.appendText("map was ").appendValueList("[", ", ", "]", map.entrySet()); } @Override public void describeTo(Description description) { description.appendText("map containing [") - .appendDescriptionOf(keyMatcher) - .appendText("->") - .appendDescriptionOf(valueMatcher) - .appendText("]"); + .appendDescriptionOf(keyMatcher) + .appendText("->") + .appendDescriptionOf(valueMatcher) + .appendText("]"); } /** @@ -49,11 +82,14 @@ public void describeTo(Description description) { * value satisfies the specified valueMatcher. * For example: *
assertThat(myMap, hasEntry(equalTo("bar"), equalTo("foo")))
- * + * + * @param the map key type + * @param the map value type * @param keyMatcher * the key matcher that, in combination with the valueMatcher, must be satisfied by at least one entry * @param valueMatcher * the value matcher that, in combination with the keyMatcher, must be satisfied by at least one entry + * @return the created matcher */ public static Matcher> hasEntry(Matcher keyMatcher, Matcher valueMatcher) { return new IsMapContaining<>(keyMatcher, valueMatcher); @@ -65,24 +101,29 @@ public static Matcher> hasEntry(Matchervalue. * For example: *
assertThat(myMap, hasEntry("bar", "foo"))
- * + * + * @param the map key type + * @param the map value type * @param key * the key that, in combination with the value, must be describe at least one entry * @param value * the value that, in combination with the key, must be describe at least one entry + * @return the created matcher */ public static Matcher> hasEntry(K key, V value) { return new IsMapContaining<>(equalTo(key), equalTo(value)); } - + /** * Creates a matcher for {@link java.util.Map}s matching when the examined {@link java.util.Map} contains * at least one key that satisfies the specified matcher. * For example: *
assertThat(myMap, hasKey(equalTo("bar")))
- * + * + * @param the map key type * @param keyMatcher * the matcher that must be satisfied by at least one key + * @return the created matcher */ public static Matcher> hasKey(Matcher keyMatcher) { return new IsMapContaining<>(keyMatcher, anything()); @@ -93,9 +134,11 @@ public static Matcher> hasEntry(K key, V valu * at least one key that is equal to the specified key. * For example: *
assertThat(myMap, hasKey("bar"))
- * + * + * @param the map key type * @param key * the key that satisfying maps must contain + * @return the created matcher */ public static Matcher> hasKey(K key) { return new IsMapContaining<>(equalTo(key), anything()); @@ -106,9 +149,11 @@ public static Matcher> hasEntry(K key, V valu * at least one value that satisfies the specified valueMatcher. * For example: *
assertThat(myMap, hasValue(equalTo("foo")))
- * + * + * @param the map value type * @param valueMatcher * the matcher that must be satisfied by at least one value + * @return the created matcher */ public static Matcher> hasValue(Matcher valueMatcher) { return new IsMapContaining<>(anything(), valueMatcher); @@ -119,9 +164,11 @@ public static Matcher> hasEntry(K key, V valu * at least one value that is equal to the specified value. * For example: *
assertThat(myMap, hasValue("foo"))
- * + * + * @param the map value type * @param value * the value that satisfying maps must contain + * @return the created matcher */ public static Matcher> hasValue(V value) { return new IsMapContaining<>(anything(), equalTo(value)); diff --git a/hamcrest/src/main/java/org/hamcrest/collection/IsMapWithSize.java b/hamcrest/src/main/java/org/hamcrest/collection/IsMapWithSize.java index 966d9ca2..ee4c3d46 100644 --- a/hamcrest/src/main/java/org/hamcrest/collection/IsMapWithSize.java +++ b/hamcrest/src/main/java/org/hamcrest/collection/IsMapWithSize.java @@ -1,24 +1,55 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; +import java.util.Map; import org.hamcrest.FeatureMatcher; import org.hamcrest.Matcher; - -import java.util.Map; - import static org.hamcrest.core.IsEqual.equalTo; /** * Matches if map size satisfies a nested matcher. + * @param the map key type + * @param the map value type */ public final class IsMapWithSize extends FeatureMatcher, Integer> { @SuppressWarnings("WeakerAccess") public IsMapWithSize(Matcher sizeMatcher) { - super(sizeMatcher, "a map with size", "map size"); + super(sizeMatcher, "a map with size", "map size"); } @Override protected Integer featureValueOf(Map actual) { - return actual.size(); + return actual.size(); } /** @@ -26,9 +57,12 @@ protected Integer featureValueOf(Map actual) { * a value that satisfies the specified matcher. * For example: *
assertThat(myMap, is(aMapWithSize(equalTo(2))))
- * + * + * @param the map key type + * @param the map value type * @param sizeMatcher * a matcher for the size of an examined {@link java.util.Map} + * @return the created matcher */ public static Matcher> aMapWithSize(Matcher sizeMatcher) { return new IsMapWithSize<>(sizeMatcher); @@ -39,20 +73,26 @@ protected Integer featureValueOf(Map actual) { * a value equal to the specified size. * For example: *
assertThat(myMap, is(aMapWithSize(2)))
- * + * + * @param the map key type + * @param the map value type * @param size * the expected size of an examined {@link java.util.Map} + * @return the created matcher */ public static Matcher> aMapWithSize(int size) { return IsMapWithSize.aMapWithSize(equalTo(size)); } - + /** * Creates a matcher for {@link java.util.Map}s that matches when the size() method returns * zero. * For example: *
assertThat(myMap, is(anEmptyMap()))
- * + * + * @param the map key type + * @param the map value type + * @return the created matcher */ public static Matcher> anEmptyMap() { return IsMapWithSize.aMapWithSize(equalTo(0)); diff --git a/hamcrest/src/main/java/org/hamcrest/comparator/ComparatorMatcherBuilder.java b/hamcrest/src/main/java/org/hamcrest/comparator/ComparatorMatcherBuilder.java index cf522113..3001c668 100644 --- a/hamcrest/src/main/java/org/hamcrest/comparator/ComparatorMatcherBuilder.java +++ b/hamcrest/src/main/java/org/hamcrest/comparator/ComparatorMatcherBuilder.java @@ -1,13 +1,46 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.comparator; +import static java.lang.Integer.signum; +import java.util.Comparator; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; -import java.util.Comparator; - -import static java.lang.Integer.signum; - +/** + * A builder for comparator matchers. + * @param the matcher type + */ public final class ComparatorMatcherBuilder { private final Comparator comparator; @@ -17,14 +50,17 @@ public final class ComparatorMatcherBuilder { * Creates a matcher factory for matchers of {@code Comparable}s. * For example: *
assertThat(1, ComparatorMatcherBuilder.<Integer>usingNaturalOrdering().lessThanOrEqualTo(1))
+ * @param the matcher type + * @return the created matcher */ public static > ComparatorMatcherBuilder usingNaturalOrdering() { - return new ComparatorMatcherBuilder(new Comparator() { + return new ComparatorMatcherBuilder<>(new Comparator() { @Override public int compare(T o1, T o2) { return o1.compareTo(o2); } - }, false); + }, + false); } /** @@ -35,9 +71,12 @@ public int compare(T o1, T o2) { * return -o1.compareTo(o2); * } * }).lessThan(4)) + * @param the matcher type + * @param comparator the comparator to use + * @return the created matcher */ public static ComparatorMatcherBuilder comparedBy(Comparator comparator) { - return new ComparatorMatcherBuilder(comparator, true); + return new ComparatorMatcherBuilder<>(comparator, true); } private ComparatorMatcherBuilder(Comparator comparator, boolean includeComparatorInDescription) { @@ -45,6 +84,10 @@ private ComparatorMatcherBuilder(Comparator comparator, boolean includeCompar this.includeComparatorInDescription = includeComparatorInDescription; } + /** + * A comparator matcher implementation. + * @param the matcher type + */ private static final class ComparatorMatcher extends TypeSafeMatcher { private static final int LESS_THAN = -1; private static final int GREATER_THAN = 1; @@ -56,10 +99,10 @@ private static final class ComparatorMatcher extends TypeSafeMatcher { private final int maxCompare; private final boolean includeComparatorInDescription; - private static final String[] comparisonDescriptions = { - "less than", - "equal to", - "greater than" + private static final String[] COMPARISON_DESCRIPTIONS = { + "less than", + "equal to", + "greater than" }; private ComparatorMatcher(Comparator comparator, T expected, int minCompare, int maxCompare, boolean includeComparatorInDescription) { @@ -103,7 +146,7 @@ public void describeTo(Description description) { } private static String asText(int comparison) { - return comparisonDescriptions[signum(comparison) + 1]; + return COMPARISON_DESCRIPTIONS[signum(comparison) + 1]; } } @@ -115,9 +158,10 @@ private static String asText(int comparison) { *
assertThat(1, ComparatorMatcherBuilder.<Integer>usingNaturalOrdering().comparesEqualTo(1))
* * @param value the value which, when passed to the Comparator supplied to this builder, should return zero + * @return the created matcher */ public Matcher comparesEqualTo(T value) { - return new ComparatorMatcher(comparator, value, ComparatorMatcher.EQUAL, ComparatorMatcher.EQUAL, includeComparatorInDescription); + return new ComparatorMatcher<>(comparator, value, ComparatorMatcher.EQUAL, ComparatorMatcher.EQUAL, includeComparatorInDescription); } /** @@ -129,9 +173,10 @@ public Matcher comparesEqualTo(T value) { * * @param value the value which, when passed to the Comparator supplied to this builder, should return greater * than zero + * @return the created matcher */ public Matcher greaterThan(T value) { - return new ComparatorMatcher(comparator, value, ComparatorMatcher.GREATER_THAN, ComparatorMatcher.GREATER_THAN, includeComparatorInDescription); + return new ComparatorMatcher<>(comparator, value, ComparatorMatcher.GREATER_THAN, ComparatorMatcher.GREATER_THAN, includeComparatorInDescription); } /** @@ -143,9 +188,10 @@ public Matcher greaterThan(T value) { * * @param value the value which, when passed to the Comparator supplied to this builder, should return greater * than or equal to zero + * @return the created matcher */ public Matcher greaterThanOrEqualTo(T value) { - return new ComparatorMatcher(comparator, value, ComparatorMatcher.EQUAL, ComparatorMatcher.GREATER_THAN, includeComparatorInDescription); + return new ComparatorMatcher<>(comparator, value, ComparatorMatcher.EQUAL, ComparatorMatcher.GREATER_THAN, includeComparatorInDescription); } /** @@ -157,9 +203,10 @@ public Matcher greaterThanOrEqualTo(T value) { * * @param value the value which, when passed to the Comparator supplied to this builder, should return less * than zero + * @return the created matcher */ public Matcher lessThan(T value) { - return new ComparatorMatcher(comparator, value, ComparatorMatcher.LESS_THAN, ComparatorMatcher.LESS_THAN, includeComparatorInDescription); + return new ComparatorMatcher<>(comparator, value, ComparatorMatcher.LESS_THAN, ComparatorMatcher.LESS_THAN, includeComparatorInDescription); } /** @@ -171,8 +218,9 @@ public Matcher lessThan(T value) { * * @param value the value which, when passed to the Comparator supplied to this builder, should return less * than or equal to zero + * @return the created matcher */ public Matcher lessThanOrEqualTo(T value) { - return new ComparatorMatcher(comparator, value, ComparatorMatcher.LESS_THAN, ComparatorMatcher.EQUAL, includeComparatorInDescription); + return new ComparatorMatcher<>(comparator, value, ComparatorMatcher.LESS_THAN, ComparatorMatcher.EQUAL, includeComparatorInDescription); } } diff --git a/hamcrest/src/main/java/org/hamcrest/core/AllOf.java b/hamcrest/src/main/java/org/hamcrest/core/AllOf.java index b8c3faad..77ee6409 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/AllOf.java +++ b/hamcrest/src/main/java/org/hamcrest/core/AllOf.java @@ -1,14 +1,45 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; +import java.util.Arrays; import org.hamcrest.Description; import org.hamcrest.DiagnosingMatcher; import org.hamcrest.Matcher; -import java.util.Arrays; - /** * Calculates the logical conjunction of multiple matchers. Evaluation is shortcut, so * subsequent matchers are not called if an earlier matcher returns false. + * @param the matcher type */ public class AllOf extends DiagnosingMatcher { @@ -29,7 +60,7 @@ public boolean matches(Object o, Description mismatch) { if (!matcher.matches(o)) { mismatch.appendDescriptionOf(matcher).appendText(" "); matcher.describeMismatch(o, mismatch); - return false; + return false; } } return true; @@ -44,6 +75,9 @@ public void describeTo(Description description) { * Creates a matcher that matches if the examined object matches ALL of the specified matchers. * For example: *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
+ * @param the matcher type + * @param matchers the matchers to match + * @return the created matcher */ public static Matcher allOf(Iterable> matchers) { return new AllOf<>(matchers); @@ -53,6 +87,9 @@ public static Matcher allOf(Iterable> matchers) { * Creates a matcher that matches if the examined object matches ALL of the specified matchers. * For example: *
assertThat("myValue", allOf(startsWith("my"), containsString("Val")))
+ * @param the matcher type + * @param matchers the matchers to match + * @return the created matcher */ @SafeVarargs public static Matcher allOf(Matcher... matchers) { diff --git a/hamcrest/src/main/java/org/hamcrest/core/AnyOf.java b/hamcrest/src/main/java/org/hamcrest/core/AnyOf.java index 7a22c22e..ddf2c5e4 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/AnyOf.java +++ b/hamcrest/src/main/java/org/hamcrest/core/AnyOf.java @@ -1,13 +1,44 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; +import java.util.Arrays; import org.hamcrest.Description; import org.hamcrest.Matcher; -import java.util.Arrays; - /** * Calculates the logical disjunction of multiple matchers. Evaluation is shortcut, so * subsequent matchers are not called if an earlier matcher returns true. + * @param the matcher type */ public class AnyOf extends ShortcutCombination { @@ -34,15 +65,21 @@ public void describeTo(Description description) { * Creates a matcher that matches if the examined object matches ANY of the specified matchers. * For example: *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
+ * @param the matcher type + * @param matchers the matchers to match + * @return the created matcher */ public static AnyOf anyOf(Iterable> matchers) { return new AnyOf<>(matchers); } - + /** * Creates a matcher that matches if the examined object matches ANY of the specified matchers. * For example: *
assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))
+ * @param the matcher type + * @param matchers the matchers to match + * @return the created matcher */ @SafeVarargs public static AnyOf anyOf(Matcher... matchers) { diff --git a/hamcrest/src/main/java/org/hamcrest/core/CombinableMatcher.java b/hamcrest/src/main/java/org/hamcrest/core/CombinableMatcher.java index e37efce6..5fdb2448 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/CombinableMatcher.java +++ b/hamcrest/src/main/java/org/hamcrest/core/CombinableMatcher.java @@ -1,82 +1,134 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; +import java.util.ArrayList; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; -import java.util.ArrayList; - +/** + * Combine matchers. + * @param the matcher type + */ public class CombinableMatcher extends TypeSafeDiagnosingMatcher { - private final Matcher matcher; + private final Matcher matcher; + + public CombinableMatcher(Matcher matcher) { + this.matcher = matcher; + } + + @Override + protected boolean matchesSafely(T item, Description mismatch) { + if (!matcher.matches(item)) { + matcher.describeMismatch(item, mismatch); + return false; + } + return true; + } + + @Override + public void describeTo(Description description) { + description.appendDescriptionOf(matcher); + } + + public CombinableMatcher and(Matcher other) { + return new CombinableMatcher<>(new AllOf<>(templatedListWith(other))); + } - public CombinableMatcher(Matcher matcher) { - this.matcher = matcher; - } + public CombinableMatcher or(Matcher other) { + return new CombinableMatcher<>(new AnyOf<>(templatedListWith(other))); + } - @Override - protected boolean matchesSafely(T item, Description mismatch) { - if (!matcher.matches(item)) { - matcher.describeMismatch(item, mismatch); - return false; + private ArrayList> templatedListWith(Matcher other) { + ArrayList> matchers = new ArrayList<>(); + matchers.add(matcher); + matchers.add(other); + return matchers; } - return true; - } - - @Override - public void describeTo(Description description) { - description.appendDescriptionOf(matcher); - } - - public CombinableMatcher and(Matcher other) { - return new CombinableMatcher<>(new AllOf<>(templatedListWith(other))); - } - - public CombinableMatcher or(Matcher other) { - return new CombinableMatcher<>(new AnyOf<>(templatedListWith(other))); - } - - private ArrayList> templatedListWith(Matcher other) { - ArrayList> matchers = new ArrayList<>(); - matchers.add(matcher); - matchers.add(other); - return matchers; - } - - /** - * Creates a matcher that matches when both of the specified matchers match the examined object. - * For example: - *
assertThat("fab", both(containsString("a")).and(containsString("b")))
- */ - public static CombinableBothMatcher both(Matcher matcher) { - return new CombinableBothMatcher<>(matcher); - } - - public static final class CombinableBothMatcher { - private final Matcher first; - public CombinableBothMatcher(Matcher matcher) { - this.first = matcher; + + /** + * Creates a matcher that matches when both of the specified matchers match the examined object. + * For example: + *
assertThat("fab", both(containsString("a")).and(containsString("b")))
+ * @param the matcher type + * @param matcher the matcher to wrap + * @return the created matcher + */ + public static CombinableBothMatcher both(Matcher matcher) { + return new CombinableBothMatcher<>(matcher); } - public CombinableMatcher and(Matcher other) { - return new CombinableMatcher<>(first).and(other); + + /** + * Combines both matchers. + * @param the matcher tpye + */ + public static final class CombinableBothMatcher { + private final Matcher first; + + public CombinableBothMatcher(Matcher matcher) { + this.first = matcher; + } + + public CombinableMatcher and(Matcher other) { + return new CombinableMatcher<>(first).and(other); + } } - } - - /** - * Creates a matcher that matches when either of the specified matchers match the examined object. - * For example: - *
assertThat("fan", either(containsString("a")).or(containsString("b")))
- */ - public static CombinableEitherMatcher either(Matcher matcher) { - return new CombinableEitherMatcher<>(matcher); - } - - public static final class CombinableEitherMatcher { - private final Matcher first; - public CombinableEitherMatcher(Matcher matcher) { - this.first = matcher; + + /** + * Creates a matcher that matches when either of the specified matchers match the examined object. + * For example: + *
assertThat("fan", either(containsString("a")).or(containsString("b")))
+ * @param the matcher type + * @param matcher the matcher to wrap + * @return the created matcher + */ + public static CombinableEitherMatcher either(Matcher matcher) { + return new CombinableEitherMatcher<>(matcher); } - public CombinableMatcher or(Matcher other) { - return new CombinableMatcher<>(first).or(other); + + /** + * Combines matcher matching either of them. + * @param the matcher type + */ + public static final class CombinableEitherMatcher { + private final Matcher first; + + public CombinableEitherMatcher(Matcher matcher) { + this.first = matcher; + } + + public CombinableMatcher or(Matcher other) { + return new CombinableMatcher<>(first).or(other); + } } - } } diff --git a/hamcrest/src/main/java/org/hamcrest/core/DescribedAs.java b/hamcrest/src/main/java/org/hamcrest/core/DescribedAs.java index 23876095..abadf9b8 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/DescribedAs.java +++ b/hamcrest/src/main/java/org/hamcrest/core/DescribedAs.java @@ -1,29 +1,59 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; +import static java.lang.Integer.parseInt; +import java.util.regex.Pattern; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; -import java.util.regex.Pattern; - -import static java.lang.Integer.parseInt; - /** * Provides a custom description to another matcher. + * @param the matcher type */ public class DescribedAs extends BaseMatcher { private final String descriptionTemplate; private final Matcher matcher; private final Object[] values; - - private final static Pattern ARG_PATTERN = Pattern.compile("%([0-9]+)"); - + + private final static Pattern ARG_PATTERN = Pattern.compile("%([0-9]+)"); + public DescribedAs(String descriptionTemplate, Matcher matcher, Object[] values) { this.descriptionTemplate = descriptionTemplate; this.matcher = matcher; this.values = values.clone(); } - + @Override public boolean matches(Object o) { return matcher.matches(o); @@ -32,19 +62,19 @@ public boolean matches(Object o) { @Override public void describeTo(Description description) { java.util.regex.Matcher arg = ARG_PATTERN.matcher(descriptionTemplate); - + int textStart = 0; while (arg.find()) { description.appendText(descriptionTemplate.substring(textStart, arg.start())); description.appendValue(values[parseInt(arg.group(1))]); textStart = arg.end(); } - + if (textStart < descriptionTemplate.length()) { description.appendText(descriptionTemplate.substring(textStart)); } } - + @Override public void describeMismatch(Object item, Description description) { matcher.describeMismatch(item, description); @@ -54,16 +84,18 @@ public void describeMismatch(Object item, Description description) { * Wraps an existing matcher, overriding its description with that specified. All other functions are * delegated to the decorated matcher, including its mismatch description. * For example: - *
describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())
- * + *
describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())
+ * + * @param the matcher type * @param description * the new description for the wrapped matcher * @param matcher * the matcher to wrap * @param values * optional values to insert into the tokenised description + * @return the created matcher */ public static Matcher describedAs(String description, Matcher matcher, Object... values) { - return new DescribedAs(description, matcher, values); + return new DescribedAs<>(description, matcher, values); } } diff --git a/hamcrest/src/main/java/org/hamcrest/core/Every.java b/hamcrest/src/main/java/org/hamcrest/core/Every.java index 988758b1..b2222016 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/Every.java +++ b/hamcrest/src/main/java/org/hamcrest/core/Every.java @@ -1,9 +1,44 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; +/** + * A matcher matching ever item of a list of matchers. + * @param the matcher type + */ public class Every extends TypeSafeDiagnosingMatcher> { private final Matcher matcher; @@ -34,9 +69,11 @@ public void describeTo(Description description) { * itemMatcher. * For example: *
assertThat(Arrays.asList("bar", "baz"), everyItem(startsWith("ba")))
- * + * + * @param the matcher type * @param itemMatcher * the matcher to apply to every item provided by the examined {@link Iterable} + * @return the created matcher */ public static Matcher> everyItem(final Matcher itemMatcher) { return new Every<>(itemMatcher); diff --git a/hamcrest/src/main/java/org/hamcrest/core/Is.java b/hamcrest/src/main/java/org/hamcrest/core/Is.java index 5264e89d..95b138c7 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/Is.java +++ b/hamcrest/src/main/java/org/hamcrest/core/Is.java @@ -1,9 +1,39 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; - import static org.hamcrest.core.IsEqual.equalTo; /** @@ -12,6 +42,7 @@ * * For example: assertThat(cheese, equalTo(smelly)) * vs. assertThat(cheese, is(equalTo(smelly))) + * @param the matcher type */ public class Is extends BaseMatcher { private final Matcher matcher; @@ -42,7 +73,9 @@ public void describeMismatch(Object item, Description mismatchDescription) { *
assertThat(cheese, is(equalTo(smelly)))
* instead of: *
assertThat(cheese, equalTo(smelly))
- * + * @param the matcher type + * @param matcher the matcher to match + * @return the created matcher */ public static Matcher is(Matcher matcher) { return new Is<>(matcher); @@ -54,7 +87,10 @@ public static Matcher is(Matcher matcher) { *
assertThat(cheese, is(smelly))
* instead of: *
assertThat(cheese, is(equalTo(smelly)))
- * + * + * @param the matcher type + * @param value the value to match + * @return the created matcher */ public static Matcher is(T value) { return is(equalTo(value)); @@ -66,7 +102,10 @@ public static Matcher is(T value) { *
assertThat(cheese, isA(Cheddar.class))
* instead of: *
assertThat(cheese, is(instanceOf(Cheddar.class)))
- * + * + * @param the matcher type + * @param type the type to match + * @return the created matcher */ public static Matcher isA(Class type) { return is(IsInstanceOf.instanceOf(type)); diff --git a/hamcrest/src/main/java/org/hamcrest/core/IsAnything.java b/hamcrest/src/main/java/org/hamcrest/core/IsAnything.java index 94943dc0..5aff985e 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/IsAnything.java +++ b/hamcrest/src/main/java/org/hamcrest/core/IsAnything.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.BaseMatcher; @@ -7,9 +38,9 @@ /** * A matcher that always returns true. + * @param the matcher type */ public class IsAnything extends BaseMatcher { - private final String message; public IsAnything() { @@ -32,8 +63,11 @@ public void describeTo(Description description) { /** * Creates a matcher that always matches, regardless of the examined object. + * @return the created matcher */ - public static Matcher anything() { return new IsAnything<>(); } + public static Matcher anything() { + return new IsAnything<>(); + } /** * Creates a matcher that always matches, regardless of the examined object, but describes @@ -41,6 +75,7 @@ public void describeTo(Description description) { * * @param description * a meaningful {@link String} used when describing itself + * @return the created matcher */ public static Matcher anything(String description) { return new IsAnything<>(description); diff --git a/hamcrest/src/main/java/org/hamcrest/core/IsCollectionContaining.java b/hamcrest/src/main/java/org/hamcrest/core/IsCollectionContaining.java index b54b6aa9..cd2a1d68 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/IsCollectionContaining.java +++ b/hamcrest/src/main/java/org/hamcrest/core/IsCollectionContaining.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.Description; @@ -5,6 +36,7 @@ import org.hamcrest.TypeSafeDiagnosingMatcher; /** + * @param the matcher type * @deprecated As of release 2.1, replaced by {@link IsIterableContaining}. */ @Deprecated @@ -25,7 +57,6 @@ public void describeTo(Description description) { delegate.describeTo(description); } - /** * Creates a matcher for {@link Iterable}s that only matches when a single pass over the * examined {@link Iterable} yields at least one item that is matched by the specified @@ -34,10 +65,11 @@ public void describeTo(Description description) { * For example: *
assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))
* - * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItem(Matcher)}. - * * @param itemMatcher * the matcher to apply to items provided by the examined {@link Iterable} + * @param the matcher type + * @return the created matcher + * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItem(Matcher)}. */ public static Matcher> hasItem(Matcher itemMatcher) { return IsIterableContaining.hasItem(itemMatcher); @@ -51,10 +83,11 @@ public static Matcher> hasItem(Matcher itemMa * For example: *
assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))
* - * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItem(Object)}. - * * @param item * the item to compare against the items provided by the examined {@link Iterable} + * @param the matcher type + * @return the created matcher + * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItem(Object)}. */ public static Matcher> hasItem(T item) { // Doesn't forward to hasItem() method so compiler can sort out generics. @@ -69,16 +102,17 @@ public static Matcher> hasItem(T item) { * For example: *
assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))
* - * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItems(Matcher[])}}. - * * @param itemMatchers * the matchers to apply to items provided by the examined {@link Iterable} + * @param the matcher type + * @return the created matcher + * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItems(Matcher[])}}. */ @SafeVarargs public static Matcher> hasItems(Matcher... itemMatchers) { return IsIterableContaining.hasItems(itemMatchers); } - + /** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is equal to the corresponding @@ -87,10 +121,11 @@ public static Matcher> hasItems(Matcher... itemMatche * For example: *
assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))
* - * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItems(Object[])}}. - * * @param items * the items to compare against the items provided by the examined {@link Iterable} + * @param the matcher type + * @return the created matcher + * @deprecated As of version 2.1, use {@link IsIterableContaining#hasItems(Object[])}}. */ @SafeVarargs public static Matcher> hasItems(T... items) { diff --git a/hamcrest/src/main/java/org/hamcrest/core/IsEqual.java b/hamcrest/src/main/java/org/hamcrest/core/IsEqual.java index 582c630f..78d63835 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/IsEqual.java +++ b/hamcrest/src/main/java/org/hamcrest/core/IsEqual.java @@ -1,15 +1,45 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; +import java.lang.reflect.Array; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; -import java.lang.reflect.Array; - - /** * Is the value equal to another value, as tested by the * {@link java.lang.Object#equals} invokedMethod? + * @param the matcher type */ public class IsEqual extends BaseMatcher { private final Object expectedValue; @@ -32,11 +62,11 @@ private static boolean areEqual(Object actual, Object expected) { if (actual == null) { return expected == null; } - + if (expected != null && isArray(actual)) { return isArray(expected) && areArraysEqual(actual, expected); } - + return actual.equals(expected); } @@ -65,23 +95,26 @@ private static boolean isArray(Object o) { * Creates a matcher that matches when the examined object is logically equal to the specified * operand, as determined by calling the {@link java.lang.Object#equals} method on * the examined object. - * + * *

If the specified operand is null then the created matcher will only match if * the examined object's equals method returns true when passed a * null (which would be a violation of the equals contract), unless the * examined object itself is null, in which case the matcher will return a positive * match.

- * + * *

The created matcher provides a special behaviour when examining Arrays, whereby * it will match if both the operand and the examined object are arrays of the same length and * contain items that are equal to each other (according to the above rules) in the same - * indexes.

+ * indexes.

* For example: *
      * assertThat("foo", equalTo("foo"));
      * assertThat(new String[] {"foo", "bar"}, equalTo(new String[] {"foo", "bar"}));
      * 
- * + * + * @param the matcher tpye + * @param operand the operand to match + * @return the created matcher */ public static Matcher equalTo(T operand) { return new IsEqual<>(operand); @@ -90,6 +123,8 @@ public static Matcher equalTo(T operand) { /** * Creates an {@link org.hamcrest.core.IsEqual} matcher that does not enforce the values being * compared to be of the same static type. + * @param operand the operand to match + * @return the created matcher */ public static Matcher equalToObject(Object operand) { return new IsEqual<>(operand); diff --git a/hamcrest/src/main/java/org/hamcrest/core/IsInstanceOf.java b/hamcrest/src/main/java/org/hamcrest/core/IsInstanceOf.java index 5a508c9b..6c92e71b 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/IsInstanceOf.java +++ b/hamcrest/src/main/java/org/hamcrest/core/IsInstanceOf.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.Description; @@ -25,30 +56,46 @@ public IsInstanceOf(Class expectedClass) { } private static Class matchableClass(Class expectedClass) { - if (boolean.class.equals(expectedClass)) return Boolean.class; - if (byte.class.equals(expectedClass)) return Byte.class; - if (char.class.equals(expectedClass)) return Character.class; - if (double.class.equals(expectedClass)) return Double.class; - if (float.class.equals(expectedClass)) return Float.class; - if (int.class.equals(expectedClass)) return Integer.class; - if (long.class.equals(expectedClass)) return Long.class; - if (short.class.equals(expectedClass)) return Short.class; - return expectedClass; + if (boolean.class.equals(expectedClass)) { + return Boolean.class; + } + if (byte.class.equals(expectedClass)) { + return Byte.class; + } + if (char.class.equals(expectedClass)) { + return Character.class; + } + if (double.class.equals(expectedClass)) { + return Double.class; + } + if (float.class.equals(expectedClass)) { + return Float.class; + } + if (int.class.equals(expectedClass)) { + return Integer.class; + } + if (long.class.equals(expectedClass)) { + return Long.class; + } + if (short.class.equals(expectedClass)) { + return Short.class; + } + return expectedClass; } @Override protected boolean matches(Object item, Description mismatch) { - if (null == item) { - mismatch.appendText("null"); - return false; - } - - if (!matchableClass.isInstance(item)) { - mismatch.appendValue(item).appendText(" is a " + item.getClass().getName()); - return false; - } - - return true; + if (null == item) { + mismatch.appendText("null"); + return false; + } + + if (!matchableClass.isInstance(item)) { + mismatch.appendValue(item).appendText(" is a " + item.getClass().getName()); + return false; + } + + return true; } @Override @@ -60,28 +107,34 @@ public void describeTo(Description description) { * Creates a matcher that matches when the examined object is an instance of the specified type, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. - * + * *

The created matcher assumes no relationship between specified type and the examined object.

* For example: *
assertThat(new Canoe(), instanceOf(Paddlable.class));
- * + * + * @param the matcher type + * @param type the type to match + * @return the created matcher */ @SuppressWarnings("unchecked") public static Matcher instanceOf(Class type) { return (Matcher) new IsInstanceOf(type); } - + /** * Creates a matcher that matches when the examined object is an instance of the specified type, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. - * + * *

The created matcher forces a relationship between specified type and the examined object, and should be * used when it is necessary to make generics conform, for example in the JMock clause * with(any(Thing.class))

* For example: *
assertThat(new Canoe(), instanceOf(Canoe.class));
* + * @param the matcher type + * @param type the type to match + * @return the created matcher */ @SuppressWarnings("unchecked") public static Matcher any(Class type) { diff --git a/hamcrest/src/main/java/org/hamcrest/core/IsIterableContaining.java b/hamcrest/src/main/java/org/hamcrest/core/IsIterableContaining.java index 67e776b0..244e994c 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/IsIterableContaining.java +++ b/hamcrest/src/main/java/org/hamcrest/core/IsIterableContaining.java @@ -1,15 +1,48 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; +import java.util.ArrayList; +import java.util.List; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; - -import java.util.ArrayList; -import java.util.List; - import static org.hamcrest.core.AllOf.allOf; import static org.hamcrest.core.IsEqual.equalTo; +/** + * Tests whether an {@link Iterable} is containing a certain value. + * @param the matcher type + */ public class IsIterableContaining extends TypeSafeDiagnosingMatcher> { private final Matcher elementMatcher; @@ -20,8 +53,8 @@ public IsIterableContaining(Matcher elementMatcher) { @Override protected boolean matchesSafely(Iterable collection, Description mismatchDescription) { if (isEmpty(collection)) { - mismatchDescription.appendText("was empty"); - return false; + mismatchDescription.appendText("was empty"); + return false; } for (Object item : collection) { @@ -34,7 +67,7 @@ protected boolean matchesSafely(Iterable collection, Description mism boolean isPastFirst = false; for (Object item : collection) { if (isPastFirst) { - mismatchDescription.appendText(", "); + mismatchDescription.appendText(", "); } elementMatcher.describeMismatch(item, mismatchDescription); isPastFirst = true; @@ -44,17 +77,16 @@ protected boolean matchesSafely(Iterable collection, Description mism } private boolean isEmpty(Iterable iterable) { - return ! iterable.iterator().hasNext(); + return ! iterable.iterator().hasNext(); } @Override public void describeTo(Description description) { description - .appendText("a collection containing ") - .appendDescriptionOf(elementMatcher); + .appendText("a collection containing ") + .appendDescriptionOf(elementMatcher); } - /** * Creates a matcher for {@link Iterable}s that only matches when a single pass over the * examined {@link Iterable} yields at least one item that is matched by the specified @@ -62,9 +94,11 @@ public void describeTo(Description description) { * will stop as soon as a matching item is found. * For example: *
assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))
- * + * + * @param the matcher type * @param itemMatcher * the matcher to apply to items provided by the examined {@link Iterable} + * @return the created matcher */ public static Matcher> hasItem(Matcher itemMatcher) { return new IsIterableContaining<>(itemMatcher); @@ -77,9 +111,11 @@ public static Matcher> hasItem(Matcher itemMa * will stop as soon as a matching item is found. * For example: *
assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))
- * + * + * @param the matcher type * @param item * the item to compare against the items provided by the examined {@link Iterable} + * @return the created matcher */ public static Matcher> hasItem(T item) { // Doesn't forward to hasItem() method so compiler can sort out generics. @@ -93,22 +129,24 @@ public static Matcher> hasItem(T item) { * the examined {@link Iterable} will stop as soon as a matching item is found. * For example: *
assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))
- * + * + * @param the matcher type * @param itemMatchers * the matchers to apply to items provided by the examined {@link Iterable} + * @return the created matcher */ @SafeVarargs public static Matcher> hasItems(Matcher... itemMatchers) { List>> all = new ArrayList<>(itemMatchers.length); - + for (Matcher elementMatcher : itemMatchers) { - // Doesn't forward to hasItem() method so compiler can sort out generics. - all.add(new IsIterableContaining<>(elementMatcher)); + // Doesn't forward to hasItem() method so compiler can sort out generics. + all.add(new IsIterableContaining<>(elementMatcher)); } - + return allOf(all); } - + /** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is equal to the corresponding @@ -116,9 +154,11 @@ public static Matcher> hasItems(Matcher... itemMatche * examined {@link Iterable} will stop as soon as a matching item is found. * For example: *
assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))
- * + * + * @param the matcher type * @param items * the items to compare against the items provided by the examined {@link Iterable} + * @return the created matcher */ @SafeVarargs public static Matcher> hasItems(T... items) { @@ -126,7 +166,7 @@ public static Matcher> hasItems(T... items) { for (T item : items) { all.add(hasItem(item)); } - + return allOf(all); } diff --git a/hamcrest/src/main/java/org/hamcrest/core/IsNot.java b/hamcrest/src/main/java/org/hamcrest/core/IsNot.java index d5cf9c06..a08db7d2 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/IsNot.java +++ b/hamcrest/src/main/java/org/hamcrest/core/IsNot.java @@ -1,14 +1,44 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; - import static org.hamcrest.core.IsEqual.equalTo; - /** * Calculates the logical negation of a matcher. + * @param the matcher type */ public class IsNot extends BaseMatcher { private final Matcher matcher; @@ -27,18 +57,19 @@ public void describeTo(Description description) { description.appendText("not ").appendDescriptionOf(matcher); } - /** * Creates a matcher that wraps an existing matcher, but inverts the logic by which * it will match. * For example: *
assertThat(cheese, is(not(equalTo(smelly))))
- * + * + * @param the matcher type * @param matcher * the matcher whose sense should be inverted + * @return the created matcher */ public static Matcher not(Matcher matcher) { - return new IsNot(matcher); + return new IsNot<>(matcher); } /** @@ -47,9 +78,11 @@ public static Matcher not(Matcher matcher) { *
assertThat(cheese, is(not(smelly)))
* instead of: *
assertThat(cheese, is(not(equalTo(smelly))))
- * + * + * @param the matcher type * @param value * the value that any examined object should not equal + * @return the created matcher */ public static Matcher not(T value) { return not(equalTo(value)); diff --git a/hamcrest/src/main/java/org/hamcrest/core/IsNull.java b/hamcrest/src/main/java/org/hamcrest/core/IsNull.java index 9ebf080f..2ed9eddf 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/IsNull.java +++ b/hamcrest/src/main/java/org/hamcrest/core/IsNull.java @@ -1,15 +1,47 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; - import static org.hamcrest.core.IsNot.not; /** * Is the value null? + * @param the matcher type */ public class IsNull extends BaseMatcher { + @Override public boolean matches(Object o) { return o == null; @@ -24,10 +56,11 @@ public void describeTo(Description description) { * Creates a matcher that matches if examined object is null. * For example: *
assertThat(cheese, is(nullValue())
- * + * + * @return the created matcher */ public static Matcher nullValue() { - return new IsNull(); + return new IsNull<>(); } /** @@ -36,7 +69,8 @@ public static Matcher nullValue() { *
assertThat(cheese, is(notNullValue()))
* instead of: *
assertThat(cheese, is(not(nullValue())))
- * + * + * @return the created matcher */ public static Matcher notNullValue() { return not(nullValue()); @@ -47,12 +81,14 @@ public static Matcher notNullValue() { * single dummy argument to facilitate type inference. * For example: *
assertThat(cheese, is(nullValue(Cheese.class))
- * + * + * @param the matcher type * @param type * dummy parameter used to infer the generic type of the returned matcher + * @return the created matcher */ public static Matcher nullValue(Class type) { - return new IsNull(); + return new IsNull<>(); } /** @@ -62,10 +98,11 @@ public static Matcher nullValue(Class type) { *
assertThat(cheese, is(notNullValue(X.class)))
* instead of: *
assertThat(cheese, is(not(nullValue(X.class))))
- * + * + * @param the matcher type * @param type * dummy parameter used to infer the generic type of the returned matcher - * + * @return the created matcher */ public static Matcher notNullValue(Class type) { return not(nullValue(type)); diff --git a/hamcrest/src/main/java/org/hamcrest/core/IsSame.java b/hamcrest/src/main/java/org/hamcrest/core/IsSame.java index cbc3971b..a0603c9d 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/IsSame.java +++ b/hamcrest/src/main/java/org/hamcrest/core/IsSame.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.BaseMatcher; @@ -7,10 +38,11 @@ /** * Is the value the same object as another value? + * @param the matcher type */ public class IsSame extends BaseMatcher { private final T object; - + public IsSame(T object) { this.object = object; } @@ -26,26 +58,30 @@ public void describeTo(Description description) { .appendValue(object) .appendText(")"); } - + /** * Creates a matcher that matches only when the examined object is the same instance as * the specified target object. * + * @param the matcher type * @param target * the target instance against which others should be assessed + * @return the created matcher */ public static Matcher sameInstance(T target) { - return new IsSame(target); + return new IsSame<>(target); } - + /** * Creates a matcher that matches only when the examined object is the same instance as * the specified target object. * + * @param the matcher type * @param target * the target instance against which others should be assessed + * @return the created matcher */ public static Matcher theInstance(T target) { - return new IsSame(target); + return new IsSame<>(target); } } diff --git a/hamcrest/src/main/java/org/hamcrest/core/ShortcutCombination.java b/hamcrest/src/main/java/org/hamcrest/core/ShortcutCombination.java index 30b33af5..174e11ad 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/ShortcutCombination.java +++ b/hamcrest/src/main/java/org/hamcrest/core/ShortcutCombination.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.BaseMatcher; @@ -11,13 +42,13 @@ abstract class ShortcutCombination extends BaseMatcher { public ShortcutCombination(Iterable> matchers) { this.matchers = matchers; } - + @Override public abstract boolean matches(Object o); - + @Override public abstract void describeTo(Description description); - + protected boolean matches(Object o, boolean shortcut) { for (Matcher matcher : matchers) { if (matcher.matches(o) == shortcut) { @@ -26,7 +57,7 @@ protected boolean matches(Object o, boolean shortcut) { } return !shortcut; } - + public void describeTo(Description description, String operator) { description.appendList("(", " " + operator + " ", ")", matchers); } diff --git a/hamcrest/src/main/java/org/hamcrest/core/StringContains.java b/hamcrest/src/main/java/org/hamcrest/core/StringContains.java index 050fd159..dd5c6cdb 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/StringContains.java +++ b/hamcrest/src/main/java/org/hamcrest/core/StringContains.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.Matcher; @@ -6,7 +37,10 @@ * Tests if the argument is a string that contains a specific substring. */ public class StringContains extends SubstringMatcher { - public StringContains(String substring) { this(false, substring); } + + public StringContains(String substring) { + this(false, substring); + } public StringContains(boolean ignoringCase, String substring) { super("containing", ignoringCase, substring); @@ -22,10 +56,10 @@ protected boolean evalSubstringOf(String s) { * {@link String} anywhere. * For example: *
assertThat("myStringOfNote", containsString("ring"))
- * + * * @param substring * the substring that the returned matcher will expect to find within any examined string - * + * @return the created matcher */ public static Matcher containsString(String substring) { return new StringContains(false, substring); @@ -39,7 +73,7 @@ public static Matcher containsString(String substring) { * * @param substring * the substring that the returned matcher will expect to find within any examined string - * + * @return the created matcher */ public static Matcher containsStringIgnoringCase(String substring) { return new StringContains(true, substring); diff --git a/hamcrest/src/main/java/org/hamcrest/core/StringEndsWith.java b/hamcrest/src/main/java/org/hamcrest/core/StringEndsWith.java index 48ffd923..91363f5f 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/StringEndsWith.java +++ b/hamcrest/src/main/java/org/hamcrest/core/StringEndsWith.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.Matcher; @@ -6,9 +37,14 @@ * Tests if the argument is a string that ends with a specific substring. */ public class StringEndsWith extends SubstringMatcher { - public StringEndsWith(String substring) { this(false, substring); } - public StringEndsWith(boolean ignoringCase, String substring) { super("ending with", ignoringCase, substring); } + public StringEndsWith(String substring) { + this(false, substring); + } + + public StringEndsWith(boolean ignoringCase, String substring) { + super("ending with", ignoringCase, substring); + } @Override protected boolean evalSubstringOf(String s) { @@ -20,9 +56,10 @@ protected boolean evalSubstringOf(String s) { * {@link String}. * For example: *
assertThat("myStringOfNote", endsWith("Note"))
- * + * * @param suffix * the substring that the returned matcher will expect at the end of any examined string + * @return the created matcher */ public static Matcher endsWith(String suffix) { return new StringEndsWith(false, suffix); @@ -36,6 +73,7 @@ public static Matcher endsWith(String suffix) { * * @param suffix * the substring that the returned matcher will expect at the end of any examined string + * @return the created matcher */ public static Matcher endsWithIgnoringCase(String suffix) { return new StringEndsWith(true, suffix); diff --git a/hamcrest/src/main/java/org/hamcrest/core/StringRegularExpression.java b/hamcrest/src/main/java/org/hamcrest/core/StringRegularExpression.java index b893ff0e..a2c692ef 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/StringRegularExpression.java +++ b/hamcrest/src/main/java/org/hamcrest/core/StringRegularExpression.java @@ -1,10 +1,37 @@ /** + * BSD License * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ package org.hamcrest.core; import java.util.regex.Pattern; - import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; @@ -15,54 +42,53 @@ * */ public class StringRegularExpression extends TypeSafeDiagnosingMatcher { + private Pattern pattern; - protected StringRegularExpression(Pattern pattern) { - this.pattern = pattern; - } - - private Pattern pattern; + protected StringRegularExpression(Pattern pattern) { + this.pattern = pattern; + } - @Override - public void describeTo(Description description) { - description.appendText("a string matching the pattern ").appendValue(pattern); - } + @Override + public void describeTo(Description description) { + description.appendText("a string matching the pattern ").appendValue(pattern); + } - @Override - protected boolean matchesSafely(String actual, Description mismatchDescription) { - if (!pattern.matcher(actual).matches()) { - mismatchDescription.appendText("the string was ").appendValue(actual); - return false; + @Override + protected boolean matchesSafely(String actual, Description mismatchDescription) { + if (!pattern.matcher(actual).matches()) { + mismatchDescription.appendText("the string was ").appendValue(actual); + return false; + } + return true; } - return true; - } - /** - * Creates a matcher that checks if the examined string matches a specified {@link java.util.regex.Pattern}. - * - *
-   * assertThat("abc", matchesRegex(Pattern.compile("ˆ[a-z]$"));
-   * 
- * - * @param pattern - * the pattern to be used. - * @return The matcher. - */ - public static Matcher matchesRegex(Pattern pattern) { - return new StringRegularExpression(pattern); - } + /** + * Creates a matcher that checks if the examined string matches a specified {@link java.util.regex.Pattern}. + * + *
+     * assertThat("abc", matchesRegex(Pattern.compile("ˆ[a-z]$"));
+     * 
+ * + * @param pattern + * the pattern to be used. + * @return The matcher. + */ + public static Matcher matchesRegex(Pattern pattern) { + return new StringRegularExpression(pattern); + } - /** - * Creates a matcher that checks if the examined string matches a specified regex. - * - *
-   * assertThat("abc", matchesRegex("ˆ[a-z]+$"));
-   * 
- * - * @param regex - * The regex to be used for the validation. - * @return The matcher. - */ - public static Matcher matchesRegex(String regex) { - return matchesRegex(Pattern.compile(regex)); - } + /** + * Creates a matcher that checks if the examined string matches a specified regex. + * + *
+     * assertThat("abc", matchesRegex("ˆ[a-z]+$"));
+     * 
+ * + * @param regex + * The regex to be used for the validation. + * @return The matcher. + */ + public static Matcher matchesRegex(String regex) { + return matchesRegex(Pattern.compile(regex)); + } } diff --git a/hamcrest/src/main/java/org/hamcrest/core/StringStartsWith.java b/hamcrest/src/main/java/org/hamcrest/core/StringStartsWith.java index fa49b793..d07634f4 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/StringStartsWith.java +++ b/hamcrest/src/main/java/org/hamcrest/core/StringStartsWith.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.Matcher; @@ -6,12 +37,19 @@ * Tests if the argument is a string that starts with a specific substring. */ public class StringStartsWith extends SubstringMatcher { - public StringStartsWith(String substring) { this(false, substring); } - public StringStartsWith(boolean ignoringCase, String substring) { super("starting with", ignoringCase, substring); } + public StringStartsWith(String substring) { + this(false, substring); + } + + public StringStartsWith(boolean ignoringCase, String substring) { + super("starting with", ignoringCase, substring); + } @Override - protected boolean evalSubstringOf(String s) { return converted(s).startsWith(converted(substring)); } + protected boolean evalSubstringOf(String s) { + return converted(s).startsWith(converted(substring)); + } /** *

@@ -20,11 +58,14 @@ public class StringStartsWith extends SubstringMatcher { *

* For example: *
assertThat("myStringOfNote", startsWith("my"))
- * + * * @param prefix * the substring that the returned matcher will expect at the start of any examined string + * @return the created matcher */ - public static Matcher startsWith(String prefix) { return new StringStartsWith(false, prefix); } + public static Matcher startsWith(String prefix) { + return new StringStartsWith(false, prefix); + } /** *

@@ -36,7 +77,10 @@ public class StringStartsWith extends SubstringMatcher { * * @param prefix * the substring that the returned matcher will expect at the start of any examined string + * @return the created matcher */ - public static Matcher startsWithIgnoringCase(String prefix) { return new StringStartsWith(true, prefix); } + public static Matcher startsWithIgnoringCase(String prefix) { + return new StringStartsWith(true, prefix); + } } diff --git a/hamcrest/src/main/java/org/hamcrest/core/SubstringMatcher.java b/hamcrest/src/main/java/org/hamcrest/core/SubstringMatcher.java index f2b7cff0..27a5e90a 100644 --- a/hamcrest/src/main/java/org/hamcrest/core/SubstringMatcher.java +++ b/hamcrest/src/main/java/org/hamcrest/core/SubstringMatcher.java @@ -1,8 +1,42 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.Description; import org.hamcrest.TypeSafeMatcher; +/** + * Substring matcher. + */ public abstract class SubstringMatcher extends TypeSafeMatcher { // TODO: Replace String with CharSequence to allow for easy interoperability between @@ -25,11 +59,12 @@ protected SubstringMatcher(String relationship, boolean ignoringCase, String sub public boolean matchesSafely(String item) { return evalSubstringOf(ignoringCase ? item.toLowerCase() :item); } + @Override public void describeMismatchSafely(String item, Description mismatchDescription) { - mismatchDescription.appendText("was \"").appendText(item).appendText("\""); + mismatchDescription.appendText("was \"").appendText(item).appendText("\""); } - + @Override public void describeTo(Description description) { description.appendText("a string ") @@ -41,7 +76,9 @@ public void describeTo(Description description) { } } - protected String converted(String arg) { return ignoringCase ? arg.toLowerCase() : arg; } - protected abstract boolean evalSubstringOf(String string); + protected String converted(String arg) { + return ignoringCase ? arg.toLowerCase() : arg; + } + protected abstract boolean evalSubstringOf(String string); } diff --git a/hamcrest/src/main/java/org/hamcrest/internal/ArrayIterator.java b/hamcrest/src/main/java/org/hamcrest/internal/ArrayIterator.java index 03e4c43e..7d013a84 100644 --- a/hamcrest/src/main/java/org/hamcrest/internal/ArrayIterator.java +++ b/hamcrest/src/main/java/org/hamcrest/internal/ArrayIterator.java @@ -1,19 +1,53 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.internal; import java.lang.reflect.Array; import java.util.Iterator; +/** + * Iteration functionality for arrays. + */ public class ArrayIterator implements Iterator { private final Object array; private int currentIndex = 0; - + public ArrayIterator(Object array) { if (!array.getClass().isArray()) { throw new IllegalArgumentException("not an array"); } this.array = array; } - + @Override public boolean hasNext() { return currentIndex < Array.getLength(array); @@ -23,7 +57,7 @@ public boolean hasNext() { public Object next() { return Array.get(array, currentIndex++); } - + @Override public void remove() { throw new UnsupportedOperationException("cannot remove items from an array"); diff --git a/hamcrest/src/main/java/org/hamcrest/internal/NullSafety.java b/hamcrest/src/main/java/org/hamcrest/internal/NullSafety.java index 9310abfc..afe906fd 100644 --- a/hamcrest/src/main/java/org/hamcrest/internal/NullSafety.java +++ b/hamcrest/src/main/java/org/hamcrest/internal/NullSafety.java @@ -1,12 +1,46 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.internal; -import org.hamcrest.Matcher; -import org.hamcrest.core.IsNull; - import java.util.ArrayList; import java.util.List; +import org.hamcrest.Matcher; +import org.hamcrest.core.IsNull; +/** + * Methods to protect against {@code null}. + */ public class NullSafety { + @SuppressWarnings("unchecked") public static List> nullSafe(Matcher[] itemMatchers) { final List> matchers = new ArrayList>(itemMatchers.length); diff --git a/hamcrest/src/main/java/org/hamcrest/internal/ReflectiveTypeFinder.java b/hamcrest/src/main/java/org/hamcrest/internal/ReflectiveTypeFinder.java index b06df48c..584d8151 100644 --- a/hamcrest/src/main/java/org/hamcrest/internal/ReflectiveTypeFinder.java +++ b/hamcrest/src/main/java/org/hamcrest/internal/ReflectiveTypeFinder.java @@ -1,70 +1,100 @@ /** - * The TypeSafe classes, and their descendants, need a mechanism to find out what type has been used as a parameter - * for the concrete matcher. Unfortunately, this type is lost during type erasure so we need to use reflection - * to get it back, by picking out the type of a known parameter to a known method. - * The catch is that, with bridging methods, this type is only visible in the class that actually implements + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package org.hamcrest.internal; + +import java.lang.reflect.Method; + +/** + * The TypeSafe classes, and their descendants, need a mechanism to find out what type has been used as a parameter + * for the concrete matcher. Unfortunately, this type is lost during type erasure so we need to use reflection + * to get it back, by picking out the type of a known parameter to a known method. + * The catch is that, with bridging methods, this type is only visible in the class that actually implements * the expected method, so the ReflectiveTypeFinder needs to be applied to that class or a subtype. - * + * * For example, the abstract TypeSafeDiagnosingMatcher<T> defines an abstract method *
protected abstract boolean matchesSafely(T item, Description mismatchDescription);
* By default it uses new ReflectiveTypeFinder("matchesSafely", 2, 0); to find the * parameterised type. If we create a TypeSafeDiagnosingMatcher<String>, the type * finder will return String.class. - * - * A FeatureMatcher is an abstract subclass of TypeSafeDiagnosingMatcher. + * + * A FeatureMatcher is an abstract subclass of TypeSafeDiagnosingMatcher. * Although it has a templated implementation of matchesSafely(<T>, Description);, the * actual run-time signature of this is matchesSafely(Object, Description);. Instead, - * we must find the type by reflecting on the concrete implementation of + * we must find the type by reflecting on the concrete implementation of *
protected abstract U featureValueOf(T actual);
* a method which is declared in FeatureMatcher. - * - * In short, use this to extract a type from a method in the leaf class of a templated class hierarchy. - * + * + * In short, use this to extract a type from a method in the leaf class of a templated class hierarchy. + * * @author Steve Freeman * @author Nat Pryce */ -package org.hamcrest.internal; - -import java.lang.reflect.Method; - public class ReflectiveTypeFinder { - private final String methodName; - private final int expectedNumberOfParameters; - private final int typedParameter; + private final String methodName; + private final int expectedNumberOfParameters; + private final int typedParameter; + + public ReflectiveTypeFinder(String methodName, int expectedNumberOfParameters, int typedParameter) { + this.methodName = methodName; + this.expectedNumberOfParameters = expectedNumberOfParameters; + this.typedParameter = typedParameter; + } - public ReflectiveTypeFinder(String methodName, int expectedNumberOfParameters, int typedParameter) { - this.methodName = methodName; - this.expectedNumberOfParameters = expectedNumberOfParameters; - this.typedParameter = typedParameter; - } - - public Class findExpectedType(Class fromClass) { - for (Class c = fromClass; c != Object.class; c = c.getSuperclass()) { - for (Method method : c.getDeclaredMethods()) { - if (canObtainExpectedTypeFrom(method)) { - return expectedTypeFrom(method); + public Class findExpectedType(Class fromClass) { + for (Class c = fromClass; c != Object.class; c = c.getSuperclass()) { + for (Method method : c.getDeclaredMethods()) { + if (canObtainExpectedTypeFrom(method)) { + return expectedTypeFrom(method); + } } } + throw new Error("Cannot determine correct type for " + methodName + "() method."); } - throw new Error("Cannot determine correct type for " + methodName + "() method."); - } - - /** - * @param method The method to examine. - * @return true if this method references the relevant type - */ - private boolean canObtainExpectedTypeFrom(Method method) { - return method.getName().equals(methodName) - && method.getParameterTypes().length == expectedNumberOfParameters - && !method.isSynthetic(); - } + /** + * @param method The method to examine. + * @return true if this method references the relevant type + */ + private boolean canObtainExpectedTypeFrom(Method method) { + return method.getName().equals(methodName) + && method.getParameterTypes().length == expectedNumberOfParameters + && !method.isSynthetic(); + } - /** - * @param method The method from which to extract - * @return The type we're looking for - */ - private Class expectedTypeFrom(Method method) { - return method.getParameterTypes()[typedParameter]; - } + /** + * @param method The method from which to extract + * @return The type we're looking for + */ + private Class expectedTypeFrom(Method method) { + return method.getParameterTypes()[typedParameter]; + } } diff --git a/hamcrest/src/main/java/org/hamcrest/internal/SelfDescribingValue.java b/hamcrest/src/main/java/org/hamcrest/internal/SelfDescribingValue.java index 6537018a..3be01523 100644 --- a/hamcrest/src/main/java/org/hamcrest/internal/SelfDescribingValue.java +++ b/hamcrest/src/main/java/org/hamcrest/internal/SelfDescribingValue.java @@ -1,11 +1,46 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.internal; import org.hamcrest.Description; import org.hamcrest.SelfDescribing; +/** + * A self describing value. + * @param the value type + */ public class SelfDescribingValue implements SelfDescribing { private T value; - + public SelfDescribingValue(T value) { this.value = value; } diff --git a/hamcrest/src/main/java/org/hamcrest/internal/SelfDescribingValueIterator.java b/hamcrest/src/main/java/org/hamcrest/internal/SelfDescribingValueIterator.java index bc8f8f43..00ba1336 100644 --- a/hamcrest/src/main/java/org/hamcrest/internal/SelfDescribingValueIterator.java +++ b/hamcrest/src/main/java/org/hamcrest/internal/SelfDescribingValueIterator.java @@ -1,16 +1,50 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.internal; -import org.hamcrest.SelfDescribing; - import java.util.Iterator; +import org.hamcrest.SelfDescribing; +/** + * A self-describing iterator. + * @param the type of values + */ public class SelfDescribingValueIterator implements Iterator { private Iterator values; - + public SelfDescribingValueIterator(Iterator values) { this.values = values; } - + @Override public boolean hasNext() { return values.hasNext(); diff --git a/hamcrest/src/main/java/org/hamcrest/io/FileMatchers.java b/hamcrest/src/main/java/org/hamcrest/io/FileMatchers.java index 88288b07..d56a2eb0 100644 --- a/hamcrest/src/main/java/org/hamcrest/io/FileMatchers.java +++ b/hamcrest/src/main/java/org/hamcrest/io/FileMatchers.java @@ -1,15 +1,47 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.io; +import java.io.File; +import java.io.IOException; import org.hamcrest.Description; import org.hamcrest.FeatureMatcher; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; - -import java.io.File; -import java.io.IOException; - import static org.hamcrest.core.IsEqual.equalTo; +/** + * File matchers. + */ public final class FileMatchers { public static Matcher anExistingDirectory() { @@ -38,19 +70,26 @@ public static Matcher aFileWithSize(long size) { public static Matcher aFileWithSize(final Matcher expected) { return new FeatureMatcher(expected, "A file with size", "size") { - @Override protected Long featureValueOf(File actual) { return actual.length(); } + @Override + protected Long featureValueOf(File actual) { + return actual.length(); + } }; } public static Matcher aFileNamed(final Matcher expected) { return new FeatureMatcher(expected, "A file with name", "name") { - @Override protected String featureValueOf(File actual) { return actual.getName(); } + @Override + protected String featureValueOf(File actual) { + return actual.getName(); + } }; } public static Matcher aFileWithCanonicalPath(final Matcher expected) { return new FeatureMatcher(expected, "A file with canonical path", "path") { - @Override protected String featureValueOf(File actual) { + @Override + protected String featureValueOf(File actual) { try { return actual.getCanonicalPath(); } catch (IOException e) { @@ -62,31 +101,52 @@ public static Matcher aFileWithCanonicalPath(final Matcher expecte public static Matcher aFileWithAbsolutePath(final Matcher expected) { return new FeatureMatcher(expected, "A file with absolute path", "path") { - @Override protected String featureValueOf(File actual) { return actual.getAbsolutePath(); } + @Override + protected String featureValueOf(File actual) { + return actual.getAbsolutePath(); + } }; } + /** + * A file status matcher. + */ public static interface FileStatus { boolean check(File actual); } public static final FileStatus CAN_WRITE = new FileStatus() { - @Override public boolean check(File actual) { return actual.canWrite(); } + @Override + public boolean check(File actual) { + return actual.canWrite(); + } }; public static final FileStatus CAN_READ = new FileStatus() { - @Override public boolean check(File actual) { return actual.canRead(); } + @Override + public boolean check(File actual) { + return actual.canRead(); + } }; public static final FileStatus IS_FILE = new FileStatus() { - @Override public boolean check(File actual) { return actual.isFile(); } + @Override + public boolean check(File actual) { + return actual.isFile(); + } }; public static final FileStatus IS_DIRECTORY = new FileStatus() { - @Override public boolean check(File actual) { return actual.isDirectory(); } + @Override + public boolean check(File actual) { + return actual.isDirectory(); + } }; public static final FileStatus EXISTS = new FileStatus() { - @Override public boolean check(File actual) { return actual.exists(); } + @Override + public boolean check(File actual) { + return actual.exists(); + } }; private static Matcher fileChecker(final FileStatus fileStatus, final String successDescription, final String failureDescription) { diff --git a/hamcrest/src/main/java/org/hamcrest/number/BigDecimalCloseTo.java b/hamcrest/src/main/java/org/hamcrest/number/BigDecimalCloseTo.java index d9cb0264..8b48be6d 100644 --- a/hamcrest/src/main/java/org/hamcrest/number/BigDecimalCloseTo.java +++ b/hamcrest/src/main/java/org/hamcrest/number/BigDecimalCloseTo.java @@ -1,63 +1,96 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.number; +import java.math.BigDecimal; +import java.math.MathContext; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; -import java.math.BigDecimal; -import java.math.MathContext; - +/** + * A matcher for closeness of {@link BigDecimal}s. + */ public class BigDecimalCloseTo extends TypeSafeMatcher { + private final BigDecimal delta; + private final BigDecimal value; + + public BigDecimalCloseTo(BigDecimal value, BigDecimal error) { + this.delta = error; + this.value = value; + } + + @Override + public boolean matchesSafely(BigDecimal item) { + return actualDelta(item).compareTo(BigDecimal.ZERO) <= 0; + } + + @Override + public void describeMismatchSafely(BigDecimal item, Description mismatchDescription) { + mismatchDescription.appendValue(item) + .appendText(" differed by ") + .appendValue(actualDelta(item)) + .appendText(" more than delta ") + .appendValue(delta); + } + + @Override + public void describeTo(Description description) { + description.appendText("a numeric value within ") + .appendValue(delta) + .appendText(" of ") + .appendValue(value); + } + + private BigDecimal actualDelta(BigDecimal item) { + return item.subtract(value, MathContext.DECIMAL128).abs().subtract(delta, MathContext.DECIMAL128).stripTrailingZeros(); + } - private final BigDecimal delta; - private final BigDecimal value; - - public BigDecimalCloseTo(BigDecimal value, BigDecimal error) { - this.delta = error; - this.value = value; - } - - @Override - public boolean matchesSafely(BigDecimal item) { - return actualDelta(item).compareTo(BigDecimal.ZERO) <= 0; - } - - @Override - public void describeMismatchSafely(BigDecimal item, Description mismatchDescription) { - mismatchDescription.appendValue(item) - .appendText(" differed by ") - .appendValue(actualDelta(item)) - .appendText(" more than delta ") - .appendValue(delta); - } - - @Override - public void describeTo(Description description) { - description.appendText("a numeric value within ") - .appendValue(delta) - .appendText(" of ") - .appendValue(value); - } - - private BigDecimal actualDelta(BigDecimal item) { - return item.subtract(value, MathContext.DECIMAL128).abs().subtract(delta, MathContext.DECIMAL128).stripTrailingZeros(); - } - - /** - * Creates a matcher of {@link java.math.BigDecimal}s that matches when an examined BigDecimal is equal - * to the specified operand, within a range of +/- error. The comparison for equality - * is done by BigDecimals {@link java.math.BigDecimal#compareTo(java.math.BigDecimal)} method. - * For example: - *
assertThat(new BigDecimal("1.03"), is(closeTo(new BigDecimal("1.0"), new BigDecimal("0.03"))))
- * - * @param operand - * the expected value of matching BigDecimals - * @param error - * the delta (+/-) within which matches will be allowed - */ - public static Matcher closeTo(BigDecimal operand, BigDecimal error) { - return new BigDecimalCloseTo(operand, error); - } + /** + * Creates a matcher of {@link java.math.BigDecimal}s that matches when an examined BigDecimal is equal + * to the specified operand, within a range of +/- error. The comparison for equality + * is done by BigDecimals {@link java.math.BigDecimal#compareTo(java.math.BigDecimal)} method. + * For example: + *
assertThat(new BigDecimal("1.03"), is(closeTo(new BigDecimal("1.0"), new BigDecimal("0.03"))))
+ * + * @param operand + * the expected value of matching BigDecimals + * @param error + * the delta (+/-) within which matches will be allowed + * @return the created matcher + */ + public static Matcher closeTo(BigDecimal operand, BigDecimal error) { + return new BigDecimalCloseTo(operand, error); + } } diff --git a/hamcrest/src/main/java/org/hamcrest/number/IsCloseTo.java b/hamcrest/src/main/java/org/hamcrest/number/IsCloseTo.java index 3b6967dc..8cee93b6 100644 --- a/hamcrest/src/main/java/org/hamcrest/number/IsCloseTo.java +++ b/hamcrest/src/main/java/org/hamcrest/number/IsCloseTo.java @@ -1,12 +1,41 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.number; +import static java.lang.Math.abs; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; -import static java.lang.Math.abs; - - /** * Is the value a number equal to a value within some range of * acceptable error? @@ -27,11 +56,11 @@ public boolean matchesSafely(Double item) { @Override public void describeMismatchSafely(Double item, Description mismatchDescription) { - mismatchDescription.appendValue(item) - .appendText(" differed by ") - .appendValue(actualDelta(item)) - .appendText(" more than delta ") - .appendValue(delta); + mismatchDescription.appendValue(item) + .appendText(" differed by ") + .appendValue(actualDelta(item)) + .appendText(" more than delta ") + .appendValue(delta); } @Override @@ -43,7 +72,7 @@ public void describeTo(Description description) { } private double actualDelta(Double item) { - return abs(item - value) - delta; + return abs(item - value) - delta; } /** @@ -51,11 +80,12 @@ private double actualDelta(Double item) { * to the specified operand, within a range of +/- error. * For example: *
assertThat(1.03, is(closeTo(1.0, 0.03)))
- * + * * @param operand * the expected value of matching doubles * @param error * the delta (+/-) within which matches will be allowed + * @return the created matcher */ public static Matcher closeTo(double operand, double error) { return new IsCloseTo(operand, error); diff --git a/hamcrest/src/main/java/org/hamcrest/number/IsNaN.java b/hamcrest/src/main/java/org/hamcrest/number/IsNaN.java index 415a9a2b..c78179a8 100644 --- a/hamcrest/src/main/java/org/hamcrest/number/IsNaN.java +++ b/hamcrest/src/main/java/org/hamcrest/number/IsNaN.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.number; import org.hamcrest.Description; @@ -31,6 +62,7 @@ public void describeTo(Description description) { * Creates a matcher of {@link Double}s that matches when an examined double is not a number. * For example: *
assertThat(Double.NaN, is(notANumber()))
+ * @return the created matcher */ public static Matcher notANumber() { return new IsNaN(); diff --git a/hamcrest/src/main/java/org/hamcrest/number/OrderingComparison.java b/hamcrest/src/main/java/org/hamcrest/number/OrderingComparison.java index 8a77713d..9a6ed8d9 100644 --- a/hamcrest/src/main/java/org/hamcrest/number/OrderingComparison.java +++ b/hamcrest/src/main/java/org/hamcrest/number/OrderingComparison.java @@ -1,8 +1,42 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.number; import org.hamcrest.Matcher; import org.hamcrest.comparator.ComparatorMatcherBuilder; +/** + * Compares ordering. + */ public class OrderingComparison { private OrderingComparison() { @@ -15,7 +49,9 @@ private OrderingComparison() { * For example: *
assertThat(1, comparesEqualTo(1))
* + * @param the matcher type * @param value the value which, when passed to the compareTo method of the examined object, should return zero + * @return the created matcher */ public static > Matcher comparesEqualTo(T value) { return ComparatorMatcherBuilder.usingNaturalOrdering().comparesEqualTo(value); @@ -28,8 +64,10 @@ public static > Matcher comparesEqualTo(T value) { * For example: *
assertThat(2, greaterThan(1))
* + * @param the matcher type * @param value the value which, when passed to the compareTo method of the examined object, should return greater * than zero + * @return the created matcher */ public static > Matcher greaterThan(T value) { return ComparatorMatcherBuilder.usingNaturalOrdering().greaterThan(value); @@ -42,8 +80,10 @@ public static > Matcher greaterThan(T value) { * For example: *
assertThat(1, greaterThanOrEqualTo(1))
* + * @param the matcher type * @param value the value which, when passed to the compareTo method of the examined object, should return greater * than or equal to zero + * @return the created matcher */ public static > Matcher greaterThanOrEqualTo(T value) { return ComparatorMatcherBuilder.usingNaturalOrdering().greaterThanOrEqualTo(value); @@ -56,8 +96,10 @@ public static > Matcher greaterThanOrEqualTo(T value) * For example: *
assertThat(1, lessThan(2))
* + * @param the matcher type * @param value the value which, when passed to the compareTo method of the examined object, should return less * than zero + * @return the created matcher */ public static > Matcher lessThan(T value) { return ComparatorMatcherBuilder.usingNaturalOrdering().lessThan(value); @@ -70,8 +112,10 @@ public static > Matcher lessThan(T value) { * For example: *
assertThat(1, lessThanOrEqualTo(1))
* + * @param the matcher type * @param value the value which, when passed to the compareTo method of the examined object, should return less * than or equal to zero + * @return the created matcher */ public static > Matcher lessThanOrEqualTo(T value) { return ComparatorMatcherBuilder.usingNaturalOrdering().lessThanOrEqualTo(value); diff --git a/hamcrest/src/main/java/org/hamcrest/object/HasEqualValues.java b/hamcrest/src/main/java/org/hamcrest/object/HasEqualValues.java index cffea890..44b1e032 100644 --- a/hamcrest/src/main/java/org/hamcrest/object/HasEqualValues.java +++ b/hamcrest/src/main/java/org/hamcrest/object/HasEqualValues.java @@ -1,17 +1,50 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.object; +import static java.lang.String.format; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; import org.hamcrest.Description; import org.hamcrest.DiagnosingMatcher; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; import org.hamcrest.core.IsEqual; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import static java.lang.String.format; - +/** + * A matcher for equal values. + * @param the matcher type + */ public class HasEqualValues extends TypeSafeDiagnosingMatcher { private final T expectedObject; private final List fieldMatchers; @@ -81,6 +114,4 @@ private static Object uncheckedGet(Field field, Object object) { throw new AssertionError(format("IllegalAccess, reading field '%s' from %s", field.getName(), object)); } } - - } diff --git a/hamcrest/src/main/java/org/hamcrest/object/HasToString.java b/hamcrest/src/main/java/org/hamcrest/object/HasToString.java index 2dab9de4..eed0221f 100644 --- a/hamcrest/src/main/java/org/hamcrest/object/HasToString.java +++ b/hamcrest/src/main/java/org/hamcrest/object/HasToString.java @@ -1,18 +1,53 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.object; import org.hamcrest.FeatureMatcher; import org.hamcrest.Matcher; - import static org.hamcrest.core.IsEqual.equalTo; +/** + * A matcher to check whether has a {@code toString} implementation. + * @param the matcher type + */ public class HasToString extends FeatureMatcher { + public HasToString(Matcher toStringMatcher) { - super(toStringMatcher, "with toString()", "toString()"); + super(toStringMatcher, "with toString()", "toString()"); } - + @Override protected String featureValueOf(T actual) { - return String.valueOf(actual); + return String.valueOf(actual); } /** @@ -20,12 +55,14 @@ protected String featureValueOf(T actual) { * returns a value that satisfies the specified matcher. * For example: *
assertThat(true, hasToString(equalTo("TRUE")))
- * + * + * @param the matcher type * @param toStringMatcher * the matcher used to verify the toString result + * @return the created matcher */ public static Matcher hasToString(Matcher toStringMatcher) { - return new HasToString(toStringMatcher); + return new HasToString<>(toStringMatcher); } /** @@ -33,11 +70,13 @@ public static Matcher hasToString(Matcher toStringMatcher * returns a value equalTo the specified string. * For example: *
assertThat(true, hasToString("TRUE"))
- * + * + * @param the matcher type * @param expectedToString * the expected toString result + * @return the created matcher */ public static Matcher hasToString(String expectedToString) { - return new HasToString(equalTo(expectedToString)); + return new HasToString<>(equalTo(expectedToString)); } } diff --git a/hamcrest/src/main/java/org/hamcrest/object/IsCompatibleType.java b/hamcrest/src/main/java/org/hamcrest/object/IsCompatibleType.java index e1410a47..c66152b1 100644 --- a/hamcrest/src/main/java/org/hamcrest/object/IsCompatibleType.java +++ b/hamcrest/src/main/java/org/hamcrest/object/IsCompatibleType.java @@ -1,41 +1,78 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.object; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; +/** + * A matcher for class compatibility. + * @param the matcher type + */ public class IsCompatibleType extends TypeSafeMatcher> { private final Class type; - + public IsCompatibleType(Class type) { this.type = type; } - + @Override public boolean matchesSafely(Class cls) { return type.isAssignableFrom(cls); } - + @Override public void describeMismatchSafely(Class cls, Description mismatchDescription) { - mismatchDescription.appendValue(cls.getName()); + mismatchDescription.appendValue(cls.getName()); } - + @Override public void describeTo(Description description) { description.appendText("type < ").appendText(type.getName()); } - + /** * Creates a matcher of {@link Class} that matches when the specified baseType is * assignable from the examined class. * For example: *
assertThat(Integer.class, typeCompatibleWith(Number.class))
- * + * + * @param the type to compare to * @param baseType * the base class to examine classes against + * @return the created matcher */ public static Matcher> typeCompatibleWith(Class baseType) { - return new IsCompatibleType(baseType); + return new IsCompatibleType<>(baseType); } } diff --git a/hamcrest/src/main/java/org/hamcrest/object/IsEventFrom.java b/hamcrest/src/main/java/org/hamcrest/object/IsEventFrom.java index 43b64d46..d582db7a 100644 --- a/hamcrest/src/main/java/org/hamcrest/object/IsEventFrom.java +++ b/hamcrest/src/main/java/org/hamcrest/object/IsEventFrom.java @@ -1,11 +1,41 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.object; +import java.util.EventObject; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; -import java.util.EventObject; - /** * Tests if the value is an event announced by a specific object. @@ -22,18 +52,17 @@ public IsEventFrom(Class eventClass, Object source) { @Override public boolean matchesSafely(EventObject item, Description mismatchDescription) { if (!eventClass.isInstance(item)) { - mismatchDescription.appendText("item type was " + item.getClass().getName()); - return false; + mismatchDescription.appendText("item type was " + item.getClass().getName()); + return false; } - + if (!eventHasSameSource(item)) { - mismatchDescription.appendText("source was ").appendValue(item.getSource()); - return false; + mismatchDescription.appendText("source was ").appendValue(item.getSource()); + return false; } return true; } - private boolean eventHasSameSource(EventObject ev) { return ev.getSource() == source; } @@ -51,11 +80,12 @@ public void describeTo(Description description) { * derived from eventClass announced by source. * For example: *
assertThat(myEvent, is(eventFrom(PropertyChangeEvent.class, myBean)))
- * + * * @param eventClass * the class of the event to match on * @param source * the source of the event + * @return the created matcher */ public static Matcher eventFrom(Class eventClass, Object source) { return new IsEventFrom(eventClass, source); @@ -66,9 +96,10 @@ public static Matcher eventFrom(Class eventC * announced by source. * For example: *
assertThat(myEvent, is(eventFrom(myBean)))
- * + * * @param source * the source of the event + * @return the created matcher */ public static Matcher eventFrom(Object source) { return eventFrom(EventObject.class, source); diff --git a/hamcrest/src/main/java/org/hamcrest/text/CharSequenceLength.java b/hamcrest/src/main/java/org/hamcrest/text/CharSequenceLength.java index e5e3d466..8d4df2a2 100644 --- a/hamcrest/src/main/java/org/hamcrest/text/CharSequenceLength.java +++ b/hamcrest/src/main/java/org/hamcrest/text/CharSequenceLength.java @@ -1,10 +1,40 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.text; +import static org.hamcrest.CoreMatchers.equalTo; import org.hamcrest.FeatureMatcher; import org.hamcrest.Matcher; -import static org.hamcrest.CoreMatchers.equalTo; - /** * @author Marco Leichsenring * @author Steve Freeman @@ -27,31 +57,33 @@ protected Integer featureValueOf(CharSequence actual) { /** * Creates a matcher of {@link CharSequence} that matches when a char sequence has the given length * For example: - * + * *
      * assertThat("text", hasLength(4))
      * 
- * + * * @param length the expected length of the string + * @return the created matcher */ public static Matcher hasLength(int length) { return new CharSequenceLength(equalTo(length)); } /** - * Creates a matcher of {@link CharSequence} that matches when a char sequence has the given length - * For example: - * - *
-      * assertThat("text", hasLength(lessThan(4)))
-      * 
- * - * @param lengthMatcher the expected length of the string - */ - @SuppressWarnings("WeakerAccess") - public static Matcher hasLength(Matcher lengthMatcher) { - return new CharSequenceLength(lengthMatcher); - } + * Creates a matcher of {@link CharSequence} that matches when a char sequence has the given length + * For example: + * + *
+     * assertThat("text", hasLength(lessThan(4)))
+     * 
+ * + * @param lengthMatcher the expected length of the string + * @return the created matcher + */ + @SuppressWarnings("WeakerAccess") + public static Matcher hasLength(Matcher lengthMatcher) { + return new CharSequenceLength(lengthMatcher); + } } diff --git a/hamcrest/src/main/java/org/hamcrest/text/IsBlankString.java b/hamcrest/src/main/java/org/hamcrest/text/IsBlankString.java index b168541b..783d28ad 100644 --- a/hamcrest/src/main/java/org/hamcrest/text/IsBlankString.java +++ b/hamcrest/src/main/java/org/hamcrest/text/IsBlankString.java @@ -1,12 +1,40 @@ - +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.text; +import java.util.regex.Pattern; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; - -import java.util.regex.Pattern; - import static org.hamcrest.core.AnyOf.anyOf; import static org.hamcrest.core.IsNull.nullValue; @@ -37,6 +65,7 @@ public void describeTo(Description description) { * zero or more whitespace characters and nothing else. * For example: *
assertThat("  ", is(blankString()))
+ * @return the created matcher */ public static Matcher blankString() { return BLANK_INSTANCE; @@ -47,7 +76,8 @@ public static Matcher blankString() { * contains zero or more whitespace characters and nothing else. * For example: *
assertThat(((String)null), is(blankOrNullString()))
- * + * + * @return the created matcher */ public static Matcher blankOrNullString() { return NULL_OR_BLANK_INSTANCE; diff --git a/hamcrest/src/main/java/org/hamcrest/text/IsEmptyString.java b/hamcrest/src/main/java/org/hamcrest/text/IsEmptyString.java index bbe56814..e526b79a 100644 --- a/hamcrest/src/main/java/org/hamcrest/text/IsEmptyString.java +++ b/hamcrest/src/main/java/org/hamcrest/text/IsEmptyString.java @@ -1,10 +1,39 @@ - +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.text; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; - import static org.hamcrest.core.AnyOf.anyOf; import static org.hamcrest.core.IsNull.nullValue; @@ -32,7 +61,8 @@ public void describeTo(Description description) { * Creates a matcher of {@link String} that matches when the examined string has zero length. * For example: *
assertThat("", isEmptyString())
- * + * + * @return the created matcher * @deprecated use is(emptyString()) instead */ @Deprecated @@ -44,7 +74,8 @@ public static Matcher isEmptyString() { * Creates a matcher of {@link String} that matches when the examined string has zero length. * For example: *
assertThat("", is(emptyString()))
- * + * + * @return the created matcher */ public static Matcher emptyString() { return INSTANCE; @@ -55,9 +86,9 @@ public static Matcher emptyString() { * has zero length. * For example: *
assertThat(((String)null), isEmptyOrNullString())
- * + * + * @return the created matcher * @deprecated use is(emptyOrNullString()) instead - * */ @Deprecated public static Matcher isEmptyOrNullString() { @@ -69,7 +100,8 @@ public static Matcher isEmptyOrNullString() { * has zero length. * For example: *
assertThat(((String)null), is(emptyOrNullString()))
- * + * + * @return the created matcher */ public static Matcher emptyOrNullString() { return NULL_OR_EMPTY_INSTANCE; diff --git a/hamcrest/src/main/java/org/hamcrest/text/IsEqualCompressingWhiteSpace.java b/hamcrest/src/main/java/org/hamcrest/text/IsEqualCompressingWhiteSpace.java index c3e0d7b1..ebd51fba 100644 --- a/hamcrest/src/main/java/org/hamcrest/text/IsEqualCompressingWhiteSpace.java +++ b/hamcrest/src/main/java/org/hamcrest/text/IsEqualCompressingWhiteSpace.java @@ -1,11 +1,40 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.text; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; -import static java.lang.Character.isWhitespace; - /** * Tests if a string is equal to another string, compressing any changes in whitespace. */ @@ -27,12 +56,12 @@ public IsEqualCompressingWhiteSpace(String string) { public boolean matchesSafely(String item) { return stripSpaces(string).equals(stripSpaces(item)); } - + @Override public void describeMismatchSafely(String item, Description mismatchDescription) { - mismatchDescription.appendText("was ").appendValue(item); + mismatchDescription.appendText("was ").appendValue(item); } - + @Override public void describeTo(Description description) { description.appendText("a string equal to ") @@ -45,9 +74,10 @@ public String stripSpaces(String toBeStripped) { } /** - * @deprecated {@link #equalToCompressingWhiteSpace(String)} * @param expectedString * the expected value of matched strings + * @return the created matcher + * @deprecated {@link #equalToCompressingWhiteSpace(String)} */ public static Matcher equalToIgnoringWhiteSpace(String expectedString) { return new IsEqualCompressingWhiteSpace(expectedString); @@ -66,6 +96,7 @@ public static Matcher equalToIgnoringWhiteSpace(String expectedString) { * * @param expectedString * the expected value of matched strings + * @return the created matcher */ public static Matcher equalToCompressingWhiteSpace(String expectedString) { return new IsEqualCompressingWhiteSpace(expectedString); diff --git a/hamcrest/src/main/java/org/hamcrest/text/IsEqualIgnoringCase.java b/hamcrest/src/main/java/org/hamcrest/text/IsEqualIgnoringCase.java index defa6123..016ba1ba 100644 --- a/hamcrest/src/main/java/org/hamcrest/text/IsEqualIgnoringCase.java +++ b/hamcrest/src/main/java/org/hamcrest/text/IsEqualIgnoringCase.java @@ -1,3 +1,34 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.text; import org.hamcrest.Description; @@ -28,9 +59,9 @@ public boolean matchesSafely(String item) { @Override public void describeMismatchSafely(String item, Description mismatchDescription) { - mismatchDescription.appendText("was ").appendValue(item); + mismatchDescription.appendText("was ").appendValue(item); } - + @Override public void describeTo(Description description) { description.appendText("a string equal to ") @@ -43,9 +74,10 @@ public void describeTo(Description description) { * the specified expectedString, ignoring case. * For example: *
assertThat("Foo", equalToIgnoringCase("FOO"))
- * + * * @param expectedString * the expected value of matched strings + * @return the created matcher */ public static Matcher equalToIgnoringCase(String expectedString) { return new IsEqualIgnoringCase(expectedString); diff --git a/hamcrest/src/main/java/org/hamcrest/text/MatchesPattern.java b/hamcrest/src/main/java/org/hamcrest/text/MatchesPattern.java index e0eda0a8..9af37cea 100644 --- a/hamcrest/src/main/java/org/hamcrest/text/MatchesPattern.java +++ b/hamcrest/src/main/java/org/hamcrest/text/MatchesPattern.java @@ -1,11 +1,44 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.text; +import java.util.regex.Pattern; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; -import java.util.regex.Pattern; - +/** + * A matcher for regular expression patterns. + */ public class MatchesPattern extends TypeSafeMatcher { private final Pattern pattern; @@ -26,6 +59,8 @@ public void describeTo(Description description) { /** * Creates a matcher of {@link java.lang.String} that matches when the examined string * exactly matches the given {@link java.util.regex.Pattern}. + * @param pattern the regular expression to create the matcher for + * @return the created matcher */ public static Matcher matchesPattern(Pattern pattern) { return new MatchesPattern(pattern); @@ -34,6 +69,8 @@ public static Matcher matchesPattern(Pattern pattern) { /** * Creates a matcher of {@link java.lang.String} that matches when the examined string * exactly matches the given regular expression, treated as a {@link java.util.regex.Pattern}. + * @param regex the regular expression to create the matcher for + * @return the created matcher */ public static Matcher matchesPattern(String regex) { return new MatchesPattern(Pattern.compile(regex)); diff --git a/hamcrest/src/main/java/org/hamcrest/text/StringContainsInOrder.java b/hamcrest/src/main/java/org/hamcrest/text/StringContainsInOrder.java index 6df9a531..10c2e899 100644 --- a/hamcrest/src/main/java/org/hamcrest/text/StringContainsInOrder.java +++ b/hamcrest/src/main/java/org/hamcrest/text/StringContainsInOrder.java @@ -1,11 +1,44 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.text; +import java.util.Arrays; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; -import java.util.Arrays; - +/** + * A Matcher to check whether a string is contained. + */ public class StringContainsInOrder extends TypeSafeMatcher { private final Iterable substrings; @@ -16,7 +49,7 @@ public StringContainsInOrder(Iterable substrings) { @Override public boolean matchesSafely(String s) { int fromIndex = 0; - + for (String substring : substrings) { fromIndex = s.indexOf(substring, fromIndex); if (fromIndex == -1) { @@ -24,31 +57,32 @@ public boolean matchesSafely(String s) { } fromIndex++; } - + return true; } - + @Override public void describeMismatchSafely(String item, Description mismatchDescription) { mismatchDescription.appendText("was \"").appendText(item).appendText("\""); } - + @Override public void describeTo(Description description) { description.appendText("a string containing ") .appendValueList("", ", ", "", substrings) .appendText(" in order"); } - + /** * Creates a matcher of {@link String} that matches when the examined string contains all of * the specified substrings, considering the order of their appearance. * For example: *
assertThat("myfoobarbaz", stringContainsInOrder(Arrays.asList("bar", "foo")))
* fails as "foo" occurs before "bar" in the string "myfoobarbaz" - * + * * @param substrings * the substrings that must be contained within matching strings + * @return the created matcher */ public static Matcher stringContainsInOrder(Iterable substrings) { return new StringContainsInOrder(substrings); @@ -63,6 +97,7 @@ public static Matcher stringContainsInOrder(Iterable substrings) * * @param substrings * the substrings that must be contained within matching strings + * @return the created matcher */ public static Matcher stringContainsInOrder(String... substrings) { return new StringContainsInOrder(Arrays.asList(substrings)); diff --git a/hamcrest/src/main/java/org/hamcrest/xml/HasXPath.java b/hamcrest/src/main/java/org/hamcrest/xml/HasXPath.java index 30ed081a..2ed8e166 100644 --- a/hamcrest/src/main/java/org/hamcrest/xml/HasXPath.java +++ b/hamcrest/src/main/java/org/hamcrest/xml/HasXPath.java @@ -1,20 +1,53 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.xml; +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import static javax.xml.xpath.XPathConstants.STRING; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; import org.hamcrest.Condition; +import static org.hamcrest.Condition.matched; +import static org.hamcrest.Condition.notMatched; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; import org.hamcrest.core.IsAnything; import org.w3c.dom.Node; -import javax.xml.namespace.NamespaceContext; -import javax.xml.namespace.QName; -import javax.xml.xpath.*; - -import static javax.xml.xpath.XPathConstants.STRING; -import static org.hamcrest.Condition.matched; -import static org.hamcrest.Condition.notMatched; - /** * Applies a Matcher to a given XML Node in an existing XML Node tree, specified by an XPath expression. * @@ -111,11 +144,12 @@ private static XPathExpression compiledXPath(String xPathExpression, NamespaceCo * specified xPath that satisfies the specified valueMatcher. * For example: *
assertThat(xml, hasXPath("/root/something[2]/cheese", equalTo("Cheddar")))
- * + * * @param xPath * the target xpath * @param valueMatcher * matcher for the value at the specified xpath + * @return the created matcher */ public static Matcher hasXPath(String xPath, Matcher valueMatcher) { return hasXPath(xPath, NO_NAMESPACE_CONTEXT, valueMatcher); @@ -127,13 +161,14 @@ public static Matcher hasXPath(String xPath, Matcher valueMatcher) * the specified valueMatcher. * For example: *
assertThat(xml, hasXPath("/root/something[2]/cheese", myNs, equalTo("Cheddar")))
- * + * * @param xPath * the target xpath * @param namespaceContext * the namespace for matching nodes * @param valueMatcher * matcher for the value at the specified xpath + * @return the created matcher */ public static Matcher hasXPath(String xPath, NamespaceContext namespaceContext, Matcher valueMatcher) { return new HasXPath(xPath, namespaceContext, valueMatcher, STRING); @@ -144,9 +179,10 @@ public static Matcher hasXPath(String xPath, NamespaceContext namespaceCon * at the specified xPath, with any content. * For example: *
assertThat(xml, hasXPath("/root/something[2]/cheese"))
- * + * * @param xPath * the target xpath + * @return the created matcher */ public static Matcher hasXPath(String xPath) { return hasXPath(xPath, NO_NAMESPACE_CONTEXT); @@ -157,11 +193,12 @@ public static Matcher hasXPath(String xPath) { * at the specified xPath within the specified namespace context, with any content. * For example: *
assertThat(xml, hasXPath("/root/something[2]/cheese", myNs))
- * + * * @param xPath * the target xpath * @param namespaceContext * the namespace for matching nodes + * @return the created matcher */ public static Matcher hasXPath(String xPath, NamespaceContext namespaceContext) { return new HasXPath(xPath, namespaceContext, WITH_ANY_CONTENT, XPathConstants.NODE); diff --git a/hamcrest/src/test/java/org/hamcrest/AbstractMatcherTest.java b/hamcrest/src/test/java/org/hamcrest/AbstractMatcherTest.java index f11dec3b..b38ed6f9 100644 --- a/hamcrest/src/test/java/org/hamcrest/AbstractMatcherTest.java +++ b/hamcrest/src/test/java/org/hamcrest/AbstractMatcherTest.java @@ -1,77 +1,113 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; import junit.framework.TestCase; import org.junit.Assert; +/** + * Common methods of matcher tests. + */ public abstract class AbstractMatcherTest extends TestCase { - /** - * Create an instance of the Matcher so some generic safety-net tests can be run on it. - */ - protected abstract Matcher createMatcher(); - - public static void assertMatches(Matcher matcher, T arg) { - assertMatches("Expected match, but mismatched", matcher, arg); - } - - public static void assertMatches(String message, Matcher matcher, Object arg) { - if (!matcher.matches(arg)) { - Assert.fail(message + " because: '" + mismatchDescription(matcher, arg) + "'"); + /** + * Create an instance of the Matcher so some generic safety-net tests can be run on it. + */ + protected abstract Matcher createMatcher(); + + public static void assertMatches(Matcher matcher, T arg) { + assertMatches("Expected match, but mismatched", matcher, arg); + } + + public static void assertMatches(String message, Matcher matcher, Object arg) { + if (!matcher.matches(arg)) { + Assert.fail(message + " because: '" + mismatchDescription(matcher, arg) + "'"); + } + } + + public static void assertDoesNotMatch(Matcher c, T arg) { + assertDoesNotMatch("Unexpected match", c, arg); + } + + public static void assertDoesNotMatch(String message, Matcher c, T arg) { + Assert.assertFalse(message, c.matches(arg)); + } + + public static void assertDescription(String expected, Matcher matcher) { + Description description = new StringDescription(); + description.appendDescriptionOf(matcher); + Assert.assertEquals("Expected description", expected, description.toString().trim()); + } + + public static void assertMismatchDescription(String expected, Matcher matcher, Object arg) { + Assert.assertFalse("Precondition: Matcher should not match item.", matcher.matches(arg)); + Assert.assertEquals("Expected mismatch description", expected, mismatchDescription(matcher, arg)); + } + + public static void assertNullSafe(Matcher matcher) { + try { + matcher.matches(null); + } catch (Exception e) { + Assert.fail("Matcher was not null safe"); + } + } + + public static void assertUnknownTypeSafe(Matcher matcher) { + try { + matcher.matches(new UnknownType()); + } catch (Exception e) { + Assert.fail("Matcher was not unknown type safe, because: " + e); + } + } + + public void testIsNullSafe() { + assertNullSafe(createMatcher()); + } + + public void testCopesWithUnknownTypes() { + createMatcher().matches(new UnknownType()); } - } - - public static void assertDoesNotMatch(Matcher c, T arg) { - assertDoesNotMatch("Unexpected match", c, arg); - } - - public static void assertDoesNotMatch(String message, Matcher c, T arg) { - Assert.assertFalse(message, c.matches(arg)); - } - - public static void assertDescription(String expected, Matcher matcher) { - Description description = new StringDescription(); - description.appendDescriptionOf(matcher); - Assert.assertEquals("Expected description", expected, description.toString().trim()); - } - - public static void assertMismatchDescription(String expected, Matcher matcher, Object arg) { - Assert.assertFalse("Precondition: Matcher should not match item.", matcher.matches(arg)); - Assert.assertEquals("Expected mismatch description", expected, mismatchDescription(matcher, arg)); - } - - public static void assertNullSafe(Matcher matcher) { - try { - matcher.matches(null); - } - catch (Exception e) { - Assert.fail("Matcher was not null safe"); - } - } - - public static void assertUnknownTypeSafe(Matcher matcher) { - try { - matcher.matches(new UnknownType()); - } catch (Exception e) { - Assert.fail("Matcher was not unknown type safe, because: " + e); - } - } - - public void testIsNullSafe() { - assertNullSafe(createMatcher()); - } - - public void testCopesWithUnknownTypes() { - createMatcher().matches(new UnknownType()); - } private static String mismatchDescription(Matcher matcher, Object arg) { - Description description = new StringDescription(); - matcher.describeMismatch(arg, description); - return description.toString().trim(); + Description description = new StringDescription(); + matcher.describeMismatch(arg, description); + return description.toString().trim(); } - @SuppressWarnings("WeakerAccess") - public static class UnknownType { - } + /** + * Unknown type implementation. + */ + @SuppressWarnings("WeakerAccess") + public static class UnknownType { + } } diff --git a/hamcrest/src/test/java/org/hamcrest/BaseDescriptionTest.java b/hamcrest/src/test/java/org/hamcrest/BaseDescriptionTest.java index afbdd65f..776ff821 100644 --- a/hamcrest/src/test/java/org/hamcrest/BaseDescriptionTest.java +++ b/hamcrest/src/test/java/org/hamcrest/BaseDescriptionTest.java @@ -1,112 +1,147 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +/** + * Base description test. + */ public final class BaseDescriptionTest { private final StringBuilder result = new StringBuilder(); private final BaseDescription baseDescription = new BaseDescription() { - @Override protected void append(char c) { + @Override + protected void append(char c) { result.append(c); } }; - @Test public void - describesAppendedNullValue() { + @Test + public void describesAppendedNullValue() { baseDescription.appendValue(null); assertEquals("null", result.toString()); } - @Test public void - quotesAppendedStringValue() { + @Test + public void quotesAppendedStringValue() { baseDescription.appendValue("foo"); assertEquals("\"foo\"", result.toString()); } - @Test public void - quotesAppendedCharacterValue() { + @Test + public void quotesAppendedCharacterValue() { baseDescription.appendValue('f'); assertEquals("\"f\"", result.toString()); } - @Test public void - quotesAppendedTab() { + @Test + public void quotesAppendedTab() { baseDescription.appendValue('\t'); assertEquals("\"\\t\"", result.toString()); } - @Test public void - quotesAppendedNewLine() { + @Test + public void quotesAppendedNewLine() { baseDescription.appendValue('\n'); assertEquals("\"\\n\"", result.toString()); } - @Test public void - quotesAppendedLineReturn() { + @Test + public void quotesAppendedLineReturn() { baseDescription.appendValue('\r'); assertEquals("\"\\r\"", result.toString()); } - @Test public void - quotesAppendedBackslash() { + @Test + public void quotesAppendedBackslash() { baseDescription.appendValue('\\'); assertEquals("\"\\\\\"", result.toString()); } - @Test public void - quotesAppendedDoubleQuotes() { + @Test + public void quotesAppendedDoubleQuotes() { baseDescription.appendValue('"'); assertEquals("\"\\\"\"", result.toString()); } - @Test public void - bracketsAppendedByteValue() { + @Test + public void bracketsAppendedByteValue() { baseDescription.appendValue(Byte.valueOf("2")); assertEquals("<2b>", result.toString()); } - @Test public void - bracketsAppendedShortValue() { + @Test + public void bracketsAppendedShortValue() { baseDescription.appendValue(Short.valueOf("2")); assertEquals("<2s>", result.toString()); } - @Test public void - bracketsAppendedLongValue() { + @Test + public void bracketsAppendedLongValue() { baseDescription.appendValue(Long.valueOf("2")); assertEquals("<2L>", result.toString()); } - @Test public void - bracketsAppendedFloatValue() { + @Test + public void bracketsAppendedFloatValue() { baseDescription.appendValue(Float.valueOf("1.2")); assertEquals("<1.2F>", result.toString()); } - @Test public void - describesAppendedArrayValue() { + @Test + public void describesAppendedArrayValue() { baseDescription.appendValue(new String[] {"2", "3"}); assertEquals("[\"2\", \"3\"]", result.toString()); } - @Test public void - bracketsAppendedObjectValue() { + @Test + public void bracketsAppendedObjectValue() { final Object value = new Object(); baseDescription.appendValue(value); assertEquals("<" + value.toString() + ">", result.toString()); } - - @Test public void - safelyDescribesAppendedValueOfObjectWhoseToStringThrowsAnException() { + + @Test + public void safelyDescribesAppendedValueOfObjectWhoseToStringThrowsAnException() { final Object value = new Object() { - @Override public String toString() { + @Override + public String toString() { throw new UnsupportedOperationException(); } }; - + final String expected = value.getClass().getName() + "@" + Integer.toHexString(value.hashCode()); baseDescription.appendValue(value); assertEquals("<" + expected + ">", result.toString()); diff --git a/hamcrest/src/test/java/org/hamcrest/BaseMatcherTest.java b/hamcrest/src/test/java/org/hamcrest/BaseMatcherTest.java index e663f041..1c4729a5 100644 --- a/hamcrest/src/test/java/org/hamcrest/BaseMatcherTest.java +++ b/hamcrest/src/test/java/org/hamcrest/BaseMatcherTest.java @@ -1,14 +1,46 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +/** + * The base matcher test. + */ public final class BaseMatcherTest { @Test - public void - describesItselfWithToStringMethod() { + public void describesItselfWithToStringMethod() { Matcher someMatcher = new BaseMatcher() { @Override public boolean matches(Object item) { diff --git a/hamcrest/src/test/java/org/hamcrest/CustomMatcherTest.java b/hamcrest/src/test/java/org/hamcrest/CustomMatcherTest.java index 08649f7a..f64cbbdd 100644 --- a/hamcrest/src/test/java/org/hamcrest/CustomMatcherTest.java +++ b/hamcrest/src/test/java/org/hamcrest/CustomMatcherTest.java @@ -1,13 +1,46 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.assertDescription; +import org.junit.Test; +/** + * The custom matcher test. + */ public final class CustomMatcherTest { - @Test public void - usesStaticDescription() throws Exception { + @Test + public void usesStaticDescription() throws Exception { Matcher matcher = new CustomMatcher("I match strings") { @Override public boolean matches(Object item) { diff --git a/hamcrest/src/test/java/org/hamcrest/CustomTypeSafeMatcherTest.java b/hamcrest/src/test/java/org/hamcrest/CustomTypeSafeMatcherTest.java index 2c867126..81c23707 100644 --- a/hamcrest/src/test/java/org/hamcrest/CustomTypeSafeMatcherTest.java +++ b/hamcrest/src/test/java/org/hamcrest/CustomTypeSafeMatcherTest.java @@ -1,9 +1,42 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.junit.Test; +/** + * Custom type safe matcher test. + */ public final class CustomTypeSafeMatcherTest { private static final String STATIC_DESCRIPTION = "I match non empty strings"; @@ -19,23 +52,23 @@ public void describeMismatchSafely(String item, Description mismatchDescription) } }; - @Test public void - usesStaticDescription() throws Exception { + @Test + public void usesStaticDescription() throws Exception { assertDescription(STATIC_DESCRIPTION, customMatcher); } - @Test public void - reportsMismatch() { + @Test + public void reportsMismatch() { assertMismatchDescription("an item", customMatcher, "item"); } - @Test public void - isNullSafe() { + @Test + public void isNullSafe() { assertNullSafe(customMatcher); } - - @Test public void - copesWithUnknownTypes() { + + @Test + public void copesWithUnknownTypes() { assertUnknownTypeSafe(customMatcher); } } diff --git a/hamcrest/src/test/java/org/hamcrest/FeatureMatcherTest.java b/hamcrest/src/test/java/org/hamcrest/FeatureMatcherTest.java index 8d864eb8..e2cbcbce 100644 --- a/hamcrest/src/test/java/org/hamcrest/FeatureMatcherTest.java +++ b/hamcrest/src/test/java/org/hamcrest/FeatureMatcherTest.java @@ -1,45 +1,89 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; -import org.hamcrest.core.IsEqual; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.core.IsEqual; import static org.junit.Assert.assertEquals; +import org.junit.Test; +/** + * The feature matcher test. + */ public final class FeatureMatcherTest { private final FeatureMatcher resultMatcher = resultMatcher(); - @Test public void - matchesPartOfAnObject() { + @Test + public void matchesPartOfAnObject() { assertMatches("feature", resultMatcher, new Thingy("bar")); assertDescription("Thingy with result \"bar\"", resultMatcher); } - @Test public void - mismatchesPartOfAnObject() { + @Test + public void mismatchesPartOfAnObject() { assertMismatchDescription("result mismatch-description", resultMatcher, new Thingy("foo")); } - @Test public void - doesNotThrowNullPointerException() { + @Test + public void doesNotThrowNullPointerException() { assertMismatchDescription("was null", resultMatcher, null); } - @Test public void - doesNotThrowClassCastException() { + @Test + public void doesNotThrowClassCastException() { resultMatcher.matches(new ShouldNotMatch()); - StringDescription mismatchDescription = new StringDescription(); + StringDescription mismatchDescription = new StringDescription(); resultMatcher.describeMismatch(new ShouldNotMatch(), mismatchDescription); assertEquals("was ShouldNotMatch ", mismatchDescription.toString()); } + /** + * Match implementation of {@link IsEqual}. + */ public static class Match extends IsEqual { - public Match(String equalArg) { super(equalArg); } - @Override public void describeMismatch(Object item, Description description) { + + public Match(String equalArg) { + super(equalArg); + } + + @Override + public void describeMismatch(Object item, Description description) { description.appendText("mismatch-description"); } } + /** + * The thingy implementation. + */ public static class Thingy { private final String result; @@ -52,9 +96,16 @@ public String getResult() { } } + /** + * The should not match implementation. + */ public static class ShouldNotMatch { - @Override public String toString() { return "ShouldNotMatch"; } - } + + @Override + public String toString() { + return "ShouldNotMatch"; + } + } private static FeatureMatcher resultMatcher() { return new FeatureMatcher(new Match("bar"), "Thingy with result", "result") { diff --git a/hamcrest/src/test/java/org/hamcrest/MatcherAssertTest.java b/hamcrest/src/test/java/org/hamcrest/MatcherAssertTest.java index b57c4d77..4b0ce69f 100644 --- a/hamcrest/src/test/java/org/hamcrest/MatcherAssertTest.java +++ b/hamcrest/src/test/java/org/hamcrest/MatcherAssertTest.java @@ -1,15 +1,48 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; -import org.junit.Test; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.*; +import org.junit.Test; +/** + * The matcher assert test. + */ public final class MatcherAssertTest { - @Test public void - includesDescriptionOfTestedValueInErrorMessage() { + @Test + public void includesDescriptionOfTestedValueInErrorMessage() { String expected = "expected"; String actual = "actual"; @@ -17,8 +50,7 @@ public final class MatcherAssertTest { try { assertThat("identifier", actual, equalTo(expected)); - } - catch (AssertionError e) { + } catch (AssertionError e) { assertTrue(e.getMessage().startsWith(expectedMessage)); return; } @@ -26,8 +58,8 @@ public final class MatcherAssertTest { fail("should have failed"); } - @Test public void - descriptionCanBeElided() { + @Test + public void descriptionCanBeElided() { String expected = "expected"; String actual = "actual"; @@ -35,8 +67,7 @@ public final class MatcherAssertTest { try { assertThat(actual, equalTo(expected)); - } - catch (AssertionError e) { + } catch (AssertionError e) { assertTrue(e.getMessage().startsWith(expectedMessage)); return; } @@ -44,14 +75,13 @@ public final class MatcherAssertTest { fail("should have failed"); } - @Test public void - canTestBooleanDirectly() { + @Test + public void canTestBooleanDirectly() { assertThat("success reason message", true); try { assertThat("failing reason message", false); - } - catch (AssertionError e) { + } catch (AssertionError e) { assertEquals("failing reason message", e.getMessage()); return; } @@ -59,8 +89,8 @@ public final class MatcherAssertTest { fail("should have failed"); } - @Test public void - includesMismatchDescription() { + @Test + public void includesMismatchDescription() { Matcher matcherWithCustomMismatchDescription = new BaseMatcher() { @Override public boolean matches(Object item) { @@ -83,14 +113,13 @@ public void describeMismatch(Object item, Description mismatchDescription) { try { assertThat("Value", matcherWithCustomMismatchDescription); fail("should have failed"); - } - catch (AssertionError e) { + } catch (AssertionError e) { assertEquals(expectedMessage, e.getMessage()); } } - @Test public void - canAssertSubtypes() { + @Test + public void canAssertSubtypes() { assertThat(1, equalTo((Number) 1)); } } diff --git a/hamcrest/src/test/java/org/hamcrest/NullDescriptionTest.java b/hamcrest/src/test/java/org/hamcrest/NullDescriptionTest.java index cccece0a..616ab369 100644 --- a/hamcrest/src/test/java/org/hamcrest/NullDescriptionTest.java +++ b/hamcrest/src/test/java/org/hamcrest/NullDescriptionTest.java @@ -1,16 +1,49 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; import org.hamcrest.Description.NullDescription; -import org.junit.Test; - import static org.junit.Assert.assertEquals; +import org.junit.Test; +/** + * The null description test. + */ public final class NullDescriptionTest { private final NullDescription nullDescription = new Description.NullDescription(); - @Test public void - isUnchangedByAppendedText() { + @Test + public void isUnchangedByAppendedText() { nullDescription.appendText("myText"); assertEquals("", nullDescription.toString()); } diff --git a/hamcrest/src/test/java/org/hamcrest/TypeSafeDiagnosingMatcherTest.java b/hamcrest/src/test/java/org/hamcrest/TypeSafeDiagnosingMatcherTest.java index 0b001391..aa8be166 100644 --- a/hamcrest/src/test/java/org/hamcrest/TypeSafeDiagnosingMatcherTest.java +++ b/hamcrest/src/test/java/org/hamcrest/TypeSafeDiagnosingMatcherTest.java @@ -1,8 +1,38 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.junit.Test; /** * @author Steve Freeman 2016 http://www.hamcrest.com @@ -10,38 +40,41 @@ @SuppressWarnings("WeakerAccess") public class TypeSafeDiagnosingMatcherTest { - @Test public void - describesMismatches() { + @Test + public void describesMismatches() { assertMismatchDescription("was null", STRING_MATCHER, null); assertMismatchDescription("was Character \"c\"", STRING_MATCHER, 'c'); assertMismatchDescription("mismatching", STRING_MATCHER, "other"); } - @Test public void - detects_non_builtin_types() { - final Matcher matcher = new TypeSafeDiagnosingMatcher() { - @Override - protected boolean matchesSafely(NotBuiltIn item, Description mismatchDescription) { - return true; - } + @Test + public void detectsNonBuiltinTypes() { + final Matcher matcher = new TypeSafeDiagnosingMatcher() { + @Override + protected boolean matchesSafely(NotBuiltIn item, Description mismatchDescription) { + return true; + } - @Override public void describeTo(Description description) { description.appendText("a not builtin"); } - }; + @Override + public void describeTo(Description description) { + description.appendText("a not builtin"); + } + }; - assertMatches("not built in", matcher, new NotBuiltIn()); - assertDoesNotMatch("other not built in", (Matcher)matcher, new OtherNotBuiltIn()); + assertMatches("not built in", matcher, new NotBuiltIn()); + assertDoesNotMatch("other not built in", (Matcher)matcher, new OtherNotBuiltIn()); } - @Test public void - filters_type_for_subclassed_matcher_when_expected_type_passed_in() { - final Matcher matcher = new SubMatcher<>(new NotBuiltIn()); + @Test + public void filtersTypeForSubclassedMatcherWhenExpectedTypePassedIn() { + final Matcher matcher = new SubMatcher<>(new NotBuiltIn()); - assertMatches("not built in", matcher, new NotBuiltIn()); - assertDoesNotMatch("other not built in", (Matcher)matcher, new OtherNotBuiltIn()); - } + assertMatches("not built in", matcher, new NotBuiltIn()); + assertDoesNotMatch("other not built in", (Matcher)matcher, new OtherNotBuiltIn()); + } - @Test public void - but_cannot_detect_generic_type_in_subclassed_matcher_using_reflection() { + @Test + public void butCannotDetectGenericTypeInSubclassedMatcherUsingReflection() { final Matcher matcher = new SubMatcher<>(); assertMatches("not built in", matcher, new NotBuiltIn()); @@ -51,31 +84,55 @@ protected boolean matchesSafely(NotBuiltIn item, Description mismatchDescription private static final TypeSafeDiagnosingMatcher STRING_MATCHER = new TypeSafeDiagnosingMatcher() { @Override protected boolean matchesSafely(String item, Description mismatchDescription) { - mismatchDescription.appendText("mismatching"); - return false; + mismatchDescription.appendText("mismatching"); + return false; } @Override - public void describeTo(Description description) { } + public void describeTo(Description description) { + } }; + /** + * The submatcher implementation. + * @param the matcher type + */ public static class SubMatcher extends TypeSafeDiagnosingMatcher { - public SubMatcher() { - super(); - } - public SubMatcher(T expectedObject) { - super(expectedObject.getClass()); - } - @Override protected boolean matchesSafely(T item, Description mismatchDescription) { return true; } - @Override public void describeTo(Description description) { description.appendText("sub type"); } + + public SubMatcher() { + super(); + } + + public SubMatcher(T expectedObject) { + super(expectedObject.getClass()); + } + + @Override + protected boolean matchesSafely(T item, Description mismatchDescription) { + return true; + } + + @Override + public void describeTo(Description description) { + description.appendText("sub type"); + } } + /** + * A not-built-in implementation. + */ public static class NotBuiltIn { - public final String value = "not built in"; - @Override public String toString() { return "NotBuiltIn"; } + public final String value = "not built in"; + + @Override + public String toString() { + return "NotBuiltIn"; + } } + /** + * Another not-build-in implementation. + */ public static class OtherNotBuiltIn { // empty } - } diff --git a/hamcrest/src/test/java/org/hamcrest/TypeSafeMatcherTest.java b/hamcrest/src/test/java/org/hamcrest/TypeSafeMatcherTest.java index 5563fabc..889f4066 100644 --- a/hamcrest/src/test/java/org/hamcrest/TypeSafeMatcherTest.java +++ b/hamcrest/src/test/java/org/hamcrest/TypeSafeMatcherTest.java @@ -1,14 +1,50 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.assertMismatchDescription; import static org.junit.Assert.assertFalse; +import org.junit.Test; +/** + * Type safe matcher test. + */ @SuppressWarnings("WeakerAccess") public final class TypeSafeMatcherTest { private final Matcher matcher = new TypeSafeMatcherSubclass(); + /** + * The type safe matcher subclass implementation. + */ public static class TypeSafeMatcherSubclass extends TypeSafeMatcher { @Override public boolean matchesSafely(String item) { @@ -17,7 +53,7 @@ public boolean matchesSafely(String item) { @Override public void describeMismatchSafely(String item, Description mismatchDescription) { - mismatchDescription.appendText("The mismatch"); + mismatchDescription.appendText("The mismatch"); } @Override @@ -25,17 +61,17 @@ public void describeTo(Description description) { } } - @Test public void - canDetermineMatcherTypeFromProtectedMatchesSafelyMethod() { + @Test + public void canDetermineMatcherTypeFromProtectedMatchesSafelyMethod() { assertFalse(matcher.matches(null)); assertFalse(matcher.matches(10)); } @SuppressWarnings({ "unchecked", "rawtypes" }) - @Test public void - describesMismatches() { - assertMismatchDescription("was null", matcher, null); - assertMismatchDescription("was a java.lang.Integer (<3>)", (Matcher)matcher, 3); - assertMismatchDescription("The mismatch", matcher, "a string"); + @Test + public void describesMismatches() { + assertMismatchDescription("was null", matcher, null); + assertMismatchDescription("was a java.lang.Integer (<3>)", (Matcher)matcher, 3); + assertMismatchDescription("The mismatch", matcher, "a string"); } } diff --git a/hamcrest/src/test/java/org/hamcrest/beans/HasPropertyTest.java b/hamcrest/src/test/java/org/hamcrest/beans/HasPropertyTest.java index 11813106..60c637c1 100644 --- a/hamcrest/src/test/java/org/hamcrest/beans/HasPropertyTest.java +++ b/hamcrest/src/test/java/org/hamcrest/beans/HasPropertyTest.java @@ -1,10 +1,40 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.beans; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.beans.HasProperty.hasProperty; +import org.junit.Test; /** * @author Iain McGinniss @@ -17,31 +47,31 @@ public final class HasPropertyTest { private final HasPropertyWithValueTest.BeanWithoutInfo bean = new HasPropertyWithValueTest.BeanWithoutInfo("a bean", false); - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = hasProperty("irrelevant"); - + assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - @Test public void - matchesWhenThePropertyExists() { + @Test + public void matchesWhenThePropertyExists() { assertMatches(hasProperty("writeOnlyProperty"), bean); } - @Test public void - doesNotMatchIfPropertyDoesNotExist() { + @Test + public void doesNotMatchIfPropertyDoesNotExist() { assertDoesNotMatch(hasProperty("aNonExistentProp"), bean); } - @Test public void - describesItself() { + @Test + public void describesItself() { assertDescription("hasProperty(\"property\")", hasProperty("property")); } - @Test public void - describesAMismatch() { + @Test + public void describesAMismatch() { assertMismatchDescription("no \"aNonExistentProp\" in <[Person: a bean]>", hasProperty("aNonExistentProp"), bean); } diff --git a/hamcrest/src/test/java/org/hamcrest/beans/HasPropertyWithValueTest.java b/hamcrest/src/test/java/org/hamcrest/beans/HasPropertyWithValueTest.java index d5f427e6..a906ed26 100644 --- a/hamcrest/src/test/java/org/hamcrest/beans/HasPropertyWithValueTest.java +++ b/hamcrest/src/test/java/org/hamcrest/beans/HasPropertyWithValueTest.java @@ -1,17 +1,46 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.beans; -import org.hamcrest.*; -import org.hamcrest.core.IsEqual; - import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; import java.beans.SimpleBeanInfo; - +import org.hamcrest.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.beans.HasPropertyWithValue.hasProperty; import static org.hamcrest.beans.HasPropertyWithValue.hasPropertyAtPath; import static org.hamcrest.core.IsAnything.anything; +import org.hamcrest.core.IsEqual; import static org.hamcrest.core.IsEqual.equalTo; /** @@ -22,163 +51,197 @@ */ @SuppressWarnings("UnusedDeclaration") public class HasPropertyWithValueTest extends AbstractMatcherTest { - private final BeanWithoutInfo shouldMatch = new BeanWithoutInfo("is expected", true); - private final BeanWithoutInfo shouldNotMatch = new BeanWithoutInfo("not expected", false); + private final BeanWithoutInfo shouldMatch = new BeanWithoutInfo("is expected", true); + private final BeanWithoutInfo shouldNotMatch = new BeanWithoutInfo("not expected", false); - private final BeanWithInfo beanWithInfo = new BeanWithInfo("with info"); + private final BeanWithInfo beanWithInfo = new BeanWithInfo("with info"); - @Override - protected Matcher createMatcher() { - return hasProperty("irrelevant", anything()); - } - - public void testMatchesBeanWithoutInfoWithMatchedNamedProperty() { - final Matcher propertyMatcher = hasProperty("property", equalTo("is expected")); - - assertMatches("with property", propertyMatcher, shouldMatch); - assertMismatchDescription("property 'property' was \"not expected\"", propertyMatcher, shouldNotMatch); - } + @Override + protected Matcher createMatcher() { + return hasProperty("irrelevant", anything()); + } - public void testMatchesBeanWithoutInfoWithMatchedNamedBooleanProperty() { - final Matcher booleanPropertyMatcher = hasProperty("booleanProperty", is(true)); + public void testMatchesBeanWithoutInfoWithMatchedNamedProperty() { + final Matcher propertyMatcher = hasProperty("property", equalTo("is expected")); - assertMatches("with property", booleanPropertyMatcher, shouldMatch); - assertMismatchDescription("property 'booleanProperty' was ", booleanPropertyMatcher, shouldNotMatch); - } + assertMatches("with property", propertyMatcher, shouldMatch); + assertMismatchDescription("property 'property' was \"not expected\"", propertyMatcher, shouldNotMatch); + } - public void testMatchesBeanWithInfoWithMatchedNamedProperty() { - assertMatches("with bean info", hasProperty("property", equalTo("with info")), beanWithInfo); - assertMismatchDescription("property 'property' was \"with info\"", - hasProperty("property", equalTo("without info")), beanWithInfo); - } + public void testMatchesBeanWithoutInfoWithMatchedNamedBooleanProperty() { + final Matcher booleanPropertyMatcher = hasProperty("booleanProperty", is(true)); - public void testDoesNotMatchBeanWithoutInfoOrMatchedNamedProperty() { - assertMismatchDescription("No property \"nonExistentProperty\"", - hasProperty("nonExistentProperty", anything()), shouldNotMatch); - } + assertMatches("with property", booleanPropertyMatcher, shouldMatch); + assertMismatchDescription("property 'booleanProperty' was ", booleanPropertyMatcher, shouldNotMatch); + } - public void testDoesNotMatchWriteOnlyProperty() { - assertMismatchDescription("property \"writeOnlyProperty\" is not readable", - hasProperty("writeOnlyProperty", anything()), shouldNotMatch); - } + public void testMatchesBeanWithInfoWithMatchedNamedProperty() { + assertMatches("with bean info", hasProperty("property", equalTo("with info")), beanWithInfo); + assertMismatchDescription("property 'property' was \"with info\"", + hasProperty("property", equalTo("without info")), beanWithInfo); + } - public void testMatchesPath() { - assertMatches("1-step path", hasPropertyAtPath("property", equalTo("is expected")), shouldMatch); - assertMatches("2-step path", hasPropertyAtPath("inner.property", equalTo("is expected")), new BeanWithInner(shouldMatch)); - assertMatches("3-step path", hasPropertyAtPath("inner.inner.property", equalTo("is expected")), new BeanWithInner(new BeanWithInner(shouldMatch))); + public void testDoesNotMatchBeanWithoutInfoOrMatchedNamedProperty() { + assertMismatchDescription("No property \"nonExistentProperty\"", + hasProperty("nonExistentProperty", anything()), shouldNotMatch); + } - assertMismatchDescription("inner.No property \"wrong\"", hasPropertyAtPath("inner.wrong.property", anything()), new BeanWithInner(new BeanWithInner(shouldMatch))); - assertMismatchDescription("inner.inner.property.was \"not expected\"", hasPropertyAtPath("inner.inner.property", equalTo("something")), new BeanWithInner(new BeanWithInner(shouldNotMatch))); - } + public void testDoesNotMatchWriteOnlyProperty() { + assertMismatchDescription("property \"writeOnlyProperty\" is not readable", + hasProperty("writeOnlyProperty", anything()), shouldNotMatch); + } - public void testDescribeTo() { - assertDescription("hasProperty(\"property\", )", hasProperty("property", equalTo(true))); - } + public void testMatchesPath() { + assertMatches("1-step path", hasPropertyAtPath("property", equalTo("is expected")), shouldMatch); + assertMatches("2-step path", hasPropertyAtPath("inner.property", equalTo("is expected")), new BeanWithInner(shouldMatch)); + assertMatches("3-step path", hasPropertyAtPath("inner.inner.property", equalTo("is expected")), new BeanWithInner(new BeanWithInner(shouldMatch))); - public void testMatchesPropertyAndValue() { - assertMatches("property with value", hasProperty("property", anything()), beanWithInfo); - } - - public void testDoesNotWriteMismatchIfPropertyMatches() { - Description description = new StringDescription(); - hasProperty( "property", anything()).describeMismatch(beanWithInfo, description); - assertEquals("Expected mismatch description", "", description.toString()); - } + assertMismatchDescription("inner.No property \"wrong\"", hasPropertyAtPath("inner.wrong.property", anything()), new BeanWithInner(new BeanWithInner(shouldMatch))); + assertMismatchDescription("inner.inner.property.was \"not expected\"", hasPropertyAtPath("inner.inner.property", equalTo("something")), new BeanWithInner(new BeanWithInner(shouldNotMatch))); + } - public void testDescribesMissingPropertyMismatch() { - assertMismatchDescription("No property \"honk\"", hasProperty("honk", anything()), shouldNotMatch); - } + public void testDescribeTo() { + assertDescription("hasProperty(\"property\", )", hasProperty("property", equalTo(true))); + } - public void testExceptionsInBeanMethodsShouldBeReportedCorrectly() { - assertMismatchDescription( - "Calling 'public java.lang.String org.hamcrest.beans.HasPropertyWithValueTest$BeanWithBug.getBroken()': \"bean failed\"", - hasProperty("broken", anything()), - new BeanWithBug()); - } + public void testMatchesPropertyAndValue() { + assertMatches("property with value", hasProperty("property", anything()), beanWithInfo); + } + public void testDoesNotWriteMismatchIfPropertyMatches() { + Description description = new StringDescription(); + hasProperty( "property", anything()).describeMismatch(beanWithInfo, description); + assertEquals("Expected mismatch description", "", description.toString()); + } - public void testCanAccessAnAnonymousInnerClass() { - class X implements IX { - @Override - public int getTest() { - return 1; - } + public void testDescribesMissingPropertyMismatch() { + assertMismatchDescription("No property \"honk\"", hasProperty("honk", anything()), shouldNotMatch); } - assertThat(new X(), HasPropertyWithValue.hasProperty("test", IsEqual.equalTo(1))); - } + public void testExceptionsInBeanMethodsShouldBeReportedCorrectly() { + assertMismatchDescription( + "Calling 'public java.lang.String org.hamcrest.beans.HasPropertyWithValueTest$BeanWithBug.getBroken()': \"bean failed\"", + hasProperty("broken", anything()), + new BeanWithBug()); + } - interface IX { - int getTest(); - } - @SuppressWarnings("WeakerAccess") - public static class BeanWithoutInfo { - private String property; - private final boolean booleanProperty; + public void testCanAccessAnAnonymousInnerClass() { + class X implements IX { + @Override + public int getTest() { + return 1; + } + } - public BeanWithoutInfo(String property, boolean booleanProperty) { - this.property = property; - this.booleanProperty = booleanProperty; + assertThat(new X(), HasPropertyWithValue.hasProperty("test", IsEqual.equalTo(1))); } - public String getProperty() { - return property; + interface IX { + int getTest(); } - public void setProperty(String property) { - this.property = property; + /** + * Bean without info implementation. + */ + @SuppressWarnings("WeakerAccess") + public static class BeanWithoutInfo { + private String property; + private final boolean booleanProperty; + + public BeanWithoutInfo(String property, boolean booleanProperty) { + this.property = property; + this.booleanProperty = booleanProperty; + } + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } + + public boolean isBooleanProperty() { + return booleanProperty; + } + + public void setWriteOnlyProperty(@SuppressWarnings("unused") float property) { + } + + @Override + public String toString() { + return "[Person: " + property + "]"; + } } - public boolean isBooleanProperty() { return booleanProperty; } + /** + * Bean with inner implementation. + */ + @SuppressWarnings("WeakerAccess") + public static class BeanWithInner { + private final Object inner; + + public BeanWithInner(Object inner) { + this.inner = inner; + } - public void setWriteOnlyProperty(@SuppressWarnings("unused") float property) { + public Object getInner() { + return inner; + } } - @Override - public String toString() { - return "[Person: " + property + "]"; + /** + * Bean with info implementation. + */ + @SuppressWarnings("WeakerAccess") + public static class BeanWithInfo { + private final String propertyValue; + + public BeanWithInfo(String propertyValue) { + this.propertyValue = propertyValue; + } + + public String property() { + return propertyValue; + } } - } - @SuppressWarnings("WeakerAccess") - public static class BeanWithInner { - private final Object inner; + /** + * Bean with info bean implementation. + */ + public static class BeanWithInfoBeanInfo extends SimpleBeanInfo { + @Override + public PropertyDescriptor[] getPropertyDescriptors() { + try { + return new PropertyDescriptor[] { + new PropertyDescriptor("property", BeanWithInfo.class, "property", null) + }; + } catch (IntrospectionException e) { + throw new AssertionError("Introspection exception", e); + } + } + } - public BeanWithInner(Object inner) { this.inner = inner; } - public Object getInner() { return inner; } - } + /** + * Bean with bug implementation. + */ + @SuppressWarnings("WeakerAccess") + public static class BeanWithBug { - @SuppressWarnings("WeakerAccess") - public static class BeanWithInfo { - private final String propertyValue; + public String getBroken() { + throw new BeanFailed(); + } + } - public BeanWithInfo(String propertyValue) { this.propertyValue = propertyValue; } - public String property() { return propertyValue; } - } + /** + * Bean failed implementation. + */ + @SuppressWarnings("WeakerAccess") + public static class BeanFailed extends RuntimeException { - public static class BeanWithInfoBeanInfo extends SimpleBeanInfo { - @Override - public PropertyDescriptor[] getPropertyDescriptors() { - try { - return new PropertyDescriptor[] { - new PropertyDescriptor("property", BeanWithInfo.class, "property", null) - }; - } catch (IntrospectionException e) { - throw new AssertionError("Introspection exception", e); - } - } - } - - @SuppressWarnings("WeakerAccess") - public static class BeanWithBug { - public String getBroken() { - throw new BeanFailed(); - } - } - - @SuppressWarnings("WeakerAccess") - public static class BeanFailed extends RuntimeException { - public BeanFailed() { super("bean failed"); } - } + public BeanFailed() { + super("bean failed"); + } + } } diff --git a/hamcrest/src/test/java/org/hamcrest/beans/SamePropertyValuesAsTest.java b/hamcrest/src/test/java/org/hamcrest/beans/SamePropertyValuesAsTest.java index caecb684..6e28e161 100644 --- a/hamcrest/src/test/java/org/hamcrest/beans/SamePropertyValuesAsTest.java +++ b/hamcrest/src/test/java/org/hamcrest/beans/SamePropertyValuesAsTest.java @@ -1,131 +1,184 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.beans; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - import static org.hamcrest.beans.SamePropertyValuesAs.samePropertyValuesAs; +/** + * Same property values as test. + */ @SuppressWarnings("WeakerAccess") public class SamePropertyValuesAsTest extends AbstractMatcherTest { - private static final Value aValue = new Value("expected"); - private static final ExampleBean expectedBean = new ExampleBean("same", 1, aValue); - private static final ExampleBean actualBean = new ExampleBean("same", 1, aValue); - - - @Override - protected Matcher createMatcher() { - return samePropertyValuesAs(expectedBean); - } - - public void test_reports_match_when_all_properties_match() { - assertMatches("matched properties", samePropertyValuesAs(expectedBean), actualBean); - } - - public void test_reports_mismatch_when_actual_type_is_not_assignable_to_expected_type() { - assertMismatchDescription("is incompatible type: ExampleBean", - samePropertyValuesAs((Object)aValue), actualBean); - } - - public void test_reports_mismatch_on_first_property_difference() { - assertMismatchDescription("stringProperty was \"different\"", - samePropertyValuesAs(expectedBean), new ExampleBean("different", 1, aValue)); - assertMismatchDescription("intProperty was <2>", - samePropertyValuesAs(expectedBean), new ExampleBean("same", 2, aValue)); - assertMismatchDescription("valueProperty was ", - samePropertyValuesAs(expectedBean), new ExampleBean("same", 1, new Value("other"))); - } - - public void test_matches_beans_with_inheritance_but_no_extra_properties() { - assertMatches("sub type with same properties", - samePropertyValuesAs(expectedBean), new SubBeanWithNoExtraProperties("same", 1, aValue)); - } - - public void test_rejects_subtype_that_has_extra_properties() { - assertMismatchDescription("has extra properties called [extraProperty]", - samePropertyValuesAs(expectedBean), new SubBeanWithExtraProperty("same", 1, aValue)); - } - - public void test_ignores_extra_subtype_properties() { - final SubBeanWithExtraProperty withExtraProperty = new SubBeanWithExtraProperty("same", 1, aValue); - assertMatches("extra property", samePropertyValuesAs(expectedBean, "extraProperty"), withExtraProperty); - } - - public void test_ignores_different_properties() { - final ExampleBean differentBean = new ExampleBean("different", 1, aValue); - assertMatches("different property", samePropertyValuesAs(expectedBean, "stringProperty"), differentBean); - } - - public void test_accepts_missing_properties_to_ignore() { - assertMatches("ignored property", samePropertyValuesAs(expectedBean, "notAProperty"), actualBean); - } - - public void test_can_ignore_all_properties() { - final ExampleBean differentBean = new ExampleBean("different", 2, new Value("not expected")); - assertMatches( - "different property", - samePropertyValuesAs(expectedBean, "stringProperty", "intProperty", "valueProperty"), - differentBean); - } - - - public void testDescribesItself() { - assertDescription( - "same property values as ExampleBean [intProperty: <1>, stringProperty: \"same\", valueProperty: ]", - samePropertyValuesAs(expectedBean)); - - assertDescription( - "same property values as ExampleBean [intProperty: <1>, stringProperty: \"same\", valueProperty: ] ignoring [\"ignored1\", \"ignored2\"]", - samePropertyValuesAs(expectedBean, "ignored1", "ignored2")); - } - - public static class Value { - public Value(Object value) { - this.value = value; - } + private static final Value A_VALUE = new Value("expected"); + private static final ExampleBean EXPECTED_BEAN = new ExampleBean("same", 1, A_VALUE); + private static final ExampleBean ACTUAL_BEAN = new ExampleBean("same", 1, A_VALUE); - public final Object value; @Override - public String toString() { - return "Value " + value; + protected Matcher createMatcher() { + return samePropertyValuesAs(EXPECTED_BEAN); + } + + public void testReportsMatchWhenAllPropertiesMatch() { + assertMatches("matched properties", samePropertyValuesAs(EXPECTED_BEAN), ACTUAL_BEAN); + } + + public void testReportsMismatchWhenActualTypeIsNotAssignableToExpectedType() { + assertMismatchDescription("is incompatible type: ExampleBean", + samePropertyValuesAs((Object)A_VALUE), ACTUAL_BEAN); + } + + public void testReportsMismatchOnFirstPropertyDifference() { + assertMismatchDescription("stringProperty was \"different\"", + samePropertyValuesAs(EXPECTED_BEAN), new ExampleBean("different", 1, A_VALUE)); + assertMismatchDescription("intProperty was <2>", + samePropertyValuesAs(EXPECTED_BEAN), new ExampleBean("same", 2, A_VALUE)); + assertMismatchDescription("valueProperty was ", + samePropertyValuesAs(EXPECTED_BEAN), new ExampleBean("same", 1, new Value("other"))); } - } - - @SuppressWarnings("unused") - public static class ExampleBean { - private String stringProperty; - private int intProperty; - private Value valueProperty; - - public ExampleBean(String stringProperty, int intProperty, Value valueProperty) { - this.stringProperty = stringProperty; - this.intProperty = intProperty; - this.valueProperty = valueProperty; + + public void testMatchesBeansWithInheritanceButNoExtraProperties() { + assertMatches("sub type with same properties", + samePropertyValuesAs(EXPECTED_BEAN), new SubBeanWithNoExtraProperties("same", 1, A_VALUE)); } - - public String getStringProperty() { - return stringProperty; + + public void testRejectsSubtypeThatHasExtraProperties() { + assertMismatchDescription("has extra properties called [extraProperty]", + samePropertyValuesAs(EXPECTED_BEAN), new SubBeanWithExtraProperty("same", 1, A_VALUE)); } - public int getIntProperty() { - return intProperty; + + public void testIgnoresExtraSubtypeProperties() { + final SubBeanWithExtraProperty withExtraProperty = new SubBeanWithExtraProperty("same", 1, A_VALUE); + assertMatches("extra property", samePropertyValuesAs(EXPECTED_BEAN, "extraProperty"), withExtraProperty); } - public Value getValueProperty() { - return valueProperty; + + public void testIgnoresDifferentProperties() { + final ExampleBean differentBean = new ExampleBean("different", 1, A_VALUE); + assertMatches("different property", samePropertyValuesAs(EXPECTED_BEAN, "stringProperty"), differentBean); } - @Override public String toString() { return "an ExampleBean"; } - } - - public static class SubBeanWithNoExtraProperties extends ExampleBean { - public SubBeanWithNoExtraProperties(String stringProperty, int intProperty, Value valueProperty) { - super(stringProperty, intProperty, valueProperty); + public void testAcceptsMissingPropertiesToIgnore() { + assertMatches("ignored property", samePropertyValuesAs(EXPECTED_BEAN, "notAProperty"), ACTUAL_BEAN); } - } - - public static class SubBeanWithExtraProperty extends ExampleBean { - public SubBeanWithExtraProperty(String stringProperty, int intProperty, Value valueProperty) { - super(stringProperty, intProperty, valueProperty); + + public void testCanIgnoreAllProperties() { + final ExampleBean differentBean = new ExampleBean("different", 2, new Value("not expected")); + assertMatches( + "different property", + samePropertyValuesAs(EXPECTED_BEAN, "stringProperty", "intProperty", "valueProperty"), + differentBean); } + + public void testDescribesItself() { + assertDescription( + "same property values as ExampleBean [intProperty: <1>, stringProperty: \"same\", valueProperty: ]", + samePropertyValuesAs(EXPECTED_BEAN)); + + assertDescription( + "same property values as ExampleBean [intProperty: <1>, stringProperty: \"same\", valueProperty: ] ignoring [\"ignored1\", \"ignored2\"]", + samePropertyValuesAs(EXPECTED_BEAN, "ignored1", "ignored2")); + } + + /** + * The value class. + */ + public static class Value { + public final Object value; + + public Value(Object value) { + this.value = value; + } + + @Override + public String toString() { + return "Value " + value; + } + } + + /** + * The example bean class. + */ @SuppressWarnings("unused") - public String getExtraProperty() { return "extra"; } - } + public static class ExampleBean { + private String stringProperty; + private int intProperty; + private Value valueProperty; + + public ExampleBean(String stringProperty, int intProperty, Value valueProperty) { + this.stringProperty = stringProperty; + this.intProperty = intProperty; + this.valueProperty = valueProperty; + } + + public String getStringProperty() { + return stringProperty; + } + + public int getIntProperty() { + return intProperty; + } + + public Value getValueProperty() { + return valueProperty; + } + + @Override + public String toString() { + return "an ExampleBean"; + } + } + + /** + * The sub bean with no extra properties implementation. + */ + public static class SubBeanWithNoExtraProperties extends ExampleBean { + + public SubBeanWithNoExtraProperties(String stringProperty, int intProperty, Value valueProperty) { + super(stringProperty, intProperty, valueProperty); + } + } + + /** + * The sub bean with extra properties implementation. + */ + public static class SubBeanWithExtraProperty extends ExampleBean { + public SubBeanWithExtraProperty(String stringProperty, int intProperty, Value valueProperty) { + super(stringProperty, intProperty, valueProperty); + } + + @SuppressWarnings("unused") + public String getExtraProperty() { + return "extra"; + } + } } diff --git a/hamcrest/src/test/java/org/hamcrest/collection/ArrayMatchingInAnyOrderTest.java b/hamcrest/src/test/java/org/hamcrest/collection/ArrayMatchingInAnyOrderTest.java index 572bf63d..09e613f8 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/ArrayMatchingInAnyOrderTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/ArrayMatchingInAnyOrderTest.java @@ -1,11 +1,43 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - -import static org.hamcrest.collection.ArrayMatching.arrayContainingInAnyOrder; import static org.hamcrest.core.IsEqual.equalTo; +/** + * Is array containing in any order test. + */ public class ArrayMatchingInAnyOrderTest extends AbstractMatcherTest { @SuppressWarnings("unchecked") @@ -19,25 +51,25 @@ public void testHasAReadableDescription() { assertDescription("[<1>, <2>] in any order", ArrayMatching.arrayContainingInAnyOrder(equalTo(1), equalTo(2))); assertDescription("[<1>, <2>] in any order", ArrayMatching.arrayContainingInAnyOrder(1, 2)); } - + public void testMatchesItemsInAnyOrder() { - assertMatches("in order", ArrayMatching.arrayContainingInAnyOrder(1, 2, 3), new Integer[] {1, 2, 3}); - assertMatches("out of order", ArrayMatching.arrayContainingInAnyOrder(1, 2, 3), new Integer[] {3, 2, 1}); - assertMatches("single", ArrayMatching.arrayContainingInAnyOrder(1), new Integer[] {1}); + assertMatches("in order", ArrayMatching.arrayContainingInAnyOrder(1, 2, 3), new Integer[] {1, 2, 3}); + assertMatches("out of order", ArrayMatching.arrayContainingInAnyOrder(1, 2, 3), new Integer[] {3, 2, 1}); + assertMatches("single", ArrayMatching.arrayContainingInAnyOrder(1), new Integer[] {1}); } @SuppressWarnings("unchecked") public void testAppliesMatchersInAnyOrder() { - assertMatches("in order", ArrayMatching.arrayContainingInAnyOrder(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {1, 2, 3}); - assertMatches("out of order", ArrayMatching.arrayContainingInAnyOrder(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {3, 2, 1}); - assertMatches("single", ArrayMatching.arrayContainingInAnyOrder(equalTo(1)), new Integer[] {1}); + assertMatches("in order", ArrayMatching.arrayContainingInAnyOrder(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {1, 2, 3}); + assertMatches("out of order", ArrayMatching.arrayContainingInAnyOrder(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {3, 2, 1}); + assertMatches("single", ArrayMatching.arrayContainingInAnyOrder(equalTo(1)), new Integer[] {1}); } public void testMismatchesItemsInAnyOrder() { - Matcher matcher = ArrayMatching.arrayContainingInAnyOrder(1, 2, 3); - assertMismatchDescription("was null", matcher, null); - assertMismatchDescription("no item matches: <1>, <2>, <3> in []", matcher, new Integer[] {}); - assertMismatchDescription("no item matches: <2>, <3> in [<1>]", matcher, new Integer[] {1}); - assertMismatchDescription("not matched: <4>", matcher, new Integer[] {4,3,2,1}); + Matcher matcher = ArrayMatching.arrayContainingInAnyOrder(1, 2, 3); + assertMismatchDescription("was null", matcher, null); + assertMismatchDescription("no item matches: <1>, <2>, <3> in []", matcher, new Integer[] {}); + assertMismatchDescription("no item matches: <2>, <3> in [<1>]", matcher, new Integer[] {1}); + assertMismatchDescription("not matched: <4>", matcher, new Integer[] {4,3,2,1}); } } diff --git a/hamcrest/src/test/java/org/hamcrest/collection/ArrayMatchingInOrderTest.java b/hamcrest/src/test/java/org/hamcrest/collection/ArrayMatchingInOrderTest.java index 784817a0..4aa6c931 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/ArrayMatchingInOrderTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/ArrayMatchingInOrderTest.java @@ -1,11 +1,44 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - import static org.hamcrest.collection.ArrayMatching.arrayContaining; import static org.hamcrest.core.IsEqual.equalTo; +/** + * Is array containing in order test. + */ public class ArrayMatchingInOrderTest extends AbstractMatcherTest { @SuppressWarnings("unchecked") @@ -18,28 +51,28 @@ protected Matcher createMatcher() { public void testHasAReadableDescription() { assertDescription("[<1>, <2>]", arrayContaining(equalTo(1), equalTo(2))); } - + public void testMatchesItemsInOrder() { - assertMatches("in order", arrayContaining(1, 2, 3), new Integer[] {1, 2, 3}); - assertMatches("single", arrayContaining(1), new Integer[] {1}); + assertMatches("in order", arrayContaining(1, 2, 3), new Integer[] {1, 2, 3}); + assertMatches("single", arrayContaining(1), new Integer[] {1}); } @SuppressWarnings("unchecked") public void testAppliesMatchersInOrder() { - assertMatches("in order", arrayContaining(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {1, 2, 3}); - assertMatches("single", arrayContaining(equalTo(1)), new Integer[] {1}); + assertMatches("in order", arrayContaining(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {1, 2, 3}); + assertMatches("single", arrayContaining(equalTo(1)), new Integer[] {1}); } - + public void testMismatchesItemsInOrder() { - Matcher matcher = arrayContaining(1, 2, 3); - assertMismatchDescription("was null", matcher, null); - assertMismatchDescription("no item was <1>", matcher, new Integer[] {}); - assertMismatchDescription("no item was <2>", matcher, new Integer[] {1}); - assertMismatchDescription("item 0: was <4>", matcher, new Integer[] {4,3,2,1}); - assertMismatchDescription("item 2: was <4>", matcher, new Integer[] {1,2, 4}); + Matcher matcher = arrayContaining(1, 2, 3); + assertMismatchDescription("was null", matcher, null); + assertMismatchDescription("no item was <1>", matcher, new Integer[] {}); + assertMismatchDescription("no item was <2>", matcher, new Integer[] {1}); + assertMismatchDescription("item 0: was <4>", matcher, new Integer[] {4,3,2,1}); + assertMismatchDescription("item 2: was <4>", matcher, new Integer[] {1,2, 4}); } public void testCanHandleNullValuesInAnArray() { - assertMatches("with nulls", arrayContaining(null, null), new Object[]{null, null}); + assertMatches("with nulls", arrayContaining(null, null), new Object[]{null, null}); } } diff --git a/hamcrest/src/test/java/org/hamcrest/collection/HasItemInArrayTest.java b/hamcrest/src/test/java/org/hamcrest/collection/HasItemInArrayTest.java index c4d7e34a..e02a69d5 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/HasItemInArrayTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/HasItemInArrayTest.java @@ -1,11 +1,44 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.collection.ArrayMatching.hasItemInArray; +/** + * Has item in array test. + */ public class HasItemInArrayTest extends AbstractMatcherTest { @Override diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsArrayContainingInAnyOrderTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsArrayContainingInAnyOrderTest.java index 01d9e3de..51051e07 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsArrayContainingInAnyOrderTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsArrayContainingInAnyOrderTest.java @@ -1,10 +1,40 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; -import static org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder; -import static org.hamcrest.core.IsEqual.equalTo; - import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; +import static org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder; +import static org.hamcrest.core.IsEqual.equalTo; public class IsArrayContainingInAnyOrderTest extends AbstractMatcherTest { @@ -19,25 +49,25 @@ public void testHasAReadableDescription() { assertDescription("[<1>, <2>] in any order", arrayContainingInAnyOrder(equalTo(1), equalTo(2))); assertDescription("[<1>, <2>] in any order", arrayContainingInAnyOrder(1, 2)); } - + public void testMatchesItemsInAnyOrder() { - assertMatches("in order", arrayContainingInAnyOrder(1, 2, 3), new Integer[] {1, 2, 3}); - assertMatches("out of order", arrayContainingInAnyOrder(1, 2, 3), new Integer[] {3, 2, 1}); - assertMatches("single", arrayContainingInAnyOrder(1), new Integer[] {1}); + assertMatches("in order", arrayContainingInAnyOrder(1, 2, 3), new Integer[] {1, 2, 3}); + assertMatches("out of order", arrayContainingInAnyOrder(1, 2, 3), new Integer[] {3, 2, 1}); + assertMatches("single", arrayContainingInAnyOrder(1), new Integer[] {1}); } @SuppressWarnings("unchecked") public void testAppliesMatchersInAnyOrder() { - assertMatches("in order", arrayContainingInAnyOrder(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {1, 2, 3}); - assertMatches("out of order", arrayContainingInAnyOrder(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {3, 2, 1}); - assertMatches("single", arrayContainingInAnyOrder(equalTo(1)), new Integer[] {1}); + assertMatches("in order", arrayContainingInAnyOrder(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {1, 2, 3}); + assertMatches("out of order", arrayContainingInAnyOrder(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {3, 2, 1}); + assertMatches("single", arrayContainingInAnyOrder(equalTo(1)), new Integer[] {1}); } public void testMismatchesItemsInAnyOrder() { - Matcher matcher = arrayContainingInAnyOrder(1, 2, 3); - assertMismatchDescription("was null", matcher, null); - assertMismatchDescription("no item matches: <1>, <2>, <3> in []", matcher, new Integer[] {}); - assertMismatchDescription("no item matches: <2>, <3> in [<1>]", matcher, new Integer[] {1}); - assertMismatchDescription("not matched: <4>", matcher, new Integer[] {4,3,2,1}); + Matcher matcher = arrayContainingInAnyOrder(1, 2, 3); + assertMismatchDescription("was null", matcher, null); + assertMismatchDescription("no item matches: <1>, <2>, <3> in []", matcher, new Integer[] {}); + assertMismatchDescription("no item matches: <2>, <3> in [<1>]", matcher, new Integer[] {1}); + assertMismatchDescription("not matched: <4>", matcher, new Integer[] {4,3,2,1}); } } diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsArrayContainingInOrderTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsArrayContainingInOrderTest.java index b719dd14..51e764fd 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsArrayContainingInOrderTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsArrayContainingInOrderTest.java @@ -1,10 +1,40 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; -import static org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining; -import static org.hamcrest.core.IsEqual.equalTo; - import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; +import static org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining; +import static org.hamcrest.core.IsEqual.equalTo; public class IsArrayContainingInOrderTest extends AbstractMatcherTest { @@ -18,24 +48,24 @@ protected Matcher createMatcher() { public void testHasAReadableDescription() { assertDescription("[<1>, <2>]", arrayContaining(equalTo(1), equalTo(2))); } - + public void testMatchesItemsInOrder() { - assertMatches("in order", arrayContaining(1, 2, 3), new Integer[] {1, 2, 3}); - assertMatches("single", arrayContaining(1), new Integer[] {1}); + assertMatches("in order", arrayContaining(1, 2, 3), new Integer[] {1, 2, 3}); + assertMatches("single", arrayContaining(1), new Integer[] {1}); } @SuppressWarnings("unchecked") public void testAppliesMatchersInOrder() { - assertMatches("in order", arrayContaining(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {1, 2, 3}); - assertMatches("single", arrayContaining(equalTo(1)), new Integer[] {1}); + assertMatches("in order", arrayContaining(equalTo(1), equalTo(2), equalTo(3)), new Integer[] {1, 2, 3}); + assertMatches("single", arrayContaining(equalTo(1)), new Integer[] {1}); } - + public void testMismatchesItemsInOrder() { - Matcher matcher = arrayContaining(1, 2, 3); - assertMismatchDescription("was null", matcher, null); - assertMismatchDescription("no item was <1>", matcher, new Integer[] {}); - assertMismatchDescription("no item was <2>", matcher, new Integer[] {1}); - assertMismatchDescription("item 0: was <4>", matcher, new Integer[] {4,3,2,1}); - assertMismatchDescription("item 2: was <4>", matcher, new Integer[] {1,2, 4}); + Matcher matcher = arrayContaining(1, 2, 3); + assertMismatchDescription("was null", matcher, null); + assertMismatchDescription("no item was <1>", matcher, new Integer[] {}); + assertMismatchDescription("no item was <2>", matcher, new Integer[] {1}); + assertMismatchDescription("item 0: was <4>", matcher, new Integer[] {4,3,2,1}); + assertMismatchDescription("item 2: was <4>", matcher, new Integer[] {1,2, 4}); } } diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsArrayTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsArrayTest.java index 4135d9f5..93620fe6 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsArrayTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsArrayTest.java @@ -1,13 +1,46 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.Matcher; - import static org.hamcrest.collection.IsArray.array; import static org.hamcrest.core.IsEqual.equalTo; +/** + * Is array test. + */ @SuppressWarnings("unchecked") public class IsArrayTest extends AbstractMatcherTest { @@ -20,37 +53,46 @@ public void testMatchesAnArrayThatMatchesAllTheElementMatchers() { assertMatches("should match array with matching elements", array(equalTo("a"), equalTo("b"), equalTo("c")), new String[]{"a", "b", "c"}); } - + public void testDoesNotMatchAnArrayWhenElementsDoNotMatch() { assertDoesNotMatch("should not match array with different elements", array(equalTo("a"), equalTo("b")), new String[]{"b", "c"}); } - + public void testDoesNotMatchAnArrayOfDifferentSize() { assertDoesNotMatch("should not match larger array", - array(equalTo("a"), equalTo("b")), new String[]{"a", "b", "c"}); + array(equalTo("a"), equalTo("b")), new String[]{"a", "b", "c"}); assertDoesNotMatch("should not match smaller array", - array(equalTo("a"), equalTo("b")), new String[]{"a"}); + array(equalTo("a"), equalTo("b")), new String[]{"a"}); } - + public void testDoesNotMatchNull() { assertDoesNotMatch("should not match null", array(equalTo("a")), null); } - + public void testHasAReadableDescription() { assertDescription("[\"a\", \"b\"]", array(equalTo("a"), equalTo("b"))); } - + public void testHasAReadableMismatchDescriptionUsing() { assertMismatchDescription("element <0> was \"c\"", array(equalTo("a"), equalTo("b")), new String[]{"c", "b"}); } - + public void testHasAReadableMismatchDescriptionUsingCustomMatchers() { final BaseMatcher m = new BaseMatcher() { - @Override public boolean matches(Object item) { return false; } - @Override public void describeTo(Description description) { description.appendText("c"); } - @Override public void describeMismatch(Object item, Description description) { + @Override + public boolean matches(Object item) { + return false; + } + + @Override + public void describeTo(Description description) { + description.appendText("c"); + } + + @Override + public void describeMismatch(Object item, Description description) { description.appendText("didn't match"); } }; diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsArrayWithSizeTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsArrayWithSizeTest.java index 18f607ec..9439cab5 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsArrayWithSizeTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsArrayWithSizeTest.java @@ -1,12 +1,45 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize; import static org.hamcrest.collection.IsArrayWithSize.emptyArray; import static org.hamcrest.core.IsEqual.equalTo; +/** + * Is array with size test. + */ public class IsArrayWithSizeTest extends AbstractMatcherTest { @Override diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsCollectionWithSizeTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsCollectionWithSizeTest.java index b04a0c5c..2c5b8628 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsCollectionWithSizeTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsCollectionWithSizeTest.java @@ -1,17 +1,49 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; -import org.hamcrest.AbstractMatcherTest; -import org.hamcrest.Matcher; -import org.hamcrest.MatcherAssert; - import java.util.ArrayList; +import static java.util.Arrays.asList; import java.util.Collection; import java.util.List; - -import static java.util.Arrays.asList; +import org.hamcrest.AbstractMatcherTest; +import org.hamcrest.Matcher; +import org.hamcrest.MatcherAssert; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.hamcrest.core.IsEqual.equalTo; +/** + * Is collection with size test. + */ public class IsCollectionWithSizeTest extends AbstractMatcherTest { @Override @@ -68,10 +100,10 @@ public void testProvidesConvenientShortcutForHasSizeEqualTo() { public void testHasAReadableDescription() { assertDescription("a collection with size <3>", hasSize(equalTo(3))); } - + public void testCompilesWithATypedCollection() { - // To prove Issue 43 - ArrayList arrayList = new ArrayList(); - MatcherAssert.assertThat(arrayList, hasSize(0)); + // To prove Issue 43 + ArrayList arrayList = new ArrayList(); + MatcherAssert.assertThat(arrayList, hasSize(0)); } } diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsEmptyCollectionTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsEmptyCollectionTest.java index ea875e8a..7fe123e9 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsEmptyCollectionTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsEmptyCollectionTest.java @@ -1,15 +1,47 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; -import org.hamcrest.AbstractMatcherTest; -import org.hamcrest.Matcher; - import java.util.ArrayList; -import java.util.Collection; - import static java.util.Arrays.asList; +import java.util.Collection; +import org.hamcrest.AbstractMatcherTest; +import org.hamcrest.Matcher; import static org.hamcrest.collection.IsEmptyCollection.empty; import static org.hamcrest.core.Is.is; +/** + * Is empty collection test. + */ public class IsEmptyCollectionTest extends AbstractMatcherTest { @Override @@ -33,8 +65,9 @@ public void testCompiles() { needs(IsEmptyCollection.emptyCollectionOf(String.class)); } - private void needs(@SuppressWarnings("unused") Matcher> bar) { } - + private void needs(@SuppressWarnings("unused") Matcher> bar) { + } + private static Collection collectionOfValues() { return new ArrayList(asList("one", "three")); } diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsEmptyIterableTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsEmptyIterableTest.java index 600b5760..188cf199 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsEmptyIterableTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsEmptyIterableTest.java @@ -1,14 +1,46 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; -import org.hamcrest.AbstractMatcherTest; -import org.hamcrest.Matcher; - import java.util.ArrayList; -import java.util.Collection; - import static java.util.Arrays.asList; +import java.util.Collection; +import org.hamcrest.AbstractMatcherTest; +import org.hamcrest.Matcher; import static org.hamcrest.collection.IsEmptyIterable.emptyIterable; +/** + * Is empty iterable test. + */ public class IsEmptyIterableTest extends AbstractMatcherTest { @Override diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsInTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsInTest.java index e9fcbdcb..8cca43e8 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsInTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsInTest.java @@ -1,12 +1,45 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; +import java.util.Arrays; +import java.util.Collection; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import org.hamcrest.StringDescription; -import java.util.Arrays; -import java.util.Collection; - +/** + * Is in test. + */ public class IsInTest extends AbstractMatcherTest { String[] elements = {"a", "b", "c"}; @@ -18,27 +51,27 @@ protected Matcher createMatcher() { public void testReturnsTrueIfArgumentIsInCollection() { Collection collection = Arrays.asList(elements); Matcher isIn = new IsIn(collection); - + assertMatches("a", isIn, "a"); assertMatches("b", isIn, "b"); assertMatches("c", isIn, "c"); assertDoesNotMatch("d", isIn, "d"); } - + public void testReturnsTrueIfArgumentIsInArray() { Matcher isIn = new IsIn(elements); - + assertMatches("a", isIn, "a"); assertMatches("b", isIn, "b"); assertMatches("c", isIn, "c"); assertDoesNotMatch("d", isIn, "d"); } - + public void testHasReadableDescription() { Matcher isIn = new IsIn(elements); - - assertEquals("description", - "one of {\"a\", \"b\", \"c\"}", + + assertEquals("description", + "one of {\"a\", \"b\", \"c\"}", StringDescription.toString(isIn)); } } diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInAnyOrderTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInAnyOrderTest.java index 091c3475..bf4da069 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInAnyOrderTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInAnyOrderTest.java @@ -1,39 +1,71 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; +import static java.util.Arrays.asList; +import java.util.Collections; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; -import org.hamcrest.collection.IsIterableContainingInOrderTest.WithValue; - -import java.util.Collections; - -import static java.util.Arrays.asList; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; +import org.hamcrest.collection.IsIterableContainingInOrderTest.WithValue; import static org.hamcrest.collection.IsIterableContainingInOrderTest.make; import static org.hamcrest.collection.IsIterableContainingInOrderTest.value; +/** + * Is iteratble containing in any order test. + */ public class IsIterableContainingInAnyOrderTest extends AbstractMatcherTest { @Override protected Matcher createMatcher() { return containsInAnyOrder(1, 2); - } + } public void testMatchesSingleItemIterable() { - assertMatches("single item", containsInAnyOrder(1), asList(1)); + assertMatches("single item", containsInAnyOrder(1), asList(1)); } public void testDoesNotMatchEmpty() { assertMismatchDescription("no item matches: <1>, <2> in []", containsInAnyOrder(1, 2), Collections.emptyList()); } - + public void testMatchesIterableOutOfOrder() { assertMatches("Out of order", containsInAnyOrder(1, 2), asList(2, 1)); } - + public void testMatchesIterableInOrder() { assertMatches("In order", containsInAnyOrder(1, 2), asList(1, 2)); } - + public void testDoesNotMatchIfOneOfMultipleElementsMismatches() { assertMismatchDescription("not matched: <4>", containsInAnyOrder(1, 2, 3), asList(1, 2, 4)); } @@ -43,7 +75,7 @@ public void testDoesNotMatchIfThereAreMoreElementsThanMatchers() { final Matcher> helpTheCompilerOut = containsInAnyOrder(value(1), value(3)); assertMismatchDescription("not matched: ", helpTheCompilerOut, asList(make(1), make(2), make(3))); } - + public void testDoesNotMatchIfThereAreMoreMatchersThanElements() { assertMismatchDescription("no item matches: <4> in [<1>, <2>, <3>]", containsInAnyOrder(1, 2, 3, 4), asList(1, 2, 3)); } diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInOrderTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInOrderTest.java index 14ae6f58..c79f7338 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInOrderTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInOrderTest.java @@ -1,17 +1,48 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; -import org.hamcrest.AbstractMatcherTest; -import org.hamcrest.FeatureMatcher; -import org.hamcrest.Matcher; - import java.util.ArrayList; -import java.util.List; - import static java.util.Arrays.asList; import static java.util.Collections.singletonList; +import org.hamcrest.AbstractMatcherTest; +import org.hamcrest.FeatureMatcher; +import org.hamcrest.Matcher; import static org.hamcrest.collection.IsIterableContainingInOrder.contains; import static org.hamcrest.core.IsEqual.equalTo; +/** + * Is iterable containing in order test. + */ @SuppressWarnings("unchecked") public class IsIterableContainingInOrderTest extends AbstractMatcherTest { // temporary hack until the Java type system works @@ -53,25 +84,41 @@ public void testDoesNotMatchEmptyIterable() throws Exception { public void testHasAReadableDescription() { assertDescription("iterable containing [<1>, <2>]", contains(1, 2)); } - + public void testCanHandleNullMatchers() { - assertMatches(contains(null, null), asList(null, null)); + assertMatches(contains(null, null), asList(null, null)); } + /** + * With value implementation. + */ public static class WithValue { - private final int value; - public WithValue(int value) { this.value = value; } - public int getValue() { return value; } - @Override public String toString() { return "WithValue " + value; } + private final int value; + + public WithValue(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + @Override + public String toString() { + return "WithValue " + value; + } } public static WithValue make(int value) { - return new WithValue(value); + return new WithValue(value); } public static Matcher value(int value) { - return new FeatureMatcher(equalTo(value), "value with", "value") { - @Override protected Integer featureValueOf(WithValue actual) { return actual.getValue(); } - }; + return new FeatureMatcher(equalTo(value), "value with", "value") { + @Override + protected Integer featureValueOf(WithValue actual) { + return actual.getValue(); + } + }; } } diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInRelativeOrderTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInRelativeOrderTest.java index 8192c8bf..3a908205 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInRelativeOrderTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsIterableContainingInRelativeOrderTest.java @@ -1,16 +1,48 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; +import java.util.ArrayList; +import static java.util.Arrays.asList; +import java.util.List; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.FeatureMatcher; import org.hamcrest.Matcher; - -import java.util.ArrayList; -import java.util.List; - -import static java.util.Arrays.asList; import static org.hamcrest.collection.IsIterableContainingInRelativeOrder.containsInRelativeOrder; import static org.hamcrest.core.IsEqual.equalTo; +/** + * Is iterable containing in relative order test. + */ @SuppressWarnings("unchecked") public class IsIterableContainingInRelativeOrderTest extends AbstractMatcherTest { // temporary hack until the Java type system works @@ -74,20 +106,36 @@ public void testHasAReadableDescription() { assertDescription("iterable containing [<1>, <2>] in relative order", containsInRelativeOrder(1, 2)); } + /** + * With value implementation. + */ public static class WithValue { - private final int value; - public WithValue(int value) { this.value = value; } - public int getValue() { return value; } - @Override public String toString() { return "WithValue " + value; } + private final int value; + + public WithValue(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + @Override + public String toString() { + return "WithValue " + value; + } } public static WithValue make(int value) { - return new WithValue(value); + return new WithValue(value); } public static Matcher value(int value) { - return new FeatureMatcher(equalTo(value), "value with", "value") { - @Override protected Integer featureValueOf(WithValue actual) { return actual.getValue(); } - }; + return new FeatureMatcher(equalTo(value), "value with", "value") { + @Override + protected Integer featureValueOf(WithValue actual) { + return actual.getValue(); + } + }; } } diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsIterableWithSizeTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsIterableWithSizeTest.java index 8bf65d14..7acfa9c7 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsIterableWithSizeTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsIterableWithSizeTest.java @@ -1,13 +1,45 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; -import org.hamcrest.AbstractMatcherTest; -import org.hamcrest.Matcher; - import java.util.Arrays; import java.util.Collections; - +import org.hamcrest.AbstractMatcherTest; +import org.hamcrest.Matcher; import static org.hamcrest.collection.IsIterableWithSize.iterableWithSize; +/** + * Is iterable with size test. + */ public class IsIterableWithSizeTest extends AbstractMatcherTest { @Override diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsMapContainingKeyTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsMapContainingKeyTest.java index 13f067c8..b7917ec9 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsMapContainingKeyTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsMapContainingKeyTest.java @@ -1,15 +1,47 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; -import org.hamcrest.AbstractMatcherTest; -import org.hamcrest.Matcher; - import java.util.HashMap; import java.util.Map; import java.util.TreeMap; - +import org.hamcrest.AbstractMatcherTest; +import org.hamcrest.Matcher; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsMapContaining.hasKey; +/** + * Is map containing key test. + */ public class IsMapContainingKeyTest extends AbstractMatcherTest { @Override @@ -20,20 +52,20 @@ protected Matcher createMatcher() { public void testMatchesSingletonMapContainingKey() { Map map = new HashMap(); map.put("a", 1); - + assertMatches("Matches single key", hasKey("a"), map); } - + public void testMatchesMapContainingKey() { Map map = new HashMap(); map.put("a", 1); map.put("b", 2); map.put("c", 3); - + assertMatches("Matches a", hasKey("a"), map); assertMatches("Matches c", hasKey("c"), map); } - + // No longer compiles // public void testMatchesMapContainingKeyWithNoGenerics() { @@ -68,17 +100,17 @@ public void testMatchesMapContainingKeyWithNumberKeys() throws Exception { public void testHasReadableDescription() { assertDescription("map containing [\"a\"->ANYTHING]", hasKey("a")); } - + public void testDoesNotMatchEmptyMap() { assertMismatchDescription("map was []", hasKey("Foo"), new HashMap()); } - + public void testDoesNotMatchMapMissingKey() { Map map = new TreeMap(); map.put("a", 1); map.put("b", 2); map.put("c", 3); - + assertMismatchDescription("map was [, , ]", hasKey("d"), map); } } diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsMapContainingTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsMapContainingTest.java index 3eed3463..0b58ebb3 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsMapContainingTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsMapContainingTest.java @@ -1,16 +1,48 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; -import org.hamcrest.AbstractMatcherTest; -import org.hamcrest.Matcher; - import java.util.HashMap; import java.util.Map; import java.util.TreeMap; - +import org.hamcrest.AbstractMatcherTest; +import org.hamcrest.Matcher; import static org.hamcrest.collection.IsMapContaining.hasEntry; import static org.hamcrest.core.IsAnything.anything; import static org.hamcrest.core.IsEqual.equalTo; +/** + * Is map containing test. + */ public class IsMapContainingTest extends AbstractMatcherTest { @Override diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsMapContainingValueTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsMapContainingValueTest.java index a2d7f908..df7735be 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsMapContainingValueTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsMapContainingValueTest.java @@ -1,15 +1,47 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; -import org.hamcrest.AbstractMatcherTest; -import org.hamcrest.Matcher; - import java.util.HashMap; import java.util.Map; import java.util.TreeMap; - +import org.hamcrest.AbstractMatcherTest; +import org.hamcrest.Matcher; import static org.hamcrest.collection.IsMapContaining.hasValue; +/** + * Is map containing value test. + */ public class IsMapContainingValueTest extends AbstractMatcherTest { @Override @@ -20,16 +52,16 @@ protected Matcher createMatcher() { public void testHasReadableDescription() { assertDescription("map containing [ANYTHING->\"a\"]", hasValue("a")); } - + public void testDoesNotMatchEmptyMap() { Map map = new HashMap(); assertMismatchDescription("map was []", hasValue(1), map); } - + public void testMatchesSingletonMapContainingValue() { Map map = new HashMap(); map.put("a", 1); - + assertMatches("Singleton map", hasValue(1), map); } @@ -38,9 +70,9 @@ public void testMatchesMapContainingValue() { map.put("a", 1); map.put("b", 2); map.put("c", 3); - - assertMatches("hasValue 1", hasValue(1), map); - assertMatches("hasValue 3", hasValue(3), map); - assertMismatchDescription("map was [, , ]", hasValue(4), map); + + assertMatches("hasValue 1", hasValue(1), map); + assertMatches("hasValue 3", hasValue(3), map); + assertMismatchDescription("map was [, , ]", hasValue(4), map); } } diff --git a/hamcrest/src/test/java/org/hamcrest/collection/IsMapWithSizeTest.java b/hamcrest/src/test/java/org/hamcrest/collection/IsMapWithSizeTest.java index c050924c..c2950476 100644 --- a/hamcrest/src/test/java/org/hamcrest/collection/IsMapWithSizeTest.java +++ b/hamcrest/src/test/java/org/hamcrest/collection/IsMapWithSizeTest.java @@ -1,15 +1,47 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.collection; +import java.util.HashMap; +import java.util.Map; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; import org.hamcrest.MatcherAssert; - -import java.util.HashMap; -import java.util.Map; - import static org.hamcrest.collection.IsMapWithSize.aMapWithSize; import static org.hamcrest.core.IsEqual.equalTo; +/** + * Is map with size test. + */ public final class IsMapWithSizeTest extends AbstractMatcherTest { @Override @@ -66,12 +98,12 @@ public void testProvidesConvenientShortcutForHasSizeEqualTo() { public void testHasAReadableDescription() { assertDescription("a map with size <3>", aMapWithSize(equalTo(3))); } - + public void testCompilesWithATypedMap() { - Map arrayList = new HashMap(); - MatcherAssert.assertThat(arrayList, aMapWithSize(0)); + Map arrayList = new HashMap(); + MatcherAssert.assertThat(arrayList, aMapWithSize(0)); } - + private static Map mapWithKeys(K... keys) { final Map result = new HashMap(); for (K key : keys) { diff --git a/hamcrest/src/test/java/org/hamcrest/comparator/ComparatorMatcherBuilderTest.java b/hamcrest/src/test/java/org/hamcrest/comparator/ComparatorMatcherBuilderTest.java index a5fdb4ac..a6ed7ffa 100644 --- a/hamcrest/src/test/java/org/hamcrest/comparator/ComparatorMatcherBuilderTest.java +++ b/hamcrest/src/test/java/org/hamcrest/comparator/ComparatorMatcherBuilderTest.java @@ -1,15 +1,47 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.comparator; -import org.hamcrest.AbstractMatcherTest; -import org.hamcrest.Matcher; - import java.math.BigDecimal; import java.util.Comparator; - +import org.hamcrest.AbstractMatcherTest; +import org.hamcrest.Matcher; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.comparator.ComparatorMatcherBuilder.comparedBy; import static org.hamcrest.core.IsNot.not; +/** + * Comparator matcher builder test. + */ public class ComparatorMatcherBuilderTest extends AbstractMatcherTest { private final ComparatorMatcherBuilder integerComparatorMatcherBuilder = ComparatorMatcherBuilder.usingNaturalOrdering(); diff --git a/hamcrest/src/test/java/org/hamcrest/comparator/ComparatorMatcherTest.java b/hamcrest/src/test/java/org/hamcrest/comparator/ComparatorMatcherTest.java index 2bc53d4c..b5d061b4 100644 --- a/hamcrest/src/test/java/org/hamcrest/comparator/ComparatorMatcherTest.java +++ b/hamcrest/src/test/java/org/hamcrest/comparator/ComparatorMatcherTest.java @@ -1,15 +1,47 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.comparator; -import org.hamcrest.AbstractMatcherTest; -import org.hamcrest.Matcher; - import java.math.BigDecimal; import java.util.Comparator; - +import org.hamcrest.AbstractMatcherTest; +import org.hamcrest.Matcher; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsNot.not; import static org.hamcrest.number.OrderingComparison.*; +/** + * Comparator matcher test. + */ public class ComparatorMatcherTest extends AbstractMatcherTest { @Override diff --git a/hamcrest/src/test/java/org/hamcrest/core/AllOfTest.java b/hamcrest/src/test/java/org/hamcrest/core/AllOfTest.java index 0387207c..f9c6c4a5 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/AllOfTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/AllOfTest.java @@ -1,9 +1,38 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.AllOf.allOf; import static org.hamcrest.core.Is.is; @@ -12,59 +41,63 @@ import static org.hamcrest.core.StringContains.containsString; import static org.hamcrest.core.StringEndsWith.endsWith; import static org.hamcrest.core.StringStartsWith.startsWith; +import org.junit.Test; +/** + * All of test. + */ public final class AllOfTest { - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = allOf(equalTo("irrelevant"), startsWith("irr")); - + assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - - @Test public void - evaluatesToTheTheLogicalConjunctionOfTwoOtherMatchers() { + + @Test + public void evaluatesToTheTheLogicalConjunctionOfTwoOtherMatchers() { Matcher matcher = allOf(startsWith("goo"), endsWith("ood")); - + assertMatches("didn't pass both sub-matchers", matcher, "good"); assertDoesNotMatch("didn't fail first sub-matcher", matcher, "mood"); assertDoesNotMatch("didn't fail second sub-matcher", matcher, "goon"); assertDoesNotMatch("didn't fail both sub-matchers", matcher, "fred"); } - @Test public void - evaluatesToTheTheLogicalConjunctionOfManyOtherMatchers() { + @Test + public void evaluatesToTheTheLogicalConjunctionOfManyOtherMatchers() { Matcher matcher = allOf(startsWith("g"), startsWith("go"), endsWith("d"), startsWith("go"), startsWith("goo")); - + assertMatches("didn't pass all sub-matchers", matcher, "good"); assertDoesNotMatch("didn't fail middle sub-matcher", matcher, "goon"); } - - @Test public void - supportsMixedTypes() { + + @Test + public void supportsMixedTypes() { final Matcher matcher = allOf( equalTo(new SampleBaseClass("bad")), is(notNullValue()), equalTo(new SampleBaseClass("good")), equalTo(new SampleSubClass("ugly"))); - + assertDoesNotMatch("didn't fail last sub-matcher", matcher, new SampleSubClass("good")); } - - @Test public void - hasAReadableDescription() { + + @Test + public void hasAReadableDescription() { assertDescription("(\"good\" and \"bad\" and \"ugly\")", allOf(equalTo("good"), equalTo("bad"), equalTo("ugly"))); } - @Test public void - hasAMismatchDescriptionDescribingTheFirstFailingMatch() { + @Test + public void hasAMismatchDescriptionDescribingTheFirstFailingMatch() { assertMismatchDescription("\"good\" was \"bad\"", allOf(equalTo("bad"), equalTo("good")), "bad"); } - @Test public void - varargs(){ + @Test + public void varargs(){ assertThat("the text!", new AllOf<>(startsWith("the"), containsString("text"), endsWith("!"))); } } diff --git a/hamcrest/src/test/java/org/hamcrest/core/AnyOfTest.java b/hamcrest/src/test/java/org/hamcrest/core/AnyOfTest.java index e2d9a9ee..4a0fb4c1 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/AnyOfTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/AnyOfTest.java @@ -1,62 +1,95 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.AnyOf.anyOf; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.StringEndsWith.endsWith; import static org.hamcrest.core.StringStartsWith.startsWith; +import org.junit.Test; +/** + * Any of test. + */ public final class AnyOfTest { - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = anyOf(equalTo("irrelevant"), startsWith("irr")); - + assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - @Test public void - evaluatesToTheTheLogicalDisjunctionOfTwoOtherMatchers() { + @Test + public void evaluatesToTheTheLogicalDisjunctionOfTwoOtherMatchers() { Matcher matcher = anyOf(startsWith("goo"), endsWith("ood")); - + assertMatches("didn't pass both sub-matchers", matcher, "good"); assertMatches("didn't pass second sub-matcher", matcher, "mood"); assertMatches("didn't pass first sub-matcher", matcher, "goon"); assertDoesNotMatch("didn't fail both sub-matchers", matcher, "flan"); } - @Test public void - evaluatesToTheTheLogicalDisjunctionOfManyOtherMatchers() { + @Test + public void evaluatesToTheTheLogicalDisjunctionOfManyOtherMatchers() { Matcher matcher = anyOf(startsWith("g"), startsWith("go"), endsWith("d"), startsWith("go"), startsWith("goo")); - + assertMatches("didn't pass middle sub-matcher", matcher, "vlad"); assertDoesNotMatch("didn't fail all sub-matchers", matcher, "flan"); } @SuppressWarnings("unchecked") - @Test public void - supportsMixedTypes() { + @Test + public void supportsMixedTypes() { final Matcher matcher = anyOf( equalTo(new SampleBaseClass("bad")), equalTo(new SampleBaseClass("good")), equalTo(new SampleSubClass("ugly"))); - + assertMatches("didn't pass middle sub-matcher", matcher, new SampleSubClass("good")); } - @Test public void - hasAReadableDescription() { + @Test + public void hasAReadableDescription() { assertDescription("(\"good\" or \"bad\" or \"ugly\")", anyOf(equalTo("good"), equalTo("bad"), equalTo("ugly"))); } - @Test public void - varargs(){ + @Test + public void varargs(){ assertThat("the text!", new AnyOf<>(startsWith("the"), endsWith("."))); } } diff --git a/hamcrest/src/test/java/org/hamcrest/core/CombinableTest.java b/hamcrest/src/test/java/org/hamcrest/core/CombinableTest.java index 7a209b62..ea0046dd 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/CombinableTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/CombinableTest.java @@ -1,67 +1,100 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNot.not; import static org.hamcrest.core.IsNull.notNullValue; +import org.junit.Test; +/** + * Combinable test. + */ public final class CombinableTest { private static final CombinableMatcher EITHER_3_OR_4 = CombinableMatcher.either(equalTo(3)).or(equalTo(4)); private static final CombinableMatcher NOT_3_AND_NOT_4 = CombinableMatcher.both(not(equalTo(3))).and(not(equalTo(4))); - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { assertNullSafe(EITHER_3_OR_4); assertNullSafe(NOT_3_AND_NOT_4); assertUnknownTypeSafe(EITHER_3_OR_4); assertUnknownTypeSafe(NOT_3_AND_NOT_4); } - @Test public void - bothAcceptsAndRejects() { + @Test + public void bothAcceptsAndRejects() { assertMatches("both didn't pass", NOT_3_AND_NOT_4, 2); assertDoesNotMatch("both didn't fail", NOT_3_AND_NOT_4, 3); } - @Test public void - acceptsAndRejectsThreeAnds() { + @Test + public void acceptsAndRejectsThreeAnds() { CombinableMatcher tripleAnd = NOT_3_AND_NOT_4.and(equalTo(2)); - + assertMatches("tripleAnd didn't pass", tripleAnd, 2); assertDoesNotMatch("tripleAnd didn't fail", tripleAnd, 3); } - @Test public void - bothDescribesItself() { + @Test + public void bothDescribesItself() { assertDescription("(not <3> and not <4>)", NOT_3_AND_NOT_4); assertMismatchDescription("not <3> was <3>", NOT_3_AND_NOT_4, 3); } - @Test public void - eitherAcceptsAndRejects() { + @Test + public void eitherAcceptsAndRejects() { assertMatches("either didn't pass", EITHER_3_OR_4, 3); assertDoesNotMatch("either didn't fail", EITHER_3_OR_4, 6); } - @Test public void - acceptsAndRejectsThreeOrs() { + @Test + public void acceptsAndRejectsThreeOrs() { final CombinableMatcher tripleOr = EITHER_3_OR_4.or(equalTo(11)); - + assertMatches("tripleOr didn't pass", tripleOr, 11); assertDoesNotMatch("tripleOr didn't fail", tripleOr, 9); } - @Test public void - eitherDescribesItself() { + @Test + public void eitherDescribesItself() { assertDescription("(<3> or <4>)", EITHER_3_OR_4); assertMismatchDescription("was <6>", EITHER_3_OR_4, 6); } - @Test public void - picksUpTypeFromLeftHandSideOfExpression() { + @Test + public void picksUpTypeFromLeftHandSideOfExpression() { @SuppressWarnings("unused") Matcher matcher = CombinableMatcher.both(equalTo("yellow")).and(notNullValue(String.class)); } diff --git a/hamcrest/src/test/java/org/hamcrest/core/DescribedAsTest.java b/hamcrest/src/test/java/org/hamcrest/core/DescribedAsTest.java index 5c76af90..6a53b8a5 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/DescribedAsTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/DescribedAsTest.java @@ -1,47 +1,80 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.core.DescribedAs.describedAs; import static org.hamcrest.core.IsAnything.anything; import static org.hamcrest.core.IsEqual.equalTo; +import org.junit.Test; +/** + * Described as test. + */ public final class DescribedAsTest { - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = describedAs("irrelevant", anything()); assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - @Test public void - overridesDescriptionOfOtherMatcherWithThatPassedToConstructor() { + @Test + public void overridesDescriptionOfOtherMatcherWithThatPassedToConstructor() { Matcher matcher = describedAs("my description", anything()); assertDescription("my description", matcher); } - @Test public void - appendsValuesToDescription() { + @Test + public void appendsValuesToDescription() { Matcher matcher = describedAs("value 1 = %0, value 2 = %1", anything(), 33, 97); assertDescription("value 1 = <33>, value 2 = <97>", matcher); } - @Test public void - celegatesMatchingToAnotherMatcher() { + @Test + public void celegatesMatchingToAnotherMatcher() { Matcher matcher = describedAs("irrelevant", equalTo("hi")); assertMatches(matcher, "hi"); assertDoesNotMatch("matched", matcher, "oi"); } - @Test public void - delegatesMismatchDescriptionToAnotherMatcher() { + @Test + public void delegatesMismatchDescriptionToAnotherMatcher() { Matcher matcher = describedAs("irrelevant", equalTo(2)); assertMismatchDescription("was <1>", matcher, 1); diff --git a/hamcrest/src/test/java/org/hamcrest/core/EveryTest.java b/hamcrest/src/test/java/org/hamcrest/core/EveryTest.java index ff9f1772..63f78b95 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/EveryTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/EveryTest.java @@ -1,43 +1,75 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; -import org.hamcrest.Matcher; -import org.junit.Test; - import java.util.ArrayList; - import static java.util.Arrays.asList; import static java.util.Collections.singletonList; import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.core.StringContains.containsString; +import org.junit.Test; +/** + * Every test. + */ public final class EveryTest { private final Matcher> matcher = Every.everyItem(containsString("a")); - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - @Test public void - matchesOnlyWhenEveryItemMatches() { + @Test + public void matchesOnlyWhenEveryItemMatches() { assertMatches(matcher, asList("AaA", "BaB", "CaC")); assertDoesNotMatch(matcher, asList("AaA", "BXB", "CaC")); } - @Test public void - matchesEmptyLists() { + @Test + public void matchesEmptyLists() { assertMatches("didn't match empty list", matcher, new ArrayList()); } - @Test public void - describesItself() { + @Test + public void describesItself() { assertDescription("every item is a string containing \"a\"", matcher); } - @Test public void - describesAMismatch() { + @Test + public void describesAMismatch() { assertMismatchDescription("an item was \"BXB\"", matcher, singletonList("BXB")); } } diff --git a/hamcrest/src/test/java/org/hamcrest/core/IsAnythingTest.java b/hamcrest/src/test/java/org/hamcrest/core/IsAnythingTest.java index 80a8444c..f8c74870 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/IsAnythingTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/IsAnythingTest.java @@ -1,14 +1,47 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.assertDescription; import static org.hamcrest.AbstractMatcherTest.assertMatches; +import org.hamcrest.Matcher; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsAnything.anything; +import org.junit.Test; +/** + * Is anything test. + */ public final class IsAnythingTest { private final Matcher matcher = anything(); @@ -17,8 +50,7 @@ private static class CustomThing { } @Test - public void - alwaysEvaluatesToTrue() { + public void alwaysEvaluatesToTrue() { assertMatches("didn't match null", matcher, null); assertMatches("didn't match Object", matcher, new Object()); assertMatches("didn't match custom object", matcher, new CustomThing()); @@ -30,13 +62,13 @@ public void compilesWithoutTypeWarnings() { assertThat(new CustomThing(), is(anything())); } - @Test public void - hasUsefulDefaultDescription() { + @Test + public void hasUsefulDefaultDescription() { assertDescription("ANYTHING", matcher); } - @Test public void - canOverrideDescription() { + @Test + public void canOverrideDescription() { String description = "description"; assertDescription(description, anything(description)); } diff --git a/hamcrest/src/test/java/org/hamcrest/core/IsCollectionContainingTest.java b/hamcrest/src/test/java/org/hamcrest/core/IsCollectionContainingTest.java index db76bb1d..328e3aed 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/IsCollectionContainingTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/IsCollectionContainingTest.java @@ -1,21 +1,51 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; -import org.hamcrest.AbstractMatcherTest; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeDiagnosingMatcher; - import java.util.ArrayList; +import static java.util.Arrays.asList; import java.util.HashSet; import java.util.Set; - -import static java.util.Arrays.asList; +import org.hamcrest.AbstractMatcherTest; +import org.hamcrest.Description; +import org.hamcrest.Matcher; import static org.hamcrest.MatcherAssert.assertThat; +import org.hamcrest.TypeSafeDiagnosingMatcher; import static org.hamcrest.core.IsCollectionContaining.hasItem; import static org.hamcrest.core.IsCollectionContaining.hasItems; import static org.hamcrest.core.IsEqual.equalTo; public class IsCollectionContainingTest extends AbstractMatcherTest { + @Override protected Matcher createMatcher() { return hasItem(equalTo("irrelevant")); @@ -23,7 +53,7 @@ protected Matcher createMatcher() { public void testMatchesACollectionThatContainsAnElementMatchingTheGivenMatcher() { Matcher> itemMatcher = hasItem(equalTo("a")); - + assertMatches("should match list that contains 'a'", itemMatcher, asList("a", "b", "c")); } @@ -31,8 +61,7 @@ public void testMatchesACollectionThatContainsAnElementMatchingTheGivenMatcher() public void testDoesNotMatchCollectionThatDoesntContainAnElementMatchingTheGivenMatcher() { final Matcher> matcher1 = hasItem(mismatchable("a")); assertMismatchDescription("mismatches were: [mismatched: b, mismatched: c]", matcher1, asList("b", "c")); - - + final Matcher> matcher2 = hasItem(equalTo("a")); assertMismatchDescription("was empty", matcher2, new ArrayList()); } @@ -44,13 +73,12 @@ public void testDoesNotMatchNull() { public void testHasAReadableDescription() { assertDescription("a collection containing \"a\"", hasItem(equalTo("a"))); } - - public void testCanMatchItemWhenCollectionHoldsSuperclass() // Issue 24 - { - final Set s = new HashSet(); - s.add(Integer.valueOf(2)); - assertThat(s, new IsCollectionContaining(new IsEqual(Integer.valueOf(2)))); - assertThat(s, IsCollectionContaining.hasItem(Integer.valueOf(2))); + + public void testCanMatchItemWhenCollectionHoldsSuperclass() {// Issue 24 + final Set s = new HashSet(); + s.add(Integer.valueOf(2)); + assertThat(s, new IsCollectionContaining(new IsEqual(Integer.valueOf(2)))); + assertThat(s, IsCollectionContaining.hasItem(Integer.valueOf(2))); } @SuppressWarnings("unchecked") @@ -59,45 +87,45 @@ public void testMatchesAllItemsInCollection() { assertMatches("should match list containing all items", matcher1, asList("a", "b", "c")); - + final Matcher> matcher2 = hasItems("a", "b", "c"); assertMatches("should match list containing all items (without matchers)", matcher2, asList("a", "b", "c")); - + final Matcher> matcher3 = hasItems(equalTo("a"), equalTo("b"), equalTo("c")); assertMatches("should match list containing all items in any order", matcher3, asList("c", "b", "a")); - + final Matcher> matcher4 = hasItems(equalTo("a"), equalTo("b"), equalTo("c")); assertMatches("should match list containing all items plus others", matcher4, asList("e", "c", "b", "a", "d")); - + final Matcher> matcher5 = hasItems(equalTo("a"), equalTo("b"), equalTo("c")); assertDoesNotMatch("should not match list unless it contains all items", matcher5, asList("e", "c", "b", "d")); // 'a' missing } - - + private static Matcher mismatchable(final String string) { - return new TypeSafeDiagnosingMatcher() { - @Override - protected boolean matchesSafely(String item, Description mismatchDescription) { - if (string.equals(item)) - return true; - - mismatchDescription.appendText("mismatched: " + item); - return false; - } - - @Override - public void describeTo(Description description) { - description.appendText("mismatchable: " + string); - } - }; + return new TypeSafeDiagnosingMatcher() { + @Override + protected boolean matchesSafely(String item, Description mismatchDescription) { + if (string.equals(item)) { + return true; + } + + mismatchDescription.appendText("mismatched: " + item); + return false; + } + + @Override + public void describeTo(Description description) { + description.appendText("mismatchable: " + string); + } + }; } } diff --git a/hamcrest/src/test/java/org/hamcrest/core/IsEqualTest.java b/hamcrest/src/test/java/org/hamcrest/core/IsEqualTest.java index d3ff21c5..f487788a 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/IsEqualTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/IsEqualTest.java @@ -1,24 +1,57 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsEqual.equalToObject; +import org.junit.Test; +/** + * Is equal test. + */ public final class IsEqualTest { - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = equalTo("irrelevant"); assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - @Test public void - comparesObjectsUsingEqualsMethod() { + @Test + public void comparesObjectsUsingEqualsMethod() { final Matcher matcher1 = equalTo("hi"); assertMatches(matcher1, "hi"); assertDoesNotMatch(matcher1, "bye"); @@ -30,10 +63,10 @@ public final class IsEqualTest { assertDoesNotMatch(matcher2, null); } - @Test public void - canCompareNullValues() { + @Test + public void canCompareNullValues() { final Matcher matcher = equalTo(null); - + assertMatches(matcher, null); assertDoesNotMatch(matcher, 2); assertDoesNotMatch(matcher, "hi"); @@ -41,8 +74,8 @@ public final class IsEqualTest { } @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") - @Test public void - honoursIsEqualImplementationEvenWithNullValues() { + @Test + public void honoursIsEqualImplementationEvenWithNullValues() { Object alwaysEqual = new Object() { @Override public boolean equals(Object obj) { @@ -62,8 +95,8 @@ public boolean equals(Object obj) { assertDoesNotMatch(matcher, neverEqual); } - @Test public void - comparesTheElementsOfAnObjectArray() { + @Test + public void comparesTheElementsOfAnObjectArray() { String[] s1 = {"a", "b"}; String[] s2 = {"a", "b"}; String[] s3 = {"c", "d"}; @@ -77,8 +110,8 @@ public boolean equals(Object obj) { assertDoesNotMatch(matcher, null); } - @Test public void - comparesTheElementsOfArraysWithNulls() { + @Test + public void comparesTheElementsOfArraysWithNulls() { String[] s1 = {"a", null, "b"}; String[] s2 = {"a", null, "b"}; String[] s3 = {"c", "d"}; @@ -91,8 +124,8 @@ public boolean equals(Object obj) { assertDoesNotMatch(matcher, s4); } - @Test public void - comparesTheElementsOfAnArrayOfPrimitiveTypes() { + @Test + public void comparesTheElementsOfAnArrayOfPrimitiveTypes() { int[] i1 = new int[]{1, 2}; int[] i2 = new int[]{1, 2}; int[] i3 = new int[]{3, 4}; @@ -106,8 +139,8 @@ public boolean equals(Object obj) { assertDoesNotMatch(matcher, null); } - @Test public void - recursivelyTestsElementsOfArrays() { + @Test + public void recursivelyTestsElementsOfArrays() { int[][] i1 = new int[][]{{1, 2}, {3, 4}}; int[][] i2 = new int[][]{{1, 2}, {3, 4}}; int[][] i3 = new int[][]{{5, 6}, {7, 8}}; @@ -121,8 +154,8 @@ public boolean equals(Object obj) { assertDoesNotMatch(matcher, null); } - @Test public void - hasUntypedVariant() { + @Test + public void hasUntypedVariant() { Object original = 10; assertMatches(equalToObject(10), original); @@ -131,8 +164,8 @@ public boolean equals(Object obj) { assertDoesNotMatch(equalToObject(10), "10"); } - @Test public void - includesTheResultOfCallingToStringOnItsArgumentInTheDescription() { + @Test + public void includesTheResultOfCallingToStringOnItsArgumentInTheDescription() { final String argumentDescription = "ARGUMENT DESCRIPTION"; Object argument = new Object() { @Override @@ -143,14 +176,14 @@ public String toString() { assertDescription("<" + argumentDescription + ">", equalTo(argument)); } - @Test public void - returnsAnObviousDescriptionIfCreatedWithANestedMatcherByMistake() { + @Test + public void returnsAnObviousDescriptionIfCreatedWithANestedMatcherByMistake() { Matcher innerMatcher = equalTo("NestedMatcher"); assertDescription("<" + innerMatcher.toString() + ">", equalTo(innerMatcher)); } - @Test public void - returnsGoodDescriptionIfCreatedWithNullReference() { + @Test + public void returnsGoodDescriptionIfCreatedWithNullReference() { assertDescription("null", equalTo(null)); } } diff --git a/hamcrest/src/test/java/org/hamcrest/core/IsInstanceOfTest.java b/hamcrest/src/test/java/org/hamcrest/core/IsInstanceOfTest.java index 8dd85af1..32deca17 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/IsInstanceOfTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/IsInstanceOfTest.java @@ -1,24 +1,57 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.core.IsInstanceOf.any; import static org.hamcrest.core.IsInstanceOf.instanceOf; +import org.junit.Test; +/** + * Is instance of test. + */ public final class IsInstanceOfTest { - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = instanceOf(Number.class); assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - @Test public void - evaluatesToTrueIfArgumentIsInstanceOfASpecificClass() { + @Test + public void evaluatesToTrueIfArgumentIsInstanceOfASpecificClass() { final Matcher matcher = instanceOf(Number.class); assertMatches(matcher, 1); @@ -27,18 +60,18 @@ public final class IsInstanceOfTest { assertDoesNotMatch(matcher, new Object()); } - @Test public void - hasAReadableDescription() { + @Test + public void hasAReadableDescription() { assertDescription("an instance of java.lang.Number", instanceOf(Number.class)); } - @Test public void - describesActualClassInMismatchMessage() { + @Test + public void describesActualClassInMismatchMessage() { assertMismatchDescription("\"some text\" is a java.lang.String", instanceOf(Number.class), "some text"); } - @Test public void - matchesPrimitiveTypes() { + @Test + public void matchesPrimitiveTypes() { assertMatches(any(boolean.class), true); assertMatches(any(byte.class), (byte)1); assertMatches(any(char.class), 'x'); @@ -49,19 +82,18 @@ public final class IsInstanceOfTest { assertMatches(any(short.class), (short)1); } - @Test public void - instanceOfRequiresACastToReturnTheCorrectTypeForUseInJMock() { + @Test + public void instanceOfRequiresACastToReturnTheCorrectTypeForUseInJMock() { @SuppressWarnings("unused") Integer anInteger = (Integer)with(instanceOf(Integer.class)); } - @Test public void - anyWillReturnTheCorrectTypeForUseInJMock() { + @Test + public void anyWillReturnTheCorrectTypeForUseInJMock() { @SuppressWarnings("unused") Integer anInteger = with(any(Integer.class)); } - private static T with(@SuppressWarnings("unused") Matcher matcher) { return null; } diff --git a/hamcrest/src/test/java/org/hamcrest/core/IsIterableContainingTest.java b/hamcrest/src/test/java/org/hamcrest/core/IsIterableContainingTest.java index 02148b81..94aba195 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/IsIterableContainingTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/IsIterableContainingTest.java @@ -1,57 +1,89 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeDiagnosingMatcher; -import org.junit.Test; - import java.util.ArrayList; +import static java.util.Arrays.asList; import java.util.HashSet; import java.util.Set; - -import static java.util.Arrays.asList; import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeDiagnosingMatcher; +import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsIterableContaining.hasItem; import static org.hamcrest.core.IsIterableContaining.hasItems; -import static org.hamcrest.core.IsEqual.equalTo; +import org.junit.Test; +/** + * Is iterable containing test. + */ public final class IsIterableContainingTest { - - @Test public void - copesWithNullsAndUnknownTypes() { + + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = hasItem(equalTo("irrelevant")); - + assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - @Test public void - matchesACollectionThatContainsAnElementForTheGivenMatcher() { + @Test + public void matchesACollectionThatContainsAnElementForTheGivenMatcher() { final Matcher> itemMatcher = hasItem(equalTo("a")); assertMatches("list containing 'a'", itemMatcher, asList("a", "b", "c")); } - @Test public void - doesNotMatchCollectionWithoutAnElementForGivenMatcher() { + @Test + public void doesNotMatchCollectionWithoutAnElementForGivenMatcher() { final Matcher> matcher = hasItem(mismatchable("a")); - + assertMismatchDescription("mismatches were: [mismatched: b, mismatched: c]", matcher, asList("b", "c")); assertMismatchDescription("was empty", matcher, new ArrayList()); } - @Test public void - doesNotMatchNull() { + @Test + public void doesNotMatchNull() { assertDoesNotMatch("doesn't match null", hasItem(equalTo("a")), null); } - @Test public void - hasAReadableDescription() { + @Test + public void hasAReadableDescription() { assertDescription("a collection containing mismatchable: a", hasItem(mismatchable("a"))); } - - @Test public void - canMatchItemWhenCollectionHoldsSuperclass() { // Issue 24 + + @Test + public void canMatchItemWhenCollectionHoldsSuperclass() { // Issue 24 final Set s = new HashSet<>(); s.add(2); @@ -60,28 +92,28 @@ public final class IsIterableContainingTest { } @SuppressWarnings("unchecked") - @Test public void - matchesMultipleItemsInCollection() { + @Test + public void matchesMultipleItemsInCollection() { final Matcher> matcher1 = hasItems(equalTo("a"), equalTo("b"), equalTo("c")); assertMatches("list containing all items", matcher1, asList("a", "b", "c")); - + final Matcher> matcher2 = hasItems("a", "b", "c"); assertMatches("list containing all items (without matchers)", matcher2, asList("a", "b", "c")); - + final Matcher> matcher3 = hasItems(equalTo("a"), equalTo("b"), equalTo("c")); assertMatches("list containing all items in any order", matcher3, asList("c", "b", "a")); - + final Matcher> matcher4 = hasItems(equalTo("a"), equalTo("b"), equalTo("c")); assertMatches("list containing all items plus others", matcher4, asList("e", "c", "b", "a", "d")); - + final Matcher> matcher5 = hasItems(equalTo("a"), equalTo("b"), equalTo("c")); assertDoesNotMatch("not match list unless it contains all items", matcher5, asList("e", "c", "b", "d")); // 'a' missing } - - @Test public void - reportsMismatchWithAReadableDescriptionForMultipleItems() { + + @Test + public void reportsMismatchWithAReadableDescriptionForMultipleItems() { final Matcher> matcher = hasItems(3, 4); - + assertMismatchDescription("a collection containing <4> mismatches were: [was <1>, was <2>, was <3>]", matcher, asList(1, 2, 3)); } @@ -90,8 +122,9 @@ private static Matcher mismatchable(final String string) { return new TypeSafeDiagnosingMatcher() { @Override protected boolean matchesSafely(String item, Description mismatchDescription) { - if (string.equals(item)) + if (string.equals(item)) { return true; + } mismatchDescription.appendText("mismatched: " + item); return false; diff --git a/hamcrest/src/test/java/org/hamcrest/core/IsNotTest.java b/hamcrest/src/test/java/org/hamcrest/core/IsNotTest.java index 79f46837..9a9d7fd7 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/IsNotTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/IsNotTest.java @@ -1,41 +1,74 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsNot.not; +import org.junit.Test; +/** + * Is not test. + */ public final class IsNotTest { - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = not("something"); assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - @Test public void - evaluatesToTheTheLogicalNegationOfAnotherMatcher() { + @Test + public void evaluatesToTheTheLogicalNegationOfAnotherMatcher() { final Matcher matcher = not(equalTo("A")); assertMatches(matcher, "B"); assertDoesNotMatch(matcher, "A"); } - @Test public void - providesConvenientShortcutForNotEqualTo() { + @Test + public void providesConvenientShortcutForNotEqualTo() { final Matcher matcher = not("A"); assertMatches(matcher, "B"); assertDoesNotMatch(matcher, "A"); } - @Test public void - usesDescriptionOfNegatedMatcherWithPrefix() { + @Test + public void usesDescriptionOfNegatedMatcherWithPrefix() { assertDescription("not an instance of java.lang.String", not(instanceOf(String.class))); assertDescription("not \"A\"", not("A")); } diff --git a/hamcrest/src/test/java/org/hamcrest/core/IsNullTest.java b/hamcrest/src/test/java/org/hamcrest/core/IsNullTest.java index 74b046b5..2245f321 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/IsNullTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/IsNullTest.java @@ -1,38 +1,70 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.core.IsNull.notNullValue; import static org.hamcrest.core.IsNull.nullValue; +import org.junit.Test; - +/** + * Is null test. + */ public final class IsNullTest { private final Matcher nullMatcher = nullValue(); private final Matcher notNullMatcher = notNullValue(); - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { assertNullSafe(nullMatcher); assertUnknownTypeSafe(nullMatcher); - + assertNullSafe(notNullMatcher); assertUnknownTypeSafe(notNullMatcher); } - @Test public void - evaluatesToTrueIfArgumentIsNull() { + @Test + public void evaluatesToTrueIfArgumentIsNull() { assertMatches(nullMatcher, null); assertDoesNotMatch(nullMatcher, new Object()); - + assertMatches(notNullMatcher, new Object()); assertDoesNotMatch(notNullMatcher, null); } - - @Test public void - supportsStaticTyping() { + + @Test + public void supportsStaticTyping() { requiresStringMatcher(nullValue(String.class)); requiresStringMatcher(notNullValue(String.class)); } diff --git a/hamcrest/src/test/java/org/hamcrest/core/IsSameTest.java b/hamcrest/src/test/java/org/hamcrest/core/IsSameTest.java index a4a20105..130d509a 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/IsSameTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/IsSameTest.java @@ -1,25 +1,57 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.core.IsSame.sameInstance; import static org.hamcrest.core.IsSame.theInstance; +import org.junit.Test; - +/** + * Is same test. + */ public final class IsSameTest { - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = sameInstance("irrelevant"); - + assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - @Test public void - evaluatesToTrueIfArgumentIsReferenceToASpecifiedObject() { + @Test + public void evaluatesToTrueIfArgumentIsReferenceToASpecifiedObject() { Object o1 = new Object(); Matcher matcher = sameInstance(o1); @@ -27,8 +59,8 @@ public final class IsSameTest { assertDoesNotMatch(matcher, new Object()); } - @Test public void - alternativeFactoryMethodAlsoMatchesOnlyIfArgumentIsReferenceToASpecifiedObject() { + @Test + public void alternativeFactoryMethodAlsoMatchesOnlyIfArgumentIsReferenceToASpecifiedObject() { Object o1 = new Object(); Matcher matcher = theInstance(o1); @@ -36,13 +68,13 @@ public final class IsSameTest { assertDoesNotMatch(matcher, new Object()); } - @Test public void - returnsReadableDescriptionFromToString() { + @Test + public void returnsReadableDescriptionFromToString() { assertDescription("sameInstance(\"ARG\")", sameInstance("ARG")); } - @Test public void - returnsReadableDescriptionFromToStringWhenInitialisedWithNull() { + @Test + public void returnsReadableDescriptionFromToStringWhenInitialisedWithNull() { assertDescription("sameInstance(null)", sameInstance(null)); } } diff --git a/hamcrest/src/test/java/org/hamcrest/core/IsTest.java b/hamcrest/src/test/java/org/hamcrest/core/IsTest.java index d5220bde..3d561660 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/IsTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/IsTest.java @@ -1,48 +1,81 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.isA; import static org.hamcrest.core.IsEqual.equalTo; +import org.junit.Test; +/** + * Is test. + */ public final class IsTest { - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = is("something"); - + assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - @Test public void - matchesTheSameWayTheUnderlyingMatcherDoes() { + @Test + public void matchesTheSameWayTheUnderlyingMatcherDoes() { final Matcher matcher = is(equalTo(true)); assertMatches(matcher, true); assertDoesNotMatch(matcher, false); } - @Test public void - generatesIsPrefixInDescription() { + @Test + public void generatesIsPrefixInDescription() { assertDescription("is ", is(equalTo(true))); assertDescription("is \"A\"", is("A")); } - @Test public void - providesConvenientShortcutForIsEqualTo() { + @Test + public void providesConvenientShortcutForIsEqualTo() { final Matcher matcher = is("A"); - + assertMatches(matcher, "A"); assertDoesNotMatch(is("A"), "B"); } @SuppressWarnings({ "unchecked", "rawtypes" }) - @Test public void - providesConvenientShortcutForIsInstanceOf() { + @Test + public void providesConvenientShortcutForIsInstanceOf() { final Matcher matcher = isA(Number.class); assertMatches(matcher, 1); assertDoesNotMatch(matcher, new Object()); diff --git a/hamcrest/src/test/java/org/hamcrest/core/SampleBaseClass.java b/hamcrest/src/test/java/org/hamcrest/core/SampleBaseClass.java index baf4d8e9..2f280376 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/SampleBaseClass.java +++ b/hamcrest/src/test/java/org/hamcrest/core/SampleBaseClass.java @@ -1,5 +1,39 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; +/** + * Sample bean class. + */ public class SampleBaseClass { String value; @@ -19,6 +53,6 @@ public boolean equals(Object obj) { @Override public int hashCode() { - return value.hashCode(); + return value.hashCode(); } } diff --git a/hamcrest/src/test/java/org/hamcrest/core/SampleSubClass.java b/hamcrest/src/test/java/org/hamcrest/core/SampleSubClass.java index bdaa160f..74059674 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/SampleSubClass.java +++ b/hamcrest/src/test/java/org/hamcrest/core/SampleSubClass.java @@ -1,7 +1,41 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; +/** + * Sample bean subclass. + */ public class SampleSubClass extends SampleBaseClass { - + public SampleSubClass(String value) { super(value); } diff --git a/hamcrest/src/test/java/org/hamcrest/core/StringContainsTest.java b/hamcrest/src/test/java/org/hamcrest/core/StringContainsTest.java index 1fc269ef..20fad6e2 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/StringContainsTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/StringContainsTest.java @@ -1,12 +1,44 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - import static org.hamcrest.core.StringContains.containsString; import static org.hamcrest.core.StringContains.containsStringIgnoringCase; - +/** + * String contains test. + */ public class StringContainsTest extends AbstractMatcherTest { static final String EXCERPT = "EXCERPT"; final Matcher stringContains = containsString(EXCERPT); diff --git a/hamcrest/src/test/java/org/hamcrest/core/StringEndsWithTest.java b/hamcrest/src/test/java/org/hamcrest/core/StringEndsWithTest.java index f482cbfa..1bae2567 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/StringEndsWithTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/StringEndsWithTest.java @@ -1,12 +1,44 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - import static org.hamcrest.core.StringEndsWith.endsWith; import static org.hamcrest.core.StringEndsWith.endsWithIgnoringCase; - +/** + * String endsWith test. + */ public class StringEndsWithTest extends AbstractMatcherTest { static final String EXCERPT = "EXCERPT"; final Matcher stringEndsWith = endsWith(EXCERPT); diff --git a/hamcrest/src/test/java/org/hamcrest/core/StringMatchingTest.java b/hamcrest/src/test/java/org/hamcrest/core/StringMatchingTest.java index 7c2e5cd0..e593c286 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/StringMatchingTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/StringMatchingTest.java @@ -1,35 +1,66 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - import static org.hamcrest.core.StringContains.containsString; import static org.hamcrest.core.StringEndsWith.endsWith; import static org.hamcrest.core.StringStartsWith.startsWith; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; /** * @author Steve Freeman 2016 http://www.hamcrest.com */ public class StringMatchingTest { - @Rule public final ExpectedException thrown = ExpectedException.none(); + @Rule + public final ExpectedException thrown = ExpectedException.none(); - @Test public void - startsWithFailsWithNullSubstring() { - thrown.expect(IllegalArgumentException.class); - startsWith(null); - } + @Test + public void startsWithFailsWithNullSubstring() { + thrown.expect(IllegalArgumentException.class); + startsWith(null); + } - @Test public void - endWithFailsWithNullSubstring() { - thrown.expect(IllegalArgumentException.class); - endsWith(null); - } + @Test + public void endWithFailsWithNullSubstring() { + thrown.expect(IllegalArgumentException.class); + endsWith(null); + } - @Test public void - containsFailsWithNullSubstring() { - thrown.expect(IllegalArgumentException.class); - containsString(null); - } + @Test + public void containsFailsWithNullSubstring() { + thrown.expect(IllegalArgumentException.class); + containsString(null); + } } diff --git a/hamcrest/src/test/java/org/hamcrest/core/StringRegularExpressionTest.java b/hamcrest/src/test/java/org/hamcrest/core/StringRegularExpressionTest.java index 2b2991bf..dc710f94 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/StringRegularExpressionTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/StringRegularExpressionTest.java @@ -1,25 +1,56 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - import static org.hamcrest.core.StringRegularExpression.matchesRegex; /** * @author Steve Freeman 2016 http://www.hamcrest.com */ public class StringRegularExpressionTest extends AbstractMatcherTest { - public final Matcher matcher = matchesRegex("^[0-9]+$"); - - @Override - protected Matcher createMatcher() { return matcher; } + public final Matcher matcher = matchesRegex("^[0-9]+$"); + @Override + protected Matcher createMatcher() { + return matcher; + } - public void testMatchingRegex() { - assertMatches(matcher, "12"); - assertDoesNotMatch(matcher, "abc"); + public void testMatchingRegex() { + assertMatches(matcher, "12"); + assertDoesNotMatch(matcher, "abc"); - assertDescription("a string matching the pattern <^[0-9]+$>", matcher); - assertMismatchDescription("the string was \"bcd\"", matcher, "bcd"); - } + assertDescription("a string matching the pattern <^[0-9]+$>", matcher); + assertMismatchDescription("the string was \"bcd\"", matcher, "bcd"); + } } diff --git a/hamcrest/src/test/java/org/hamcrest/core/StringStartsWithTest.java b/hamcrest/src/test/java/org/hamcrest/core/StringStartsWithTest.java index f093acb4..ee4acf8c 100644 --- a/hamcrest/src/test/java/org/hamcrest/core/StringStartsWithTest.java +++ b/hamcrest/src/test/java/org/hamcrest/core/StringStartsWithTest.java @@ -1,12 +1,44 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.core; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - import static org.hamcrest.core.StringStartsWith.startsWith; import static org.hamcrest.core.StringStartsWith.startsWithIgnoringCase; - +/** + * String startsWith test. + */ public class StringStartsWithTest extends AbstractMatcherTest { static final String EXCERPT = "EXCERPT"; final Matcher stringStartsWith = startsWith(EXCERPT); diff --git a/hamcrest/src/test/java/org/hamcrest/io/FileMatchersTest.java b/hamcrest/src/test/java/org/hamcrest/io/FileMatchersTest.java index c94e147d..967539b0 100644 --- a/hamcrest/src/test/java/org/hamcrest/io/FileMatchersTest.java +++ b/hamcrest/src/test/java/org/hamcrest/io/FileMatchersTest.java @@ -1,13 +1,45 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.io; -import org.hamcrest.AbstractMatcherTest; -import org.hamcrest.Matcher; - import java.io.File; import java.io.IOException; - +import org.hamcrest.AbstractMatcherTest; +import org.hamcrest.Matcher; import static org.hamcrest.core.IsEqual.equalTo; +/** + * File matchers test. + */ @SuppressWarnings("ResultOfMethodCallIgnored") public class FileMatchersTest extends AbstractMatcherTest { @@ -19,11 +51,11 @@ protected void setUp() throws IOException { directory = File.createTempFile("myDir", ""); assertTrue("deleting " + directory, directory.delete()); assertTrue("mkdir " + directory, directory.mkdirs()); - + file = new File(directory, "myFile"); file.createNewFile(); } - + public void testAnExistingDirectory() { assertMatches("matches existing directory", FileMatchers.anExistingDirectory(), directory); assertDoesNotMatch("doesn't match existing file", FileMatchers.anExistingDirectory(), file); diff --git a/hamcrest/src/test/java/org/hamcrest/number/BigDecimalCloseToTest.java b/hamcrest/src/test/java/org/hamcrest/number/BigDecimalCloseToTest.java index c82e6f4e..325bed89 100644 --- a/hamcrest/src/test/java/org/hamcrest/number/BigDecimalCloseToTest.java +++ b/hamcrest/src/test/java/org/hamcrest/number/BigDecimalCloseToTest.java @@ -1,45 +1,77 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.number; +import java.math.BigDecimal; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - -import java.math.BigDecimal; - import static org.hamcrest.number.BigDecimalCloseTo.closeTo; +/** + * Big decimal close to test. + */ public class BigDecimalCloseToTest extends AbstractMatcherTest { - private final Matcher matcher = closeTo(new BigDecimal("1.0"), new BigDecimal("0.5")); - - @Override - protected Matcher createMatcher() { - BigDecimal irrelevant = new BigDecimal("0.01"); - return closeTo(irrelevant, irrelevant); - } - - public void testEvaluatesToTrueIfArgumentIsEqualToABigDecimalWithinSomeError() { - assertTrue(matcher.matches(new BigDecimal("1.0"))); - assertTrue(matcher.matches(new BigDecimal("0.5"))); - assertTrue(matcher.matches(new BigDecimal("1.5"))); - - assertDoesNotMatch("too large", matcher, new BigDecimal("2.0")); - assertMismatchDescription("<2.0> differed by <0.5> more than delta <0.5>", matcher, new BigDecimal("2.0")); - assertDoesNotMatch("number too small", matcher, new BigDecimal("0.0")); - assertMismatchDescription("<0.0> differed by <0.5> more than delta <0.5>", matcher, new BigDecimal("0.0")); - } - - public void testEvaluatesToTrueIfArgumentHasDifferentScale() { - assertTrue(matcher.matches(new BigDecimal("1.000000"))); - assertTrue(matcher.matches(new BigDecimal("0.500000"))); - assertTrue(matcher.matches(new BigDecimal("1.500000"))); - - assertDoesNotMatch("too large", matcher, new BigDecimal("2.000000")); - assertMismatchDescription("<2.000000> differed by <0.5> more than delta <0.5>", matcher, new BigDecimal("2.000000")); - assertDoesNotMatch("number too small", matcher, new BigDecimal("0.000000")); - assertMismatchDescription("<0.000000> differed by <0.5> more than delta <0.5>", matcher, new BigDecimal("0.000000")); - } - - public void test_is_self_describing() { - assertDescription("a numeric value within <0.5> of <1.0>", matcher); - } + private final Matcher matcher = closeTo(new BigDecimal("1.0"), new BigDecimal("0.5")); + + @Override + protected Matcher createMatcher() { + BigDecimal irrelevant = new BigDecimal("0.01"); + return closeTo(irrelevant, irrelevant); + } + + public void testEvaluatesToTrueIfArgumentIsEqualToABigDecimalWithinSomeError() { + assertTrue(matcher.matches(new BigDecimal("1.0"))); + assertTrue(matcher.matches(new BigDecimal("0.5"))); + assertTrue(matcher.matches(new BigDecimal("1.5"))); + + assertDoesNotMatch("too large", matcher, new BigDecimal("2.0")); + assertMismatchDescription("<2.0> differed by <0.5> more than delta <0.5>", matcher, new BigDecimal("2.0")); + assertDoesNotMatch("number too small", matcher, new BigDecimal("0.0")); + assertMismatchDescription("<0.0> differed by <0.5> more than delta <0.5>", matcher, new BigDecimal("0.0")); + } + + public void testEvaluatesToTrueIfArgumentHasDifferentScale() { + assertTrue(matcher.matches(new BigDecimal("1.000000"))); + assertTrue(matcher.matches(new BigDecimal("0.500000"))); + assertTrue(matcher.matches(new BigDecimal("1.500000"))); + + assertDoesNotMatch("too large", matcher, new BigDecimal("2.000000")); + assertMismatchDescription("<2.000000> differed by <0.5> more than delta <0.5>", matcher, new BigDecimal("2.000000")); + assertDoesNotMatch("number too small", matcher, new BigDecimal("0.000000")); + assertMismatchDescription("<0.000000> differed by <0.5> more than delta <0.5>", matcher, new BigDecimal("0.000000")); + } + + public void testIsSelfDescribing() { + assertDescription("a numeric value within <0.5> of <1.0>", matcher); + } } diff --git a/hamcrest/src/test/java/org/hamcrest/number/IsCloseToTest.java b/hamcrest/src/test/java/org/hamcrest/number/IsCloseToTest.java index 8b0e244b..1d1007b1 100644 --- a/hamcrest/src/test/java/org/hamcrest/number/IsCloseToTest.java +++ b/hamcrest/src/test/java/org/hamcrest/number/IsCloseToTest.java @@ -1,20 +1,53 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.number; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - import static org.hamcrest.number.IsCloseTo.closeTo; +/** + * Is close to test. + */ public class IsCloseToTest extends AbstractMatcherTest { - private final Matcher matcher = closeTo(1.0d, 0.5d); + private final Matcher matcher = closeTo(1.0d, 0.5d); - @Override + @Override protected Matcher createMatcher() { final double irrelevant = 0.1; return closeTo(irrelevant, irrelevant); } - public void test_matchesIfArgumentIsEqualToADoubleValueWithinSomeError() { + public void testMatchesIfArgumentIsEqualToADoubleValueWithinSomeError() { assertMatches("1.0", matcher, 1.0); assertMatches("0.5d", matcher, 0.5d); assertMatches("1.5d", matcher, 1.5d); @@ -25,7 +58,7 @@ public void test_matchesIfArgumentIsEqualToADoubleValueWithinSomeError() { assertMismatchDescription("<0.1> differed by <0.4> more than delta <0.5>", matcher, 0.1); } - public void test_is_self_describing() { + public void testIsSelfDescribing() { assertDescription("a numeric value within <0.5> of <1.0>", matcher); } diff --git a/hamcrest/src/test/java/org/hamcrest/number/IsNanTest.java b/hamcrest/src/test/java/org/hamcrest/number/IsNanTest.java index c9b39568..a5be736f 100644 --- a/hamcrest/src/test/java/org/hamcrest/number/IsNanTest.java +++ b/hamcrest/src/test/java/org/hamcrest/number/IsNanTest.java @@ -1,43 +1,76 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.number; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.number.IsNaN.notANumber; +import org.junit.Test; +/** + * Is NaN test. + */ public final class IsNanTest { - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = notANumber(); - + assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - @Test public void - matchesNaN() { + @Test + public void matchesNaN() { assertMatches(notANumber(), Double.NaN); } - @Test public void - doesNotMatchDoubleValue() { + @Test + public void doesNotMatchDoubleValue() { assertDoesNotMatch(notANumber(), 1.25); } - @Test public void - doesNotMatchInfinity() { + @Test + public void doesNotMatchInfinity() { assertDoesNotMatch(notANumber(), Double.POSITIVE_INFINITY); } - @Test public void - describesItself() { + @Test + public void describesItself() { assertDescription("a double value of NaN", notANumber()); } - @Test public void - describesAMismatch() { + @Test + public void describesAMismatch() { assertMismatchDescription("was <1.25>", notANumber(), 1.25); } } diff --git a/hamcrest/src/test/java/org/hamcrest/number/OrderingComparisonTest.java b/hamcrest/src/test/java/org/hamcrest/number/OrderingComparisonTest.java index 5953bd0b..a381ddf9 100644 --- a/hamcrest/src/test/java/org/hamcrest/number/OrderingComparisonTest.java +++ b/hamcrest/src/test/java/org/hamcrest/number/OrderingComparisonTest.java @@ -1,14 +1,46 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.number; +import java.math.BigDecimal; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - -import java.math.BigDecimal; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsNot.not; import static org.hamcrest.number.OrderingComparison.*; +/** + * Ordering comparison test. + */ public class OrderingComparisonTest extends AbstractMatcherTest { @Override @@ -17,18 +49,18 @@ protected Matcher createMatcher() { } public void testDescription() { - assertDescription("a value greater than <1>", greaterThan(1)); - assertDescription("a value equal to or greater than <1>", greaterThanOrEqualTo(1)); - assertDescription("a value equal to <1>", comparesEqualTo(1)); - assertDescription("a value less than or equal to <1>", lessThanOrEqualTo(1)); - assertDescription("a value less than <1>", lessThan(1)); + assertDescription("a value greater than <1>", greaterThan(1)); + assertDescription("a value equal to or greater than <1>", greaterThanOrEqualTo(1)); + assertDescription("a value equal to <1>", comparesEqualTo(1)); + assertDescription("a value less than or equal to <1>", lessThanOrEqualTo(1)); + assertDescription("a value less than <1>", lessThan(1)); } public void testMismatchDescriptions() { - assertMismatchDescription("<0> was less than <1>", greaterThan(1), 0); - assertMismatchDescription("<1> was equal to <1>", greaterThan(1), 1); - assertMismatchDescription("<1> was greater than <0>", lessThan(0), 1); - assertMismatchDescription("<2> was equal to <2>", lessThan(2), 2); + assertMismatchDescription("<0> was less than <1>", greaterThan(1), 0); + assertMismatchDescription("<1> was equal to <1>", greaterThan(1), 1); + assertMismatchDescription("<1> was greater than <0>", lessThan(0), 1); + assertMismatchDescription("<2> was equal to <2>", lessThan(2), 2); } public void testComparesObjectsForGreaterThan() { @@ -43,8 +75,8 @@ public void testComparesObjectsForLessThan() { public void testComparesObjectsForEquality() { - assertThat(3, comparesEqualTo(3)); - assertThat("aa", comparesEqualTo("aa")); + assertThat(3, comparesEqualTo(3)); + assertThat("aa", comparesEqualTo("aa")); } public void testAllowsForInclusiveComparisons() { @@ -58,17 +90,18 @@ public void testSupportsDifferentTypesOfComparableObjects() { } public void testComparesBigDecimalsWithDifferentScalesCorrectlyForIssue20() { - assertThat(new BigDecimal("10.0"), greaterThanOrEqualTo(new BigDecimal("10"))); - assertThat(new BigDecimal(10), greaterThanOrEqualTo(new BigDecimal("10.0"))); - assertThat(new BigDecimal("2"), comparesEqualTo(new BigDecimal("2.000"))); + assertThat(new BigDecimal("10.0"), greaterThanOrEqualTo(new BigDecimal("10"))); + assertThat(new BigDecimal(10), greaterThanOrEqualTo(new BigDecimal("10.0"))); + assertThat(new BigDecimal("2"), comparesEqualTo(new BigDecimal("2.000"))); } - + public void testComparesCustomTypesWhoseCompareToReturnsValuesGreaterThatOne() { assertThat(new CustomInt(5), lessThan(new CustomInt(10))); } private static final class CustomInt implements Comparable { private final int value; + public CustomInt(int value) { this.value = value; } diff --git a/hamcrest/src/test/java/org/hamcrest/object/HasEqualsValuesTest.java b/hamcrest/src/test/java/org/hamcrest/object/HasEqualsValuesTest.java index 44aa7619..368e1315 100644 --- a/hamcrest/src/test/java/org/hamcrest/object/HasEqualsValuesTest.java +++ b/hamcrest/src/test/java/org/hamcrest/object/HasEqualsValuesTest.java @@ -1,8 +1,42 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.object; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; +/** + * Has equals values test. + */ @SuppressWarnings("WeakerAccess") public class HasEqualsValuesTest extends AbstractMatcherTest { private static final WithPublicFields WITH_PUBLIC_FIELDS = new WithPublicFields('x', 666, "a string"); @@ -13,28 +47,31 @@ protected Matcher createMatcher() { return WITH_PUBLIC_FIELDS_MATCHER; } - public void test_describes_itself() { + public void testDescribesItself() { assertDescription( "WithPublicFields has values [i: <666>, s: \"a string\", c: \"x\"]", WITH_PUBLIC_FIELDS_MATCHER); } - public void test_matches_equivalent_object() { + public void testMatchesEquivalentObject() { assertMatches(WITH_PUBLIC_FIELDS_MATCHER, new WithPublicFields('x', 666, "a string")); } - public void test_mismatches_on_first_field_inequality() { + public void testMismatchesOnFirstFieldInequality() { assertMismatchDescription( "'s' was \"different\"", WITH_PUBLIC_FIELDS_MATCHER, new WithPublicFields('x', 666, "different")); } - public void test_mismatches_on_inherited_field() { + public void testMismatchesOnInheritedField() { assertMismatchDescription( "'c' was \"y\"", WITH_PUBLIC_FIELDS_MATCHER, new WithPublicFields('y', 666, "a string")); } + /** + * With public fields implementation. + */ public static class WithPublicFields extends Parent { public final int i; public final String s; @@ -46,6 +83,9 @@ public WithPublicFields(char c, int i, String s) { } } + /** + * Parent class. + */ public static class Parent { public final char c; diff --git a/hamcrest/src/test/java/org/hamcrest/object/HasToStringTest.java b/hamcrest/src/test/java/org/hamcrest/object/HasToStringTest.java index 5c75ae7d..6d5d003a 100644 --- a/hamcrest/src/test/java/org/hamcrest/object/HasToStringTest.java +++ b/hamcrest/src/test/java/org/hamcrest/object/HasToStringTest.java @@ -1,12 +1,45 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.object; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.object.HasToString.hasToString; +import org.junit.Test; +/** + * Has toString test. + */ public final class HasToStringTest { private static final String TO_STRING_RESULT = "toString result"; private static final Object TEST_OBJECT = new Object() { @@ -16,40 +49,40 @@ public String toString() { } }; - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = hasToString(equalTo("irrelevant")); - + assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - - @Test public void - matchesWhenUtilisingANestedMatcher() { - final Matcher matcher = hasToString(equalTo(TO_STRING_RESULT)); - assertMatches(matcher, TEST_OBJECT); - assertDoesNotMatch(matcher, new Object()); + @Test + public void matchesWhenUtilisingANestedMatcher() { + final Matcher matcher = hasToString(equalTo(TO_STRING_RESULT)); + + assertMatches(matcher, TEST_OBJECT); + assertDoesNotMatch(matcher, new Object()); } - @Test public void - matchesWhenUsingShortcutForHasToStringEqualTo() { - final Matcher matcher = hasToString(TO_STRING_RESULT); - - assertMatches(matcher, TEST_OBJECT); - assertDoesNotMatch(matcher, new Object()); + @Test + public void matchesWhenUsingShortcutForHasToStringEqualTo() { + final Matcher matcher = hasToString(TO_STRING_RESULT); + + assertMatches(matcher, TEST_OBJECT); + assertDoesNotMatch(matcher, new Object()); } - @Test public void - describesItself() { - final Matcher matcher = hasToString(equalTo(TO_STRING_RESULT)); + @Test + public void describesItself() { + final Matcher matcher = hasToString(equalTo(TO_STRING_RESULT)); assertDescription("with toString() \"toString result\"", matcher); } - @Test public void - describesAMismatch() { - final Matcher matcher = hasToString(equalTo(TO_STRING_RESULT)); - String expectedMismatchString = "toString() was \"Cheese\""; + @Test + public void describesAMismatch() { + final Matcher matcher = hasToString(equalTo(TO_STRING_RESULT)); + String expectedMismatchString = "toString() was \"Cheese\""; assertMismatchDescription(expectedMismatchString, matcher, "Cheese"); } } diff --git a/hamcrest/src/test/java/org/hamcrest/object/IsCompatibleTypeTest.java b/hamcrest/src/test/java/org/hamcrest/object/IsCompatibleTypeTest.java index 62a3637c..947918ee 100644 --- a/hamcrest/src/test/java/org/hamcrest/object/IsCompatibleTypeTest.java +++ b/hamcrest/src/test/java/org/hamcrest/object/IsCompatibleTypeTest.java @@ -1,24 +1,73 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.object; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.object.IsCompatibleType.typeCompatibleWith; +/** + * Is compatible type test. + */ public class IsCompatibleTypeTest extends AbstractMatcherTest { + + /** + * The base class. + */ static class BaseClass { } + /** + * The extended class. + */ private static class ExtendedClass extends BaseClass { } + /** + * The base interface. + */ interface BaseInterface { } + /** + * The extended interface. + */ interface ExtendedInterface extends BaseInterface { } + /** + * Class implementing base interface. + */ private static class ClassImplementingBaseInterface implements BaseInterface { } diff --git a/hamcrest/src/test/java/org/hamcrest/object/IsEventFromTest.java b/hamcrest/src/test/java/org/hamcrest/object/IsEventFromTest.java index b3c4a3a5..561b233e 100644 --- a/hamcrest/src/test/java/org/hamcrest/object/IsEventFromTest.java +++ b/hamcrest/src/test/java/org/hamcrest/object/IsEventFromTest.java @@ -1,14 +1,45 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.object; +import java.util.EventObject; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - -import java.util.EventObject; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.object.IsEventFrom.eventFrom; - +/** + * Is event from test. + */ public class IsEventFromTest extends AbstractMatcherTest { @Override diff --git a/hamcrest/src/test/java/org/hamcrest/object/MatchesPatternTest.java b/hamcrest/src/test/java/org/hamcrest/object/MatchesPatternTest.java index 3e2d9114..d3d5550a 100644 --- a/hamcrest/src/test/java/org/hamcrest/object/MatchesPatternTest.java +++ b/hamcrest/src/test/java/org/hamcrest/object/MatchesPatternTest.java @@ -1,14 +1,46 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.object; -import org.hamcrest.Matcher; -import org.hamcrest.text.MatchesPattern; -import org.junit.Test; - import java.util.regex.Pattern; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; +import org.hamcrest.text.MatchesPattern; import static org.junit.Assert.assertThat; +import org.junit.Test; +/** + * Matches pattern test. + */ public class MatchesPatternTest { @Test public void copesWithNullsAndUnknownTypes() { diff --git a/hamcrest/src/test/java/org/hamcrest/text/CharSequenceLengthTest.java b/hamcrest/src/test/java/org/hamcrest/text/CharSequenceLengthTest.java index 76629465..46600858 100644 --- a/hamcrest/src/test/java/org/hamcrest/text/CharSequenceLengthTest.java +++ b/hamcrest/src/test/java/org/hamcrest/text/CharSequenceLengthTest.java @@ -1,8 +1,38 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.text; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - import static org.hamcrest.number.OrderingComparison.lessThan; import static org.hamcrest.text.CharSequenceLength.hasLength; @@ -17,7 +47,7 @@ protected Matcher createMatcher() { return hasLength(4); } - public void test_matchesExactLengthOf_CharSequence() { + public void testMatchesExactLengthOfCharSequence() { final Matcher matcher = hasLength(4); assertMatches(matcher, "aaaa"); assertMatches(matcher, "a b "); @@ -26,7 +56,7 @@ public void test_matchesExactLengthOf_CharSequence() { } - public void test_matchesRelativeLengthOf_CharSequence() { + public void testMatchesRelativeLengthOfCharSequence() { final Matcher matcher = hasLength(lessThan(4)); assertMatches(matcher, "aaa"); assertMatches(matcher, "a b"); diff --git a/hamcrest/src/test/java/org/hamcrest/text/IsBlankStringTest.java b/hamcrest/src/test/java/org/hamcrest/text/IsBlankStringTest.java index c5f35f1c..c5547f71 100644 --- a/hamcrest/src/test/java/org/hamcrest/text/IsBlankStringTest.java +++ b/hamcrest/src/test/java/org/hamcrest/text/IsBlankStringTest.java @@ -1,54 +1,87 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.text; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.text.IsBlankString.blankOrNullString; import static org.hamcrest.text.IsBlankString.blankString; +import org.junit.Test; +/** + * Is blank string test. + */ public final class IsBlankStringTest { - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = blankString(); - + assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - @Test public void - matchesEmptyString() { + @Test + public void matchesEmptyString() { assertMatches(blankOrNullString(), ""); assertMatches(blankString(), ""); } - @Test public void - matchesNullAppropriately() { + @Test + public void matchesNullAppropriately() { assertMatches(blankOrNullString(), null); assertDoesNotMatch(blankString(), null); } - @Test public void - matchesBlankStringAppropriately() { + @Test + public void matchesBlankStringAppropriately() { assertMatches(blankString(), " \t"); assertMatches(blankOrNullString(), " \t"); } - @Test public void - doesNotMatchFilledString() { + @Test + public void doesNotMatchFilledString() { assertDoesNotMatch(blankString(), "a"); assertDoesNotMatch(blankOrNullString(), "a"); } - @Test public void - describesItself() { + @Test + public void describesItself() { assertDescription("a blank string", blankString()); assertDescription("(null or a blank string)", blankOrNullString()); } - @Test public void - describesAMismatch() { + @Test + public void describesAMismatch() { assertMismatchDescription("was \"a\"", blankString(), "a"); assertMismatchDescription("was \"a\"", blankOrNullString(), "a"); } diff --git a/hamcrest/src/test/java/org/hamcrest/text/IsEmptyStringTest.java b/hamcrest/src/test/java/org/hamcrest/text/IsEmptyStringTest.java index 62e30535..8ece626a 100644 --- a/hamcrest/src/test/java/org/hamcrest/text/IsEmptyStringTest.java +++ b/hamcrest/src/test/java/org/hamcrest/text/IsEmptyStringTest.java @@ -1,54 +1,87 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.text; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.text.IsEmptyString.emptyOrNullString; import static org.hamcrest.text.IsEmptyString.emptyString; +import org.junit.Test; +/** + * Is empty string test. + */ public final class IsEmptyStringTest { - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = emptyString(); - + assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - @Test public void - matchesEmptyString() { + @Test + public void matchesEmptyString() { assertMatches(emptyOrNullString(), ""); assertMatches(emptyString(), ""); } - @Test public void - matchesNullAppropriately() { + @Test + public void matchesNullAppropriately() { assertMatches(emptyOrNullString(), null); assertDoesNotMatch(emptyString(), null); } - @Test public void - matchesBlankStringAppropriately() { + @Test + public void matchesBlankStringAppropriately() { assertDoesNotMatch(emptyString(), " "); assertDoesNotMatch(emptyOrNullString(), " "); } - @Test public void - doesNotMatchFilledString() { + @Test + public void doesNotMatchFilledString() { assertDoesNotMatch(emptyString(), "a"); assertDoesNotMatch(emptyOrNullString(), "a"); } - @Test public void - describesItself() { + @Test + public void describesItself() { assertDescription("an empty string", emptyString()); assertDescription("(null or an empty string)", emptyOrNullString()); } - @Test public void - describesAMismatch() { + @Test + public void describesAMismatch() { assertMismatchDescription("was \"a\"", emptyString(), "a"); assertMismatchDescription("was \"a\"", emptyOrNullString(), "a"); } diff --git a/hamcrest/src/test/java/org/hamcrest/text/IsEqualCompressingWhiteSpaceTest.java b/hamcrest/src/test/java/org/hamcrest/text/IsEqualCompressingWhiteSpaceTest.java index 2f09c136..2171ffcc 100644 --- a/hamcrest/src/test/java/org/hamcrest/text/IsEqualCompressingWhiteSpaceTest.java +++ b/hamcrest/src/test/java/org/hamcrest/text/IsEqualCompressingWhiteSpaceTest.java @@ -1,10 +1,43 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.text; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - import static org.hamcrest.text.IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace; +/** + * Is equal compressing whitespace test. + */ public class IsEqualCompressingWhiteSpaceTest extends AbstractMatcherTest { private final Matcher matcher = equalToCompressingWhiteSpace(" Hello World how\n are we? "); @@ -29,7 +62,7 @@ public void testFailsIfWhitespaceIsAddedOrRemovedInMidWord() { assertDoesNotMatch(matcher, "Hello Wo rld how are we?"); } - public void test_has_a_readable_mismatch() { + public void testHasAReadableMismatch() { assertMismatchDescription("was \"Hello World how are we \"", matcher, "Hello World how are we "); } diff --git a/hamcrest/src/test/java/org/hamcrest/text/IsEqualIgnoringCaseTest.java b/hamcrest/src/test/java/org/hamcrest/text/IsEqualIgnoringCaseTest.java index 6ca6375c..efed2f2a 100644 --- a/hamcrest/src/test/java/org/hamcrest/text/IsEqualIgnoringCaseTest.java +++ b/hamcrest/src/test/java/org/hamcrest/text/IsEqualIgnoringCaseTest.java @@ -1,62 +1,94 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.text; -import org.hamcrest.Matcher; -import org.junit.Test; - import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase; +import org.junit.Test; +/** + * Is equal ignoring case test. + */ public final class IsEqualIgnoringCaseTest { - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = equalToIgnoringCase("irrelevant"); - + assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - @Test public void - ignoresCaseOfCharsInString() { + @Test + public void ignoresCaseOfCharsInString() { final Matcher matcher = equalToIgnoringCase("heLLo"); - + assertMatches(matcher, "HELLO"); assertMatches(matcher, "hello"); assertMatches(matcher, "HelLo"); - assertDoesNotMatch(matcher, "bye"); + assertDoesNotMatch(matcher, "bye"); } - @Test public void - mismatchesIfAdditionalWhitespaceIsPresent() { - final Matcher matcher = equalToIgnoringCase("heLLo"); - - assertDoesNotMatch(matcher, "hello "); - assertDoesNotMatch(matcher, " hello"); + @Test + public void mismatchesIfAdditionalWhitespaceIsPresent() { + final Matcher matcher = equalToIgnoringCase("heLLo"); + + assertDoesNotMatch(matcher, "hello "); + assertDoesNotMatch(matcher, " hello"); } - @Test public void - mismatchesNull() { - final Matcher matcher = equalToIgnoringCase("heLLo"); - - assertDoesNotMatch(matcher, null); + @Test + public void mismatchesNull() { + final Matcher matcher = equalToIgnoringCase("heLLo"); + + assertDoesNotMatch(matcher, null); } - @Test(expected=IllegalArgumentException.class) public void - canOnlyBeConstructedAboutANonNullString() { + @Test(expected=IllegalArgumentException.class) + public void canOnlyBeConstructedAboutANonNullString() { equalToIgnoringCase(null); } - - @Test public void - describesItself() { - final Matcher matcher = equalToIgnoringCase("heLLo"); + @Test + public void describesItself() { + final Matcher matcher = equalToIgnoringCase("heLLo"); assertDescription("a string equal to \"heLLo\" ignoring case", matcher); } - @Test public void - describesAMismatch() { - final Matcher matcher = equalToIgnoringCase("heLLo"); - String expectedMismatchString = "was \"Cheese\""; + @Test + public void describesAMismatch() { + final Matcher matcher = equalToIgnoringCase("heLLo"); + String expectedMismatchString = "was \"Cheese\""; assertMismatchDescription(expectedMismatchString, matcher, "Cheese"); } } diff --git a/hamcrest/src/test/java/org/hamcrest/text/StringContainsInOrderTest.java b/hamcrest/src/test/java/org/hamcrest/text/StringContainsInOrderTest.java index 52390a82..2869c0e4 100644 --- a/hamcrest/src/test/java/org/hamcrest/text/StringContainsInOrderTest.java +++ b/hamcrest/src/test/java/org/hamcrest/text/StringContainsInOrderTest.java @@ -1,12 +1,44 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.text; +import static java.util.Arrays.asList; import org.hamcrest.AbstractMatcherTest; import org.hamcrest.Matcher; - -import static java.util.Arrays.asList; import static org.hamcrest.text.StringContainsInOrder.stringContainsInOrder; - +/** + * String contains in order test. + */ public class StringContainsInOrderTest extends AbstractMatcherTest { final StringContainsInOrder matcher = new StringContainsInOrder(asList("a", "b", "c", "c")); @@ -14,7 +46,7 @@ public class StringContainsInOrderTest extends AbstractMatcherTest { protected Matcher createMatcher() { return matcher; } - + public void testMatchesOnlyIfStringContainsGivenSubstringsInTheSameOrder() { assertMatches("substrings in order", matcher, "abcc"); assertMatches("substrings separated", matcher, "1a2b3c4c5"); @@ -26,7 +58,7 @@ public void testMatchesOnlyIfStringContainsGivenSubstringsInTheSameOrder() { assertDoesNotMatch("substring missing", matcher, "ac"); assertDoesNotMatch("empty string", matcher, ""); } - + public void testHasAReadableDescription() { assertDescription("a string containing \"a\", \"b\", \"c\", \"c\" in order", matcher); } diff --git a/hamcrest/src/test/java/org/hamcrest/xml/HasXPathTest.java b/hamcrest/src/test/java/org/hamcrest/xml/HasXPathTest.java index a66689dc..2eff1c15 100644 --- a/hamcrest/src/test/java/org/hamcrest/xml/HasXPathTest.java +++ b/hamcrest/src/test/java/org/hamcrest/xml/HasXPathTest.java @@ -1,23 +1,52 @@ +/** + * BSD License + * + * Copyright (c) 2000-2015 www.hamcrest.org + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Hamcrest nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package org.hamcrest.xml; -import org.hamcrest.Matcher; -import org.junit.Test; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -import javax.xml.namespace.NamespaceContext; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import java.io.ByteArrayInputStream; import java.util.HashSet; import java.util.Iterator; - +import javax.xml.namespace.NamespaceContext; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; import static org.hamcrest.AbstractMatcherTest.*; +import org.hamcrest.Matcher; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNot.not; import static org.hamcrest.core.StringContains.containsString; import static org.hamcrest.xml.HasXPath.hasXPath; import static org.junit.Assert.fail; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; /** * @author Joe Walnes @@ -57,16 +86,16 @@ public Iterator getPrefixes(String namespaceURI) { } }; - @Test public void - copesWithNullsAndUnknownTypes() { + @Test + public void copesWithNullsAndUnknownTypes() { Matcher matcher = hasXPath("//irrelevant"); - + assertNullSafe(matcher); assertUnknownTypeSafe(matcher); } - @Test public void - appliesMatcherToXPathInDocument() { + @Test + public void appliesMatcherToXPathInDocument() { assertMatches(hasXPath("/root/something[2]/cheese", equalTo("Cheddar")), xml); assertMatches(hasXPath("//something[1]/cheese", containsString("dam")), xml); assertMatches(hasXPath("//something[2]/cheese", not(containsString("dam"))), xml); @@ -75,37 +104,37 @@ public Iterator getPrefixes(String namespaceURI) { assertMatches(hasXPath("//something[@id='b']/cheese"), xml); } - @Test public void - matchesEmptyElement() { + @Test + public void matchesEmptyElement() { assertMatches(hasXPath("//emptySomething"), xml); } - @Test public void - matchesEmptyElementInNamespace() { + @Test + public void matchesEmptyElementInNamespace() { assertMatches(hasXPath("//cheese:emptySomething", ns), xml); } - @Test public void - failsIfNodeIsMissing() { + @Test + public void failsIfNodeIsMissing() { assertDoesNotMatch(hasXPath("/root/something[3]/cheese", ns, equalTo("Cheddar")), xml); assertDoesNotMatch(hasXPath("//something[@id='c']/cheese", ns), xml); } - @Test public void - failsIfNodeIsMissingInNamespace() { + @Test + public void failsIfNodeIsMissingInNamespace() { assertDoesNotMatch(hasXPath("//cheese:foreignSomething", equalTo("Badger")), xml); assertDoesNotMatch(hasXPath("//cheese:foreignSomething"), xml); } - @Test public void - matchesWithNamespace() { + @Test + public void matchesWithNamespace() { assertMatches(hasXPath("//cheese:foreignSomething", ns), xml); assertMatches(hasXPath("//cheese:foreignSomething/@milk", ns, equalTo("camel")), xml); assertMatches(hasXPath("//cheese:foreignSomething/text()", ns, equalTo("Caravane")), xml); } - @Test public void - throwsIllegalArgumentExceptionIfGivenIllegalExpression() { + @Test + public void throwsIllegalArgumentExceptionIfGivenIllegalExpression() { try { hasXPath("\\g:dfgd::DSgf/root/something[2]/cheese", equalTo("blah")); fail("Expected exception"); @@ -114,22 +143,22 @@ public Iterator getPrefixes(String namespaceURI) { } } - @Test public void - describesItself() { + @Test + public void describesItself() { assertDescription("an XML document with XPath /some/path \"Cheddar\"", hasXPath("/some/path", equalTo("Cheddar"))); - + assertDescription("an XML document with XPath /some/path", hasXPath("/some/path")); } - @Test public void - describesMissingNodeMismatch() { + @Test + public void describesMissingNodeMismatch() { assertMismatchDescription("xpath returned no results.", hasXPath("//honky"), xml); } - @Test public void - describesIncorrectNodeValueMismatch() { + @Test + public void describesIncorrectNodeValueMismatch() { assertMismatchDescription("was \"Edam\"", hasXPath("//something[1]/cheese", equalTo("parmesan")), xml); } @@ -139,8 +168,7 @@ private static Document parse(String xml) { documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); return documentBuilder.parse(new ByteArrayInputStream(xml.getBytes())); - } - catch (Exception e) { + } catch (Exception e) { throw new IllegalStateException(e); } }