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

com.fitbur.assertj.internal.Booleans Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
/**
 * 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.
 *
 * Copyright 2012-2016 the original author or authors.
 */
package com.fitbur.assertj.internal;

import static com.fitbur.assertj.error.ShouldBeEqual.shouldBeEqual;
import static com.fitbur.assertj.error.ShouldNotBeEqual.shouldNotBeEqual;

import com.fitbur.assertj.api.AssertionInfo;
import com.fitbur.assertj.util.VisibleForTesting;


/**
 * Reusable assertions for {@link Boolean}s.
 * 
 * @author Alex Ruiz
 */
public class Booleans {

  private static final Booleans INSTANCE = new Booleans();

  /**
   * Returns the singleton instance of this class.
   * @return the singleton instance of this class.
   */
  public static Booleans instance() {
    return INSTANCE;
  }

  @VisibleForTesting
  Failures failures = Failures.instance();

  @VisibleForTesting
  Booleans() {}

  /**
   * Asserts that two booleans are equal.
   * @param info contains information about the assertion.
   * @param actual the actual value.
   * @param expected the expected value.
   * @throws AssertionError if the actual value is {@code null}.
   * @throws AssertionError if the actual value is not equal to the expected one. This method will throw a
   *           {@code org.junit.ComparisonFailure} instead if JUnit is in the classpath and the expected and actual values are not
   *           equal.
   */
  public void assertEqual(AssertionInfo info, Boolean actual, boolean expected) {
    assertNotNull(info, actual);
    if (actual == expected) return;
    throw failures.failure(info, shouldBeEqual(actual, expected, info.representation()));
  }

  /**
   * Asserts that two longs are not equal.
   * @param info contains information about the assertion.
   * @param actual the actual value.
   * @param other the value to compare the actual value to.
   * @throws AssertionError if the actual value is {@code null}.
   * @throws AssertionError if the actual value is equal to the other one.
   */
  public void assertNotEqual(AssertionInfo info, Boolean actual, boolean other) {
    assertNotNull(info, actual);
    if (actual != other) return;
    throw failures.failure(info, shouldNotBeEqual(actual, other));
  }

  private static void assertNotNull(AssertionInfo info, Boolean actual) {
    Objects.instance().assertNotNull(info, actual);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy