Assert Util : Assert « Language Basics « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java » Language Basics » AssertScreenshots 
Assert Util
        

//package org.gwtoolbox.commons.util.client;

/**
 @author Uri Boness
 */
public class Assert {

    public static void isEqual(Object o1, Object o2throws IllegalArgumentException {
        isEqual(o1, o2, "Assertion failed: two given objects are expected to be equal");
    }

    public static void isEqual(Object o1, Object o2, String messagethrows IllegalArgumentException {
        if (!o1.equals(o2)) {
            throw new IllegalArgumentException(message);
        }
    }

    public static void isSame(Object o1, Object o2) {
        isSame(o1, o2, "Assertion failed: two give object are expected to be the same object");
    }

    public static void isSame(Object o1, Object o2, String message) {
        if (o1 != o2) {
            throw new IllegalArgumentException(message);
        }
    }

    public static void notNull(Object object) {
        notNull(object, "Assertion failed: give object cannot be null");
    }

    public static void notNull(Object object, String message) {
        if (object == null) {
            throw new IllegalArgumentException(message);
        }
    }

    public static void isTrue(boolean expression) {
        isTrue(expression, "Assertion failed: give expression is expected to be true");
    }

    public static void isTrue(boolean expression, String message) {
        if (!expression) {
            throw new IllegalArgumentException(message);
        }
    }

    public static void isFalse(boolean expression) {
        isFalse(expression, "Assertion failed: give expression is expected to be false");
    }

    public static void isFalse(boolean expression, String message) {
        isTrue(!expression, message);
    }

    public static void state(boolean expressionthrows IllegalStateException {
        state(expression, "Assertion failed: illegal state");
    }

    public static void state(boolean expression, String messagethrows IllegalStateException {
        if (!expression) {
            throw new IllegalStateException(message);
        }
    }

}

   
    
    
    
    
    
    
    
  
Related examples in the same category
1.A Program with Assertions
2.Enabling Assertions from the Command Line: -ea and -da enable and disable assertion in a package subtree or in a class.
3.Handling an Assertion Error
4.Catch assert exception with message
5.Assert with an informative message
6.Non-informative style of assert
7.Using the class loader to enable assertions
8.Class for checking syntax and comments for the assert
9.Assertion utility class that assists in validating arguments.
10.An assertion utility just for simple checks.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.