From a9f7e65f36d0c2473b06905ab5a6c90d4024923d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Date: Mon, 9 Oct 2023 15:43:41 +0200 Subject: [PATCH] Remove confusing and almost unused Asserts class --- .../com/redhat/rhn/common/util/Asserts.java | 175 ------------------ .../rhn/frontend/struts/StrutsDelegate.java | 5 +- .../redhat/rhn/manager/rhnset/RhnSetDecl.java | 9 +- .../rules/test/BaseProductRuleTest.java | 2 +- 4 files changed, 10 insertions(+), 181 deletions(-) delete mode 100644 java/code/src/com/redhat/rhn/common/util/Asserts.java diff --git a/java/code/src/com/redhat/rhn/common/util/Asserts.java b/java/code/src/com/redhat/rhn/common/util/Asserts.java deleted file mode 100644 index 8ea74b9fb1a4..000000000000 --- a/java/code/src/com/redhat/rhn/common/util/Asserts.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2009--2014 Red Hat, Inc. - * - * This software is licensed to you under the GNU General Public License, - * version 2 (GPLv2). There is NO WARRANTY for this software, express or - * implied, including the implied warranties of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 - * along with this software; if not, see - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. - * - * Red Hat trademarks are not licensed under GPLv2. No permission is - * granted to use or replicate Red Hat trademarks that are incorporated - * in this software or its documentation. - */ -package com.redhat.rhn.common.util; - -/** - * Assertions that should be used to check parameters on public methods. - * Note that, as opposed to the assert keyword, these checks - * can not and should not be turned off. - * - *

See Sun's - * assert specification for recommended best practices. - */ -public final class Asserts { - - private Asserts() { - // Only used for static methods - } - - /** - * Assert that an arbitrary condition is true and throw an exception if the - * condition is false. - * - * @param cond condition to assert - * @throws IllegalStateException if condition is false - */ - public static void assertTrue(boolean cond) throws IllegalStateException { - assertTrue(cond, ""); - } - - /** - * Assert that an arbitrary condition is true throw an exception with - * message msg if the condition is false. - * - * @param cond condition to assert - * @param msg failure message - * @throws IllegalStateException if condition is false - */ - public static void assertTrue(boolean cond, String msg) - throws IllegalStateException { - if (!cond) { - throw new IllegalStateException("Assertion failed: " + msg); - } - } - - /** - * Verify that a parameter is not null and throw a runtime exception if so. - * @param o the object that should not be null - * @throws IllegalStateException if o is null - */ - public static void assertNotNull(Object o) throws IllegalStateException { - assertNotNull(o, ""); - } - - /** - * Verify that a parameter is not null and throw a runtime exception if so. - * @param o the object that should not be null - * @param label the label for o to include in the error - * message - * @throws IllegalStateException if o is null - */ - public static void assertNotNull(Object o, String label) - throws IllegalStateException { - assertTrue(o != null, "Value of " + label + " is null."); - } - - /** - * Verify that a string is not empty and throw a runtime exception if so. A - * parameter is considered empty if it is null, or if it does not contain - * any characters that are non-whitespace. - * @param s the string to check for emptiness - * @throws IllegalStateException if s is an empty string - */ - public static void assertNotEmpty(String s) throws IllegalStateException { - assertNotEmpty(s, ""); - } - - /** - * Verify that a string is not empty and throw a runtime exception if so. A - * parameter is considered empty if it is null, or if it does not contain - * any characters that are non-whitespace. - * @param s the string to check for emptiness - * @param label the label for s to include in the error - * message - * @throws IllegalStateException if s is an empty string - */ - public static void assertNotEmpty(String s, String label) - throws IllegalStateException { - if (s == null || s.trim().isEmpty()) { - assertTrue(s != null && !s.trim().isEmpty(), - "Value of " + label + " is empty."); - } - } - - /** - * Verify that two values are equal (according to their equals method, - * unless expected is null, then according to ==). - * - * @param expected Expected value. - * @param actual Actual value. - * @throws IllegalStateException if expected is not - * equal to actual - */ - public static void assertEquals(Object expected, Object actual) - throws IllegalStateException { - assertEquals(expected, actual, "expected", "actual"); - } - - /** - * Verify that two values are equal (according to their equals method, - * unless expected is null, then according to ==). - * - * @param expected Expected value. - * @param actual Actual value. - * @param expectedLabel Label for first (generally expected) value. - * @param actualLabel Label for second (generally actual) value. - * @throws IllegalStateException condition was false - */ - public static void assertEquals(Object expected, Object actual, - String expectedLabel, String actualLabel) - throws IllegalStateException { - if (expected == null) { - assertTrue(actual == null, "Values not equal, " + expectedLabel + - " '" + expected + "', " + actualLabel + " '" + actual + - "'"); - } - else { - assertTrue(expected.equals(actual), "Values not equal, " + - expectedLabel + " '" + expected + "', " + actualLabel + - " '" + actual + "'"); - } - } - - /** - * Verify that two values are equal. - * - * @param expected Expected value. - * @param actual Actual value. - * @throws IllegalStateException if expected != actual - */ - public static void assertEquals(int expected, int actual) - throws IllegalStateException { - assertEquals(expected, actual, "expected", "actual"); - } - - /** - * Verify that two values are equal. - * - * @param expected Expected value. - * @param actual Actual value. - * @param expectedLabel Label for first (generally expected) value. - * @param actualLabel Label for second (generally actual) value. - * @throws IllegalStateException if expected != actual - */ - public static void assertEquals(int expected, int actual, - String expectedLabel, String actualLabel) - throws IllegalStateException { - if (expected != actual) { - assertTrue(expected == actual, "Values not equal, " + expectedLabel + - " '" + expected + "', " + actualLabel + " '" + actual + - "'"); - } - } -} diff --git a/java/code/src/com/redhat/rhn/frontend/struts/StrutsDelegate.java b/java/code/src/com/redhat/rhn/frontend/struts/StrutsDelegate.java index 09bf6d3ade73..98114861e740 100644 --- a/java/code/src/com/redhat/rhn/frontend/struts/StrutsDelegate.java +++ b/java/code/src/com/redhat/rhn/frontend/struts/StrutsDelegate.java @@ -14,7 +14,6 @@ */ package com.redhat.rhn.frontend.struts; -import com.redhat.rhn.common.util.Asserts; import com.redhat.rhn.common.util.DatePicker; import com.redhat.rhn.common.util.ServletUtils; import com.redhat.rhn.common.validator.ValidationMessage; @@ -97,7 +96,9 @@ public ActionForward forwardParam(ActionForward base, String param, String value * param and value. */ public ActionForward forwardParams(ActionForward base, Map params) { - Asserts.assertNotNull(base, "base"); + if (base == null) { + throw new IllegalArgumentException("Base should not be null"); + } String newPath = ServletUtils.pathWithParams(base.getPath(), params); ActionForward af = new ActionForward(newPath, base.getRedirect()); diff --git a/java/code/src/com/redhat/rhn/manager/rhnset/RhnSetDecl.java b/java/code/src/com/redhat/rhn/manager/rhnset/RhnSetDecl.java index aa9845529529..cfc6f33d6bce 100644 --- a/java/code/src/com/redhat/rhn/manager/rhnset/RhnSetDecl.java +++ b/java/code/src/com/redhat/rhn/manager/rhnset/RhnSetDecl.java @@ -14,7 +14,6 @@ */ package com.redhat.rhn.manager.rhnset; -import com.redhat.rhn.common.util.Asserts; import com.redhat.rhn.domain.channel.Channel; import com.redhat.rhn.domain.rhnset.RhnSet; import com.redhat.rhn.domain.rhnset.SetCleanup; @@ -375,7 +374,9 @@ public void clear(User u) { * @return the created set */ public RhnSet create(User u) { - Asserts.assertNotNull(u, "u"); + if (u == null) { + throw new IllegalArgumentException("user should not be null"); + } return RhnSetManager.createSet(u.getId(), label, cleanup); } @@ -387,7 +388,9 @@ public RhnSet create(User u) { * @return the set for user u */ public RhnSet get(User u) { - Asserts.assertNotNull(u, "u"); + if (u == null) { + throw new IllegalArgumentException("user should not be null"); + } RhnSet s = lookup(u); if (s == null) { s = create(u); diff --git a/java/code/src/com/redhat/rhn/taskomatic/task/payg/dimensions/rules/test/BaseProductRuleTest.java b/java/code/src/com/redhat/rhn/taskomatic/task/payg/dimensions/rules/test/BaseProductRuleTest.java index 97ff95a1cdb0..3509b17886a8 100644 --- a/java/code/src/com/redhat/rhn/taskomatic/task/payg/dimensions/rules/test/BaseProductRuleTest.java +++ b/java/code/src/com/redhat/rhn/taskomatic/task/payg/dimensions/rules/test/BaseProductRuleTest.java @@ -15,7 +15,7 @@ package com.redhat.rhn.taskomatic.task.payg.dimensions.rules.test; -import static com.redhat.rhn.common.util.Asserts.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.jmock.AbstractExpectations.returnValue; import com.redhat.rhn.domain.product.SUSEProduct;