|
| 1 | +/* |
| 2 | + * |
| 3 | + * * |
| 4 | + * * * |
| 5 | + * * * * |
| 6 | + * * * * * Copyright 2019-2022 the original author or authors. |
| 7 | + * * * * * |
| 8 | + * * * * * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | + * * * * * you may not use this file except in compliance with the License. |
| 10 | + * * * * * You may obtain a copy of the License at |
| 11 | + * * * * * |
| 12 | + * * * * * https://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * * * * * |
| 14 | + * * * * * Unless required by applicable law or agreed to in writing, software |
| 15 | + * * * * * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | + * * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | + * * * * * See the License for the specific language governing permissions and |
| 18 | + * * * * * limitations under the License. |
| 19 | + * * * * |
| 20 | + * * * |
| 21 | + * * |
| 22 | + * |
| 23 | + */ |
| 24 | +package org.springdoc.core.extractor; |
| 25 | + |
| 26 | +import java.lang.reflect.Method; |
| 27 | +import java.util.stream.Stream; |
| 28 | + |
| 29 | +import org.junit.jupiter.api.Nested; |
| 30 | +import org.junit.jupiter.api.Test; |
| 31 | + |
| 32 | +import org.springframework.core.MethodParameter; |
| 33 | + |
| 34 | +import static org.assertj.core.api.Assertions.assertThat; |
| 35 | + |
| 36 | +/** |
| 37 | + * Tests for {@link MethodParameterPojoExtractor}. |
| 38 | + */ |
| 39 | +class MethodParameterPojoExtractorTest { |
| 40 | + /** |
| 41 | + * Tests for {@link MethodParameterPojoExtractor#extractFrom(Class<?>)}. |
| 42 | + */ |
| 43 | + @Nested |
| 44 | + class extractFrom { |
| 45 | + @Test |
| 46 | + void ifRecordObjectShouldGetField() { |
| 47 | + Stream<MethodParameter> actual = MethodParameterPojoExtractor.extractFrom(RecordObject.class); |
| 48 | + assertThat(actual) |
| 49 | + .extracting(MethodParameter::getMethod) |
| 50 | + .extracting(Method::getName) |
| 51 | + .containsOnlyOnce("email", "firstName", "lastName"); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void ifClassObjectShouldGetMethod() { |
| 56 | + Stream<MethodParameter> actual = MethodParameterPojoExtractor.extractFrom(ClassObject.class); |
| 57 | + assertThat(actual) |
| 58 | + .extracting(MethodParameter::getMethod) |
| 59 | + .extracting(Method::getName) |
| 60 | + .containsOnlyOnce("getEmail", "getFirstName", "getLastName"); |
| 61 | + } |
| 62 | + |
| 63 | + public record RecordObject(String email, String firstName, String lastName) {} |
| 64 | + |
| 65 | + public class ClassObject { |
| 66 | + private String email; |
| 67 | + |
| 68 | + private String firstName; |
| 69 | + |
| 70 | + private String lastName; |
| 71 | + |
| 72 | + public ClassObject(String email, String firstName, String lastName) { |
| 73 | + this.email = email; |
| 74 | + this.firstName = firstName; |
| 75 | + this.lastName = lastName; |
| 76 | + } |
| 77 | + |
| 78 | + public String getEmail() { |
| 79 | + return email; |
| 80 | + } |
| 81 | + |
| 82 | + public String getFirstName() { |
| 83 | + return firstName; |
| 84 | + } |
| 85 | + |
| 86 | + public String getLastName() { |
| 87 | + return lastName; |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | +} |
0 commit comments