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 org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.allOf;
20  import static org.hamcrest.Matchers.hasItem;
21  import static org.hamcrest.Matchers.is;
22  import static org.hamcrest.Matchers.not;
23  import static org.hamcrest.Matchers.nullValue;
24  
25  import java.io.Serializable;
26  
27  import org.junit.Test;
28  import org.junit.experimental.categories.Category;
29  
30  import de.smartics.properties.api.core.domain.PropertyValueComment;
31  import de.smartics.testdoc.annotations.Uut;
32  import de.smartics.testdoc.categories.type.Coverage;
33  
34  /**
35   * Tests {@link PropertyValueComment}.
36   */
37  @Uut(type = PropertyValueComment.class)
38  public class PropertyValueCommentTest
39  {
40    // ********************************* Fields *********************************
41  
42    // --- constants ------------------------------------------------------------
43  
44    private static final String DEFAULT_SUMMARY = "Test comment";
45  
46    // --- members --------------------------------------------------------------
47  
48    // ****************************** Inner Classes *****************************
49  
50    // ********************************* Methods ********************************
51  
52    // --- prepare --------------------------------------------------------------
53  
54    // --- helper ---------------------------------------------------------------
55  
56    // --- tests ----------------------------------------------------------------
57  
58    @Test
59    public void providesASummaryComment()
60    {
61      final PropertyValueComment uut = new PropertyValueComment(DEFAULT_SUMMARY);
62  
63      assertThat(uut.getSummary(), is(DEFAULT_SUMMARY));
64    }
65  
66    @Test
67    public void allowsToAddValueCommentsComment()
68    {
69      final PropertyValueComment uut = new PropertyValueComment(DEFAULT_SUMMARY);
70      final Serializable value1 = "Value 1";
71      final String comment1 = "Value 1 Comment";
72      final Serializable value2 = 42;
73      final String comment2 = "Value 2 Comment";
74  
75      uut.addValueComment(value1, comment1);
76      uut.addValueComment(value2, comment2);
77  
78      assertThat(uut.getValueComment(value1), is(comment1));
79      assertThat(uut.getValueComment(value2), is(comment2));
80      assertThat(uut.getValues(), allOf(hasItem(value1), hasItem(value2)));
81    }
82  
83    @Test
84    @Category(Coverage.class)
85    public void toStringOnEmptyInstanceDoesNotFail()
86    {
87      final PropertyValueComment uut = new PropertyValueComment(null);
88  
89      assertThat(uut.toString(), is(not(nullValue())));
90    }
91  
92    @Test
93    @Category(Coverage.class)
94    public void toStringOnFullInstanceDoesNotFail()
95    {
96      final PropertyValueComment uut = new PropertyValueComment(DEFAULT_SUMMARY);
97      final Serializable value1 = "Value 1";
98      final String comment1 = "Value 1 Comment";
99      final Serializable value2 = 42;
100     final String comment2 = "Value 2 Comment";
101 
102     uut.addValueComment(value1, comment1);
103     uut.addValueComment(value2, comment2);
104 
105     assertThat(uut.toString(), is(not(nullValue())));
106   }
107 }