|
| 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-2021 the original author or authors. |
| 12 | + */ |
| 13 | +package org.assertj.core.api.object; |
| 14 | + |
| 15 | +import static org.assertj.core.api.Assertions.assertThat; |
| 16 | +import static org.assertj.core.api.Assertions.catchThrowable; |
| 17 | +import static org.assertj.core.api.Assertions.from; |
| 18 | +import static org.assertj.core.api.BDDAssertions.then; |
| 19 | +import static org.mockito.Mockito.verify; |
| 20 | + |
| 21 | +import org.assertj.core.api.ObjectAssert; |
| 22 | +import org.assertj.core.api.ObjectAssertBaseTest; |
| 23 | +import org.assertj.core.test.Jedi; |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +class ObjectAssert_doesNotReturn_Test extends ObjectAssertBaseTest { |
| 27 | + |
| 28 | + @Override |
| 29 | + protected ObjectAssert<Jedi> invoke_api_method() { |
| 30 | + return assertions.doesNotReturn("Yoda", Jedi::getName); |
| 31 | + } |
| 32 | + |
| 33 | + @Override |
| 34 | + protected void verify_internal_effects() { |
| 35 | + verify(objects).assertNotEqual(getInfo(assertions), getActual(assertions).getName(), "Yoda"); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + void should_fail_with_throwing_NullPointerException_if_method_is_null() { |
| 40 | + // WHEN |
| 41 | + Throwable thrown = catchThrowable(() -> assertions.doesNotReturn("May the force be with you.", null)); |
| 42 | + // THEN |
| 43 | + then(thrown).isInstanceOf(NullPointerException.class) |
| 44 | + .hasMessage("The given getter method/Function must not be null"); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + void perform_assertion_like_users() { |
| 49 | + // GIVEN |
| 50 | + Jedi yoda = new Jedi("Yoda", "Green"); |
| 51 | + // WHEN/THEN |
| 52 | + assertThat(yoda).doesNotReturn("Luke", from(Jedi::getName)) |
| 53 | + .doesNotReturn("Luke", Jedi::getName); |
| 54 | + } |
| 55 | + |
| 56 | +} |
0 commit comments