/*
 * 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-2018 the original author or authors.
 */
package org.assertj.core.description;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.description.Description.mostRelevantDescription;

import org.junit.Test;

public class Description_mostRelevantDescription_Test {

  @Test
  public void should_return_exsiting_description_if_not_empty() {
    // GIVEN
    String existing = "bar";
    Description description = new TextDescription(existing);
    // WHEN
    String mostRelevantDescription = mostRelevantDescription(description, "foo");

    // THEN
    assertThat(mostRelevantDescription).isEqualTo(existing);
  }

  @Test
  public void should_return_the_other_value_if_description_value_is_empty() {
    // GIVEN
    Description description = new TextDescription("");
    String other = "foo";

    // WHEN
    String mostRelevantDescription = mostRelevantDescription(description, other);

    // THEN
    assertThat(mostRelevantDescription).isEqualTo(other);
  }

  @Test
  public void should_return_the_other_value_if_description_value_is_null() {
    // GIVEN
    Description description = new TextDescription(null);
    String other = "foo";

    // WHEN
    String mostRelevantDescription = mostRelevantDescription(description, other);

    // THEN
    assertThat(mostRelevantDescription).isEqualTo(other);
  }

  @Test
  public void should_return_the_other_value_if_null() {
    // GIVEN
    Description description = null;
    String other = "foo";

    // WHEN
    String mostRelevantDescription = mostRelevantDescription(description, other);

    // THEN
    assertThat(mostRelevantDescription).isEqualTo(other);
  }

}
