001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  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,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 */
019
020package org.apache.isis.core.commons.ensure;
021
022public final class Assert {
023
024    public static void assertEquals(final Object expected, final Object actual) {
025        assertEquals("", expected, actual);
026    }
027
028    public static void assertEquals(final String message, final int expected, final int value) {
029        if (expected != value) {
030            throw new IsisAssertException(message + " expected " + expected + "; but was " + value);
031        }
032    }
033
034    public static void assertEquals(final String message, final Object expected, final Object actual) {
035        assertTrue(message + ": expected " + expected + " but was " + actual, (expected == null && actual == null) || (expected != null && expected.equals(actual)));
036    }
037
038    public static void assertFalse(final boolean flag) {
039        assertFalse("expected false", flag);
040    }
041
042    public static void assertFalse(final String message, final boolean flag) {
043        assertTrue(message, !flag);
044    }
045
046    public static void assertFalse(final String message, final Object target, final boolean flag) {
047        assertTrue(message, target, !flag);
048    }
049
050    public static void assertNotNull(final Object object) {
051        assertNotNull("", object);
052    }
053
054    public static void assertNotNull(final String message, final Object object) {
055        assertTrue("unexpected null: " + message, object != null);
056    }
057
058    public static void assertNotNull(final String message, final Object target, final Object object) {
059        assertTrue(message, target, object != null);
060    }
061
062    public static void assertNull(final Object object) {
063        assertTrue("unexpected reference; should be null", object == null);
064    }
065
066    public static void assertNull(final String message, final Object object) {
067        assertTrue(message, object == null);
068    }
069
070    public static void assertSame(final Object expected, final Object actual) {
071        assertSame("", expected, actual);
072    }
073
074    public static void assertSame(final String message, final Object expected, final Object actual) {
075        assertTrue(message + ": expected " + expected + " but was " + actual, expected == actual);
076    }
077
078    public static void assertTrue(final boolean flag) {
079        assertTrue("expected true", flag);
080    }
081
082    public static void assertTrue(final String message, final boolean flag) {
083        assertTrue(message, null, flag);
084    }
085
086    public static void assertTrue(final String message, final Object target, final boolean flag) {
087        if (!flag) {
088            throw new IsisAssertException(message + (target == null ? "" : (": " + target)));
089        }
090    }
091
092}