001/* 002 * GeoAPI - Java interfaces for OGC/ISO standards 003 * Copyright © 2008-2023 Open Geospatial Consortium, Inc. 004 * http://www.geoapi.org 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.opengis.test; 019 020import java.util.Collection; 021 022 023/** 024 * Extension to JUnit assertion methods. 025 * 026 * @author Martin Desruisseaux (Geomatys) 027 * @version 3.1 028 * @since 2.2 029 * 030 * @deprecated Replaced by {@link Assertion} for consistency with JUnit 5 conventions. 031 */ 032@Deprecated(since="3.1", forRemoval=true) 033@SuppressWarnings("strictfp") // Because we still target Java 11. 034public final strictfp class Assert { 035 /** 036 * Do not allow instantiation of this class. 037 */ 038 private Assert() { 039 } 040 041 /** 042 * Asserts that the given value is an instance of the given class. No tests are performed if 043 * the type is {@code null}. If the type is not-null but the value is null, this is considered 044 * as a failure. 045 * 046 * @param message header of the exception message in case of failure, or {@code null} if none. 047 * @param expectedType the expected parent class of the value, or {@code null} if unrestricted. 048 * @param value the value to test, or {@code null} (which is a failure). 049 * 050 * @deprecated Replaced by {@code org.junit.jupiter.api.Assertions.assertInstanceOf(…)}. 051 */ 052 @Deprecated 053 public static void assertInstanceOf(final String message, final Class<?> expectedType, final Object value) { 054 org.junit.jupiter.api.Assertions.assertInstanceOf(expectedType, value, message); 055 } 056 057 /** 058 * Asserts that the given integer value is positive, including zero. 059 * 060 * @param message header of the exception message in case of failure, or {@code null} if none. 061 * @param value the value to test. 062 */ 063 public static void assertPositive(final String message, final int value) { 064 Assertions.assertPositive(value, message); 065 } 066 067 /** 068 * Asserts that the given integer value is strictly positive, excluding zero. 069 * 070 * @param message header of the exception message in case of failure, or {@code null} if none. 071 * @param value the value to test. 072 */ 073 public static void assertStrictlyPositive(final String message, final int value) { 074 Assertions.assertStrictlyPositive(value, message); 075 } 076 077 /** 078 * Asserts that the given minimum and maximum values make a valid range. More specifically 079 * asserts that if both values are non-null, then the minimum value is not greater than the 080 * maximum value. 081 * 082 * @param <T> the type of values being compared. 083 * @param message header of the exception message in case of failure, or {@code null} if none. 084 * @param minimum the lower bound of the range to test, or {@code null} if unbounded. 085 * @param maximum the upper bound of the range to test, or {@code null} if unbounded. 086 */ 087 @SuppressWarnings("unchecked") 088 public static <T> void assertValidRange(final String message, final Comparable<T> minimum, final Comparable<T> maximum) { 089 Assertions.assertValidRange(minimum, maximum, message); 090 } 091 092 /** 093 * Asserts that the given minimum is smaller or equals to the given maximum. 094 * 095 * @param message header of the exception message in case of failure, or {@code null} if none. 096 * @param minimum the lower bound of the range to test. 097 * @param maximum the upper bound of the range to test. 098 */ 099 public static void assertValidRange(final String message, final int minimum, final int maximum) { 100 Assertions.assertValidRange(minimum, maximum, message); 101 } 102 103 /** 104 * Asserts that the given minimum is smaller or equals to the given maximum. 105 * If one bound is or both bounds are {@linkplain Double#NaN NaN}, then the test fails. 106 * 107 * @param message header of the exception message in case of failure, or {@code null} if none. 108 * @param minimum the lower bound of the range to test. 109 * @param maximum the upper bound of the range to test. 110 */ 111 public static void assertValidRange(final String message, final double minimum, final double maximum) { 112 Assertions.assertValidRange(minimum, maximum, message); 113 } 114 115 /** 116 * Asserts that the given value is inside the given range. This method does <strong>not</strong> 117 * test the validity of the given [{@code minimum} … {@code maximum}] range. 118 * 119 * @param <T> the type of values being compared. 120 * @param message header of the exception message in case of failure, or {@code null} if none. 121 * @param minimum the lower bound of the range (inclusive), or {@code null} if unbounded. 122 * @param maximum the upper bound of the range (inclusive), or {@code null} if unbounded. 123 * @param value the value to test, or {@code null} (which is a failure). 124 */ 125 public static <T> void assertBetween(final String message, final Comparable<T> minimum, final Comparable<T> maximum, T value) { 126 Assertions.assertBetween(minimum, maximum, value, message); 127 } 128 129 /** 130 * Asserts that the given value is inside the given range. This method does <strong>not</strong> 131 * test the validity of the given [{@code minimum} … {@code maximum}] range. 132 * 133 * @param message header of the exception message in case of failure, or {@code null} if none. 134 * @param minimum the lower bound of the range, inclusive. 135 * @param maximum the upper bound of the range, inclusive. 136 * @param value the value to test. 137 */ 138 public static void assertBetween(final String message, final int minimum, final int maximum, final int value) { 139 Assertions.assertBetween(minimum, maximum, value, message); 140 } 141 142 /** 143 * Asserts that the given value is inside the given range. If the given {@code value} is 144 * {@linkplain Double#NaN NaN}, then this test passes silently. This method does <strong>not</strong> 145 * test the validity of the given [{@code minimum} … {@code maximum}] range. 146 * 147 * @param message header of the exception message in case of failure, or {@code null} if none. 148 * @param minimum the lower bound of the range, inclusive. 149 * @param maximum the upper bound of the range, inclusive. 150 * @param value the value to test. 151 */ 152 public static void assertBetween(final String message, final double minimum, final double maximum, final double value) { 153 Assertions.assertBetween(minimum, maximum, value, message); 154 } 155 156 /** 157 * Asserts that the given value is contained in the given collection. If the given collection 158 * is null, then this test passes silently (a null collection is considered as "unknown", not 159 * empty). If the given value is null, then the test passes only if the given collection 160 * contains the null element. 161 * 162 * @param message header of the exception message in case of failure, or {@code null} if none. 163 * @param collection the collection where to look for inclusion, or {@code null} if unrestricted. 164 * @param value the value to test for inclusion. 165 */ 166 public static void assertContains(final String message, final Collection<?> collection, final Object value) { 167 Assertions.assertContains(collection, value, message); 168 } 169 170 /** 171 * @deprecated Renamed {@link Assertions#assertUnicodeIdentifierEquals(String, CharSequence, CharSequence, boolean)} 172 * for avoiding confusion with the {@code Identifier} interface. 173 * 174 * @param message header of the exception message in case of failure, or {@code null} if none. 175 * @param expected the expected character sequence. 176 * @param value the character sequence to compare. 177 */ 178 @Deprecated 179 public static void assertIdentifierEquals(final String message, final CharSequence expected, final CharSequence value) { 180 Assertions.assertUnicodeIdentifierEquals(expected, value, true, message); 181 } 182}