All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.immutables.check.Checkers Maven / Gradle / Ivy

Go to download

Testing dependencies and utilities. Expected to be used only in test scope

There is a newer version: 2.10.1
Show newest version
/*
   Copyright 2013-2014 Immutables Authors and Contributors

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package org.immutables.check;

import com.google.common.base.Optional;
import com.google.common.primitives.Bytes;
import com.google.common.primitives.Doubles;
import com.google.common.primitives.Ints;
import com.google.common.primitives.Longs;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;

/**
 * Convenient wrappers for matcher checking, designed for better code assist(completion) and
 * discoverability for most commonly used matchers.
 */
public class Checkers {

  public static void check(boolean actualCheckResult) {
    check("failed", actualCheckResult);
  }

  public static ObjectChecker check(@Nullable Boolean actualValue) {
    return new ObjectChecker<>(actualValue, false);
  }

  @SafeVarargs
  public static  IterableChecker, E> checkAll(E... actualValues) {
    return new IterableChecker, E>(Arrays.asList(actualValues), false);
  }

  public static , E> IterableChecker check(I actualValue) {
    return new IterableChecker<>(actualValue, false);
  }

  public static  IterableChecker, E> check(E[] actualValue) {
    return check(actualValue == null ? null : Arrays.asList(actualValue));
  }

  public static IterableChecker, Long> check(long[] actualLongArray) {
    return check(actualLongArray == null ? null : Longs.asList(actualLongArray));
  }

  public static IterableChecker, Double> check(double[] actualDoubleArray) {
    return check(actualDoubleArray == null ? null : Doubles.asList(actualDoubleArray));
  }

  public static IterableChecker, Integer> check(int[] actualIntArray) {
    return check(actualIntArray == null ? null : Ints.asList(actualIntArray));
  }

  public static IterableChecker, Byte> check(byte[] actualByteArray) {
    return check(actualByteArray == null ? null : Bytes.asList(actualByteArray));
  }

  public static StringChecker check(char[] actualCharArray) {
    return check(actualCharArray == null ? null : String.valueOf(actualCharArray));
  }

  public static  OptionalChecker check(Optional actualValue) {
    return new OptionalChecker<>(actualValue);
  }

  public static StringChecker check(@Nullable String actualString) {
    return new StringChecker(actualString, false);
  }

  public static void check(String description, boolean actualCheckResult) {
    ObjectChecker.verifyCheck(description, actualCheckResult);
  }

  public static  ObjectChecker check(@Nullable T actualValue) {
    return new ObjectChecker<>(actualValue, false);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy