|
| 1 | +/* |
| 2 | + * Copyright 2012-2023 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 | + |
| 17 | +package org.springframework.boot.actuate.info; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | + |
| 21 | +import org.springframework.aot.hint.MemberCategory; |
| 22 | +import org.springframework.aot.hint.RuntimeHints; |
| 23 | +import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; |
| 24 | +import org.springframework.boot.actuate.info.ProcessInfoContributor.ProcessInfoContributorRuntimeHints; |
| 25 | +import org.springframework.boot.info.ProcessInfo; |
| 26 | + |
| 27 | +import static org.assertj.core.api.Assertions.assertThat; |
| 28 | + |
| 29 | +/** |
| 30 | + * Tests for {@link ProcessInfoContributor}. |
| 31 | + * |
| 32 | + * @author Jonatan Ivanov |
| 33 | + */ |
| 34 | +class ProcessInfoContributorTests { |
| 35 | + |
| 36 | + @Test |
| 37 | + void processInfoShouldBeAdded() { |
| 38 | + ProcessInfoContributor processInfoContributor = new ProcessInfoContributor(); |
| 39 | + Info.Builder builder = new Info.Builder(); |
| 40 | + processInfoContributor.contribute(builder); |
| 41 | + Info info = builder.build(); |
| 42 | + assertThat(info.get("process")).isInstanceOf(ProcessInfo.class); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + void shouldRegisterHints() { |
| 47 | + RuntimeHints runtimeHints = new RuntimeHints(); |
| 48 | + new ProcessInfoContributorRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader()); |
| 49 | + assertThat(RuntimeHintsPredicates.reflection() |
| 50 | + .onType(ProcessInfo.class) |
| 51 | + .withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS)) |
| 52 | + .accepts(runtimeHints); |
| 53 | + } |
| 54 | + |
| 55 | +} |
0 commit comments