|
| 1 | +/* |
| 2 | + * Copyright 2012-2013 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.sample.aop; |
| 18 | + |
| 19 | +import org.junit.After; |
| 20 | +import org.junit.Before; |
| 21 | +import org.junit.Rule; |
| 22 | +import org.junit.Test; |
| 23 | +import org.springframework.boot.OutputCapture; |
| 24 | +import org.springframework.boot.sample.aop.SampleAopApplication; |
| 25 | + |
| 26 | +import static org.junit.Assert.assertTrue; |
| 27 | + |
| 28 | +/** |
| 29 | + * Tests for {@link SampleAopApplication}. |
| 30 | + * |
| 31 | + * @author Dave Syer |
| 32 | + * @author Phillip Webb |
| 33 | + */ |
| 34 | +public class SampleAopApplicationTests { |
| 35 | + |
| 36 | + @Rule |
| 37 | + public OutputCapture outputCapture = new OutputCapture(); |
| 38 | + |
| 39 | + private String profiles; |
| 40 | + |
| 41 | + @Before |
| 42 | + public void init() { |
| 43 | + this.profiles = System.getProperty("spring.profiles.active"); |
| 44 | + } |
| 45 | + |
| 46 | + @After |
| 47 | + public void after() { |
| 48 | + if (this.profiles != null) { |
| 49 | + System.setProperty("spring.profiles.active", this.profiles); |
| 50 | + } |
| 51 | + else { |
| 52 | + System.clearProperty("spring.profiles.active"); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void testDefaultSettings() throws Exception { |
| 58 | + SampleAopApplication.main(new String[0]); |
| 59 | + String output = this.outputCapture.toString(); |
| 60 | + assertTrue("Wrong output: " + output, output.contains("Hello Phil")); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void testCommandLineOverrides() throws Exception { |
| 65 | + SampleAopApplication.main(new String[] { "--name=Gordon" }); |
| 66 | + String output = this.outputCapture.toString(); |
| 67 | + assertTrue("Wrong output: " + output, output.contains("Hello Gordon")); |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments