1   package org.apache.maven.surefire.assertion;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import junit.framework.TestCase;
23  
24  /**
25   * Test the comparison tool string representations.
26   */
27  public class ComparisonToolTest
28      extends TestCase
29  {
30      public void testFormatMismatchNoMessage()
31      {
32          assertEquals( "expected:<foo> but was:<bar>", ComparisonTool.formatMismatch( null, "foo", "bar" ) );
33      }
34  
35      public void testFormatMismatchWithMessage()
36      {
37          assertEquals( "msg expected:<foo> but was:<bar>", ComparisonTool.formatMismatch( "msg", "foo", "bar" ) );
38      }
39  
40      public void testTrimComparisonActualNull()
41      {
42          assertEquals( "msg expected:<foo> but was:<null>", ComparisonTool.trimComparison( "msg", "foo", null ) );
43      }
44  
45      public void testTrimComparisonExpectedNull()
46      {
47          assertEquals( "msg expected:<null> but was:<bar>", ComparisonTool.trimComparison( "msg", null, "bar" ) );
48      }
49  
50      public void testTrimComparisonBothNull()
51      {
52          try
53          {
54              ComparisonTool.trimComparison( "msg", null, null );
55              fail( "Should fail to pass in equal values" );
56          }
57          catch ( IllegalArgumentException e )
58          {
59              // correct
60          }
61      }
62  
63      public void testTrimComparisonEqual()
64      {
65          try
66          {
67              ComparisonTool.trimComparison( "msg", "foo", "foo" );
68              fail( "Should fail to pass in equal values" );
69          }
70          catch ( IllegalArgumentException e )
71          {
72              // correct
73          }
74      }
75  
76      public void testTrimComparisonNoMatch()
77      {
78          assertEquals( "msg expected:<foo> but was:<bar>", ComparisonTool.trimComparison( "msg", "foo", "bar" ) );
79      }
80  
81      public void testTrimComparisonMatchStart()
82      {
83          assertEquals( "msg expected:<...rah> but was:<...bar>",
84                        ComparisonTool.trimComparison( "msg", "foorah", "foobar" ) );
85      }
86  
87      public void testTrimComparisonMatchStartWholeExpected()
88      {
89          assertEquals( "msg expected:<...> but was:<...bar>", ComparisonTool.trimComparison( "msg", "foo", "foobar" ) );
90      }
91  
92      public void testTrimComparisonMatchStartWholeActual()
93      {
94          assertEquals( "msg expected:<...rah> but was:<...>", ComparisonTool.trimComparison( "msg", "foorah", "foo" ) );
95      }
96  
97      public void testTrimComparisonMatchEnd()
98      {
99          assertEquals( "msg expected:<bop...> but was:<foo...>",
100                       ComparisonTool.trimComparison( "msg", "bopbar", "foobar" ) );
101     }
102 
103     public void testTrimComparisonMatchEndWholeExpected()
104     {
105         assertEquals( "msg expected:<...> but was:<foo...>", ComparisonTool.trimComparison( "msg", "bar", "foobar" ) );
106     }
107 
108     public void testTrimComparisonMatchEndWholeActual()
109     {
110         assertEquals( "msg expected:<foo...> but was:<...>", ComparisonTool.trimComparison( "msg", "foorah", "rah" ) );
111     }
112 
113     public void testTrimComparisonMatchStartAndEnd()
114     {
115         assertEquals( "msg expected:<...bar...> but was:<...foo...>",
116                       ComparisonTool.trimComparison( "msg", "foobarbaz", "foofoobaz" ) );
117     }
118 
119     public void testTrimComparisonMatchStartAndEndWholeExpected()
120     {
121         assertEquals( "msg expected:<......> but was:<...def...>",
122                       ComparisonTool.trimComparison( "msg", "abcghi", "abcdefghi" ) );
123     }
124 
125     public void testTrimComparisonMatchStartAndEndWholeActual()
126     {
127         assertEquals( "msg expected:<...def...> but was:<......>",
128                       ComparisonTool.trimComparison( "msg", "abcdefghi", "abcghi" ) );
129     }
130 }