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 de.smartics.properties.api.config.domain;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.hasItem;
20  import static org.hamcrest.Matchers.hasItems;
21  import static org.hamcrest.Matchers.is;
22  
23  import java.util.List;
24  
25  import org.junit.Before;
26  import org.junit.Test;
27  
28  import de.smartics.testdoc.annotations.Uut;
29  
30  /**
31   * Tests {@link DependencyParser}.
32   */
33  public class DependencyParserTest
34  {
35    // ********************************* Fields *********************************
36  
37    // --- constants ------------------------------------------------------------
38  
39    // --- members --------------------------------------------------------------
40  
41    @Uut
42    private DependenciesParser uut;
43  
44    // ****************************** Inner Classes *****************************
45  
46    // ********************************* Methods ********************************
47  
48    // --- prepare --------------------------------------------------------------
49  
50    @Before
51    public void setUp()
52    {
53      uut = new DependenciesParser();
54    }
55  
56    // --- helper ---------------------------------------------------------------
57  
58    // --- tests ----------------------------------------------------------------
59  
60    @Test
61    public void theNullValueReturnsTheEmptyList()
62    {
63      final String value = null;
64      final List<String> dependencies = uut.getDependencies(value);
65      assertThat(dependencies.isEmpty(), is(true));
66    }
67  
68    @Test
69    public void aValueWithoutPlaceholdersReturnsTheEmptyList()
70    {
71      final String value = "noPlaceholderInside";
72      final List<String> dependencies = uut.getDependencies(value);
73      assertThat(dependencies.isEmpty(), is(true));
74    }
75  
76    @Test
77    public void aPlaceholderIsFound()
78    {
79      final String value = "${thePlaceholder}";
80      final List<String> dependencies = uut.getDependencies(value);
81      assertThat(dependencies, hasItem("thePlaceholder"));
82    }
83  
84    @Test
85    public void moreThanOnePlaceholderIsFound()
86    {
87      final String value = "${one} ${two} three";
88      final List<String> dependencies = uut.getDependencies(value);
89      assertThat(dependencies, hasItems("one", "two"));
90    }
91  }