View Javadoc

1   // Copyright (C) 2007 Venelin Mitov
2   // Copyright (C) 2007 Philip Aston
3   // All rights reserved.
4   //
5   // This file is part of The Grinder software distribution. Refer to
6   // the file LICENSE which is part of The Grinder distribution for
7   // licensing details. The Grinder distribution is available on the
8   // Internet at http://grinder.sourceforge.net/
9   //
10  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
12  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13  // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
14  // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
15  // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
16  // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
17  // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
19  // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
20  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
21  // OF THE POSSIBILITY OF SUCH DAMAGE.
22  
23  package net.grinder.tools.tcpproxy;
24  
25  import junit.framework.TestCase;
26  
27  import net.grinder.testutility.AssertUtilities;
28  
29  
30  /**
31   * Unit test case for {@linkplain CommentSource}.
32   *
33   * @author Venelin Mitov
34   */
35  public class TestCommentSourceImplementation extends TestCase {
36  
37    /**
38     * Single thread test
39     *
40     * @throws Exception
41     */
42    public void testAddGetComments() throws Exception {
43      String[] comments = new String[] { "BEGIN Enter home URL",
44          "END Enter home URL", "BEGIN Click Sign In", "END Click Sign In",
45          "BEGIN Click Read Mails", "END Click Read Mails", };
46  
47      CommentSourceImplementation csi = new CommentSourceImplementation();
48  
49      AssertUtilities.assertArraysEqual(new String[0], csi.getComments());
50  
51      csi.addComment(comments[0]);
52      assertEquals(comments[0], csi.getComments()[0]);
53      AssertUtilities.assertArraysEqual(new String[0], csi.getComments());
54  
55      csi.addComment(comments[1]);
56      assertEquals(comments[1], csi.getComments()[0]);
57      AssertUtilities.assertArraysEqual(new String[0], csi.getComments());
58  
59      csi.addComment(comments[2]);
60      csi.addComment(comments[3]);
61      csi.addComment(comments[4]);
62  
63      String[] currentComments = csi.getComments();
64  
65      assertEquals(comments[2], currentComments[0]);
66      assertEquals(comments[3], currentComments[1]);
67      assertEquals(comments[4], currentComments[2]);
68  
69      AssertUtilities.assertArraysEqual(new String[0], csi.getComments());
70      AssertUtilities.assertArraysEqual(new String[0], csi.getComments());
71  
72      csi.addComment(comments[5]);
73      assertEquals(comments[5], csi.getComments()[0]);
74      AssertUtilities.assertArraysEqual(new String[0], csi.getComments());
75  
76    }
77  }