Java Assert assertIsPositive(int num, String fieldName)

Here you can find the source of assertIsPositive(int num, String fieldName)

Description

Asserts that the given number is positive (non-negative and non-zero).

License

Amazon Software License

Parameter

Parameter Description
num Number to validate
fieldName Field name to display in exception message if not positive.

Return

Number if positive.

Declaration

public static int assertIsPositive(int num, String fieldName) 

Method Source Code

//package com.java2s;
//License from project: Amazon Software License 

public class Main {
    /**//from   w  w  w.jav  a  2s .  co  m
     * Asserts that the given number is positive (non-negative and non-zero).
     *
     * @param num Number to validate
     * @param fieldName Field name to display in exception message if not
     *            positive.
     * @return Number if positive.
     */
    public static int assertIsPositive(int num, String fieldName) {
        if (num <= 0) {
            throw new IllegalArgumentException(String.format("%s must be positive", fieldName));
        }
        return num;
    }
}

Related

  1. assertionError(String message, Throwable cause)
  2. assertIOThread(Thread t, boolean flag)
  3. assertIsClass(Class klazz)
  4. assertIsNotEmptyString(String string)
  5. assertIsPermutation(int[] perm)
  6. assertIsProb(double x)
  7. assertIsProbability(final double probability)
  8. assertIsProperlyQuoted(String header, String tag)
  9. assertIsReady()