View Javadoc

1   /*
2    * Copyright 2012-2013 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.properties.api.core.domain;
17  
18  import static help.de.smartics.properties.core.PropertiesContextBuilder.DEFAULT_HOME_PAGE_URL;
19  import static help.de.smartics.properties.core.PropertiesContextBuilder.DEFAULT_PROPERTIES_REPORT_URL;
20  import static org.hamcrest.MatcherAssert.assertThat;
21  import static org.hamcrest.Matchers.is;
22  import static org.hamcrest.Matchers.nullValue;
23  
24  import org.junit.Test;
25  
26  import de.smartics.properties.api.core.domain.PropertiesContext;
27  import de.smartics.testdoc.annotations.Uut;
28  
29  /**
30   * Tests building instances of {@link PropertiesContext}.
31   */
32  @Uut(type = PropertiesContext.class)
33  public class PropertiesContextCreationTest
34  {
35    // ********************************* Fields *********************************
36  
37    // --- constants ------------------------------------------------------------
38  
39    // --- members --------------------------------------------------------------
40  
41    // ****************************** Inner Classes *****************************
42  
43    // ********************************* Methods ********************************
44  
45    // --- prepare --------------------------------------------------------------
46  
47    // --- helper ---------------------------------------------------------------
48  
49    // --- tests ----------------------------------------------------------------
50  
51    @Test(expected = NullPointerException.class)
52    public void requiresHomePageUrl()
53    {
54      new PropertiesContext.Builder().withHomePageUrl(null);
55    }
56  
57    @Test(expected = NullPointerException.class)
58    public void requiresPropertiesReportUrl()
59    {
60      new PropertiesContext.Builder().withPropertiesReportUrl(null);
61    }
62  
63    @Test
64    public void providesAccessToItsInformation()
65    {
66      final PropertiesContext.Builder builder =
67          new PropertiesContext.Builder().withHomePageUrl(DEFAULT_HOME_PAGE_URL)
68              .withPropertiesReportUrl(DEFAULT_PROPERTIES_REPORT_URL);
69      final PropertiesContext uut = builder.build();
70  
71      assertThat(uut.getHomePageUrl(), is(DEFAULT_HOME_PAGE_URL));
72      assertThat(uut.getPropertiesReportUrl(), is(DEFAULT_PROPERTIES_REPORT_URL));
73      assertThat(uut.getPropertiesReportIndexUrl(),
74          is(DEFAULT_PROPERTIES_REPORT_URL + "/smartics-properties-report.html"));
75    }
76  
77    @Test
78    public void returnsNullIfInformationIsMissing()
79    {
80      final PropertiesContext.Builder builder = new PropertiesContext.Builder();
81      final PropertiesContext uut = builder.build();
82  
83      assertThat(uut.getHomePageUrl(), is(nullValue()));
84      assertThat(uut.getPropertiesReportUrl(), is(nullValue()));
85      assertThat(uut.getPropertiesReportIndexUrl(), is(nullValue()));
86    }
87  
88    @Test
89    public void removesATrailingSlashFromReportUrl()
90    {
91      final PropertiesContext.Builder builder =
92          new PropertiesContext.Builder().withHomePageUrl(DEFAULT_HOME_PAGE_URL)
93              .withPropertiesReportUrl(DEFAULT_PROPERTIES_REPORT_URL + '/');
94      final PropertiesContext uut = builder.build();
95  
96      assertThat(uut.getPropertiesReportUrl(), is(DEFAULT_PROPERTIES_REPORT_URL));
97    }
98  }