Coverage Report - org.eclipse.swtbot.swt.finder.utils.internal.Assert
 
Classes in this File Line Coverage Branch Coverage Complexity
Assert
80%
16/20
87%
7/8
2
 
 1  
 /*******************************************************************************
 2  
  * Copyright (c) 2000, 2008 IBM Corporation and others.
 3  
  * All rights reserved. This program and the accompanying materials
 4  
  * are made available under the terms of the Eclipse Public License v1.0
 5  
  * which accompanies this distribution, and is available at
 6  
  * http://www.eclipse.org/legal/epl-v10.html
 7  
  * 
 8  
  * Contributors:
 9  
  *     IBM Corporation - initial API and implementation
 10  
  *******************************************************************************/
 11  
 package org.eclipse.swtbot.swt.finder.utils.internal;
 12  
 
 13  
 import org.eclipse.swtbot.swt.finder.exceptions.AssertionFailedException;
 14  
 
 15  
 /**
 16  
  * Copy of {@link org.eclipse.core.runtime.Assert}, moved here to reduce dependency on org.eclipse.equinox.common.
 17  
  * 
 18  
  * @noinstantiate This class is not intended to be instantiated by clients.
 19  
  */
 20  
 public final class Assert {
 21  
         /* This class is not intended to be instantiated. */
 22  0
         private Assert() {
 23  
                 // not allowed
 24  0
         }
 25  
 
 26  
         /**
 27  
          * Asserts that an argument is legal. If the given boolean is not <code>true</code>, an
 28  
          * <code>IllegalArgumentException</code> is thrown.
 29  
          * 
 30  
          * @param expression the outcode of the check
 31  
          * @return <code>true</code> if the check passes (does not return if the check fails)
 32  
          * @exception IllegalArgumentException if the legality test failed
 33  
          */
 34  
         public static boolean isLegal(boolean expression) {
 35  0
                 return isLegal(expression, ""); //$NON-NLS-1$
 36  
         }
 37  
 
 38  
         /**
 39  
          * Asserts that an argument is legal. If the given boolean is not <code>true</code>, an
 40  
          * <code>IllegalArgumentException</code> is thrown. The given message is included in that exception, to aid
 41  
          * debugging.
 42  
          * 
 43  
          * @param expression the outcode of the check
 44  
          * @param message the message to include in the exception
 45  
          * @return <code>true</code> if the check passes (does not return if the check fails)
 46  
          * @exception IllegalArgumentException if the legality test failed
 47  
          */
 48  
         public static boolean isLegal(boolean expression, Object message) {
 49  120
                 if (!expression)
 50  12
                         throw new IllegalArgumentException(message.toString());
 51  108
                 return expression;
 52  
         }
 53  
 
 54  
         /**
 55  
          * Asserts that the given object is not <code>null</code>. If this is not the case, some kind of unchecked exception
 56  
          * is thrown.
 57  
          * 
 58  
          * @param object the value to test
 59  
          */
 60  
         public static void isNotNull(Object object) {
 61  3802
                 isNotNull(object, ""); //$NON-NLS-1$
 62  3802
         }
 63  
 
 64  
         /**
 65  
          * Asserts that the given object is not <code>null</code>. If this is not the case, some kind of unchecked exception
 66  
          * is thrown. The given message is included in that exception, to aid debugging.
 67  
          * 
 68  
          * @param object the value to test
 69  
          * @param message the message to include in the exception
 70  
          */
 71  
         public static void isNotNull(Object object, Object message) {
 72  3837
                 if (object == null)
 73  0
                         throw new AssertionFailedException("null argument: " + message); //$NON-NLS-1$
 74  3837
         }
 75  
 
 76  
         /**
 77  
          * Asserts that the given boolean is <code>true</code>. If this is not the case, some kind of unchecked exception is
 78  
          * thrown.
 79  
          * 
 80  
          * @param expression the outcode of the check
 81  
          */
 82  
         public static void isTrue(boolean expression) {
 83  31
                 isTrue(expression, ""); //$NON-NLS-1$
 84  31
         }
 85  
 
 86  
         /**
 87  
          * Asserts that the given boolean is <code>true</code>. If this is not the case, some kind of unchecked exception is
 88  
          * thrown. The given message is included in that exception, to aid debugging.
 89  
          * 
 90  
          * @param expression the outcode of the check
 91  
          * @param message the message to include in the exception
 92  
          */
 93  
         public static void isTrue(boolean expression, Object message) {
 94  6516
                 if (!expression)
 95  4
                         throw new AssertionFailedException("assertion failed: " + message); //$NON-NLS-1$
 96  6512
         }
 97  
 
 98  
         /**
 99  
          * Asserts that the given list is not empty or null. If this is not the case, some kind of unchecked exception is
 100  
          * thrown. The given message is included in that exception, to aid debugging.
 101  
          * 
 102  
          * @param expression the outcode of the check
 103  
          * @param message the message to include in the exception
 104  
          */
 105  
         public static void isNotEmpty(Object... toCheck) {
 106  15
                 Assert.isNotNull(toCheck);
 107  15
                 if (toCheck.length == 0) {
 108  1
                         throw new AssertionFailedException("List cannot be empty or null.");
 109  
                 }
 110  14
         }
 111  
 }