|
| 1 | +/* |
| 2 | + * Copyright 2012-2026 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.assertj.core.api; |
| 17 | + |
| 18 | +import static org.assertj.core.api.BDDAssertions.thenNoException; |
| 19 | +import static org.assertj.core.api.SoftAssertions.assertSoftly; |
| 20 | +import static org.assertj.core.util.Lists.list; |
| 21 | +import static org.assertj.core.util.Lists.newArrayList; |
| 22 | + |
| 23 | +import java.util.List; |
| 24 | + |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | + |
| 27 | +/** |
| 28 | + * Tests for {@link SoftAssertions}, to verify that proxied custom assertions inheriting from {@link AbstractListAssert} do not throw {@link ClassCastException}. |
| 29 | + * |
| 30 | + * @author HuitaePark |
| 31 | + */ |
| 32 | +public class SoftAssertions_proxied_AbstractListAssert_Test { |
| 33 | + |
| 34 | + @Test |
| 35 | + void should_not_throw_class_cast_exception_when_calling_methods_with_array_args_on_proxied_custom_assertion() { |
| 36 | + // GIVEN |
| 37 | + List<String> actual = list("a", "b"); |
| 38 | + List<String> expected = list("a", "b"); |
| 39 | + |
| 40 | + // WHEN / THEN |
| 41 | + thenNoException().isThrownBy(() -> { |
| 42 | + assertSoftly(softly -> softly.proxy(TestListAssert.class, List.class, actual) |
| 43 | + .containsExactlyInAnyOrderElementsOf(expected)); |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + static class TestListAssert extends AbstractListAssert<TestListAssert, List<String>, String, ObjectAssert<String>> { |
| 48 | + |
| 49 | + public TestListAssert(List<String> actual) { |
| 50 | + super(actual, TestListAssert.class); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + protected TestListAssert newAbstractIterableAssert(Iterable<? extends String> iterable) { |
| 55 | + return new TestListAssert(newArrayList(iterable)); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + protected ObjectAssert<String> toAssert(String value, String description) { |
| 60 | + return new ObjectAssert<>(value); |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + protected ObjectAssert<String> toAssert(String value) { |
| 65 | + return new ObjectAssert<>(value); |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments