|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 3 | + * the License. You may obtain a copy of the License at |
| 4 | + * |
| 5 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 8 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 9 | + * specific language governing permissions and limitations under the License. |
| 10 | + * |
| 11 | + * Copyright 2012-2018 the original author or authors. |
| 12 | + */ |
| 13 | +package org.assertj.core.api.recursive.comparison; |
| 14 | + |
| 15 | +import static org.assertj.core.api.Assertions.assertThatCode; |
| 16 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
| 17 | +import static org.assertj.core.api.Assumptions.assumeThat; |
| 18 | +import static org.assertj.core.presentation.UnicodeRepresentation.UNICODE_REPRESENTATION; |
| 19 | + |
| 20 | +import org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest; |
| 21 | +import org.assertj.core.internal.objects.data.Person; |
| 22 | +import org.junit.AssumptionViolatedException; |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | + |
| 25 | +public class RecursiveComparisonAssert_assumptions_Test extends RecursiveComparisonAssert_isEqualTo_BaseTest { |
| 26 | + |
| 27 | + @Test |
| 28 | + public void should_ignore_test_when_one_of_the_assumption_fails() { |
| 29 | + // GIVEN |
| 30 | + Person actual = new Person("John"); |
| 31 | + actual.home.address.number = 1; |
| 32 | + Person expected = new Person("John"); |
| 33 | + expected.home.address.number = 1; |
| 34 | + Person unexpected = new Person("John"); |
| 35 | + unexpected.home.address.number = 2; |
| 36 | + // THEN |
| 37 | + assumeThat(actual).usingRecursiveComparison().isEqualTo(expected); |
| 38 | + assertThatExceptionOfType(AssumptionViolatedException.class).isThrownBy(() -> assumeThat(actual).usingRecursiveComparison() |
| 39 | + .isEqualTo(unexpected)); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void should_run_test_when_all_assumptions_are_met() { |
| 44 | + // GIVEN |
| 45 | + Person actual = new Person("John"); |
| 46 | + actual.home.address.number = 1; |
| 47 | + Person expected = new Person("John"); |
| 48 | + expected.home.address.number = 1; |
| 49 | + // THEN |
| 50 | + assertThatCode(() -> { |
| 51 | + assumeThat("foo").isNotNull() |
| 52 | + .isNotEmpty() |
| 53 | + .isEqualTo("foo"); |
| 54 | + assumeThat(actual).usingRecursiveComparison().isEqualTo(expected); |
| 55 | + assumeThat(expected).usingRecursiveComparison().isEqualTo(actual); |
| 56 | + assumeThat(actual).as("test description") |
| 57 | + .withFailMessage("error message") |
| 58 | + .withRepresentation(UNICODE_REPRESENTATION) |
| 59 | + .usingRecursiveComparison() |
| 60 | + .isEqualTo(expected); |
| 61 | + }).doesNotThrowAnyException(); |
| 62 | + } |
| 63 | + |
| 64 | +} |
0 commit comments