|
| 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.info; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.BeforeEach; |
| 20 | +import org.junit.jupiter.api.Test; |
| 21 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 22 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 23 | + |
| 24 | +import org.springframework.boot.SpringBootVersion; |
| 25 | +import org.springframework.core.SpringVersion; |
| 26 | +import org.springframework.mock.env.MockEnvironment; |
| 27 | + |
| 28 | +import static org.assertj.core.api.Assertions.assertThat; |
| 29 | + |
| 30 | +/** |
| 31 | + * Tests for {@link SpringInfo}. |
| 32 | + * |
| 33 | + * @author Jonatan Ivanov |
| 34 | + */ |
| 35 | +@ExtendWith(MockitoExtension.class) |
| 36 | +class SpringInfoTests { |
| 37 | + |
| 38 | + private MockEnvironment environment; |
| 39 | + |
| 40 | + @BeforeEach |
| 41 | + void setUp() { |
| 42 | + this.environment = new MockEnvironment(); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + void springInfoIsAvailableWithoutExplicitProfiles() { |
| 47 | + SpringInfo info = new SpringInfo(this.environment); |
| 48 | + assertThat(info.getFramework().getVersion()).isEqualTo(SpringVersion.getVersion()); |
| 49 | + assertThat(info.getFramework().getProfiles()).containsExactly("default"); |
| 50 | + assertThat(info.getBoot().getVersion()).isEqualTo(SpringBootVersion.getVersion()); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + void springInfoContainsDefaultProfilesIfDefaultProfileIsSet() { |
| 55 | + this.environment.setDefaultProfiles("test-default-profile"); |
| 56 | + SpringInfo info = new SpringInfo(this.environment); |
| 57 | + assertThat(info.getFramework().getProfiles()).containsExactly("test-default-profile"); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + void springInfoContainsActiveProfilesIfActiveProfilesIsSet() { |
| 62 | + this.environment.setActiveProfiles("test-active-profile"); |
| 63 | + SpringInfo info = new SpringInfo(this.environment); |
| 64 | + assertThat(info.getFramework().getProfiles()).containsExactly("test-active-profile"); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + void springInfoContainsActiveProfilesIfBothDefaultAndActiveProfilesAreSet() { |
| 69 | + this.environment.setDefaultProfiles("test-default-profile"); |
| 70 | + this.environment.setActiveProfiles("test-active-profile"); |
| 71 | + SpringInfo info = new SpringInfo(this.environment); |
| 72 | + assertThat(info.getFramework().getProfiles()).containsExactly("test-active-profile"); |
| 73 | + } |
| 74 | + |
| 75 | +} |
0 commit comments