View Javadoc

1   /*
2    * Copyright 2012 smartics, Kronseder & Reiner GmbH
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  package test.de.smartics.ci.config.load;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.allOf;
20  import static org.hamcrest.Matchers.containsString;
21  import static org.hamcrest.Matchers.is;
22  import static org.hamcrest.Matchers.sameInstance;
23  
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.junit.experimental.categories.Category;
27  
28  import de.smartics.ci.config.load.LoaderPlan;
29  import de.smartics.ci.config.maven.MavenConfig;
30  import de.smartics.ci.config.test.MavenConfigBuilder;
31  import de.smartics.testdoc.annotations.Uut;
32  import de.smartics.testdoc.categories.type.Construction;
33  import de.smartics.util.lang.BlankArgumentException;
34  import de.smartics.util.lang.NullArgumentException;
35  
36  /**
37   * Tests {@link LoaderPlan}.
38   */
39  @Uut(type = LoaderPlan.class)
40  @Category(Construction.class)
41  public class LoaderPlanConstructionTest
42  {
43    // ********************************* Fields *********************************
44  
45    // --- constants ------------------------------------------------------------
46  
47    // --- members --------------------------------------------------------------
48  
49    private MavenConfig mavenConfig;
50  
51    // ****************************** Inner Classes *****************************
52  
53    // ********************************* Methods ********************************
54  
55    // --- prepare --------------------------------------------------------------
56  
57    @Before
58    public void setUp()
59    {
60      mavenConfig = MavenConfigBuilder.a().build();
61    }
62  
63    // --- helper ---------------------------------------------------------------
64  
65    // --- tests ----------------------------------------------------------------
66  
67    @Test(expected = BlankArgumentException.class)
68    public void allowsNoBlankIdInConstruction()
69    {
70      new LoaderPlan("", mavenConfig);
71    }
72  
73    @Test(expected = NullArgumentException.class)
74    public void requiresAMavenConfig()
75    {
76      new LoaderPlan("valid", null);
77    }
78  
79    @Test
80    public void providesValidToStringWithoutElements()
81    {
82      final String id = "id";
83      final LoaderPlan uut = new LoaderPlan(id, mavenConfig);
84  
85      final String string = uut.toString();
86      assertThat(string, containsString(id));
87      assertThat(uut.getMavenConfig(), is(sameInstance(mavenConfig)));
88    }
89  
90    @Test
91    @SuppressWarnings("unchecked")
92    public void providesValidToStringWithElements()
93    {
94      final String id = "id";
95      final String configurationName = "valid";
96      final LoaderPlan uut = new LoaderPlan(id, mavenConfig);
97      uut.addConfigurationName(configurationName);
98  
99      final String string = uut.toString();
100     assertThat(string,
101         allOf(containsString(id), containsString(configurationName)));
102   }
103 }