|
| 1 | +/* |
| 2 | + * Copyright 2012-2017 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 | + * http://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.configurationprocessor; |
| 18 | + |
| 19 | +import java.io.File; |
| 20 | +import java.io.IOException; |
| 21 | + |
| 22 | +import javax.annotation.processing.ProcessingEnvironment; |
| 23 | + |
| 24 | +import org.junit.Rule; |
| 25 | +import org.junit.Test; |
| 26 | +import org.junit.rules.TemporaryFolder; |
| 27 | + |
| 28 | +import static org.assertj.core.api.Assertions.assertThat; |
| 29 | +import static org.mockito.Mockito.mock; |
| 30 | + |
| 31 | +/** |
| 32 | + * Tests for {@link MetadataStore}. |
| 33 | + * |
| 34 | + * @author Andy Wilkinson |
| 35 | + */ |
| 36 | +public class MetadataStoreTests { |
| 37 | + |
| 38 | + @Rule |
| 39 | + public final TemporaryFolder temp = new TemporaryFolder(); |
| 40 | + |
| 41 | + private final MetadataStore metadataStore = new MetadataStore( |
| 42 | + mock(ProcessingEnvironment.class)); |
| 43 | + |
| 44 | + @Test |
| 45 | + public void additionalMetadataIsLocatedInMavenBuild() throws IOException { |
| 46 | + File app = this.temp.newFolder("app"); |
| 47 | + File classesLocation = new File(app, "target/classes"); |
| 48 | + File metaInf = new File(classesLocation, "META-INF"); |
| 49 | + metaInf.mkdirs(); |
| 50 | + File additionalMetadata = new File(metaInf, |
| 51 | + "additional-spring-configuration-metadata.json"); |
| 52 | + additionalMetadata.createNewFile(); |
| 53 | + assertThat( |
| 54 | + this.metadataStore.locateAdditionalMetadataFile(new File(classesLocation, |
| 55 | + "META-INF/additional-spring-configuration-metadata.json"))) |
| 56 | + .isEqualTo(additionalMetadata); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void additionalMetadataIsLocatedInGradle3Build() throws IOException { |
| 61 | + File app = this.temp.newFolder("app"); |
| 62 | + File classesLocation = new File(app, "build/classes/main"); |
| 63 | + File resourcesLocation = new File(app, "build/resources/main"); |
| 64 | + File metaInf = new File(resourcesLocation, "META-INF"); |
| 65 | + metaInf.mkdirs(); |
| 66 | + File additionalMetadata = new File(metaInf, |
| 67 | + "additional-spring-configuration-metadata.json"); |
| 68 | + additionalMetadata.createNewFile(); |
| 69 | + assertThat( |
| 70 | + this.metadataStore.locateAdditionalMetadataFile(new File(classesLocation, |
| 71 | + "META-INF/additional-spring-configuration-metadata.json"))) |
| 72 | + .isEqualTo(additionalMetadata); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void additionalMetadataIsLocatedInGradle4Build() throws IOException { |
| 77 | + File app = this.temp.newFolder("app"); |
| 78 | + File classesLocation = new File(app, "build/classes/java/main"); |
| 79 | + File resourcesLocation = new File(app, "build/resources/main"); |
| 80 | + File metaInf = new File(resourcesLocation, "META-INF"); |
| 81 | + metaInf.mkdirs(); |
| 82 | + File additionalMetadata = new File(metaInf, |
| 83 | + "additional-spring-configuration-metadata.json"); |
| 84 | + additionalMetadata.createNewFile(); |
| 85 | + assertThat( |
| 86 | + this.metadataStore.locateAdditionalMetadataFile(new File(classesLocation, |
| 87 | + "META-INF/additional-spring-configuration-metadata.json"))) |
| 88 | + .isEqualTo(additionalMetadata); |
| 89 | + } |
| 90 | + |
| 91 | +} |
0 commit comments