View Javadoc

1   // Copyright (C) 2006 - 2008 Philip Aston
2   // All rights reserved.
3   //
4   // This file is part of The Grinder software distribution. Refer to
5   // the file LICENSE which is part of The Grinder distribution for
6   // licensing details. The Grinder distribution is available on the
7   // Internet at http://grinder.sourceforge.net/
8   //
9   // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
10  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
12  // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
13  // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
14  // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
15  // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
16  // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
17  // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
18  // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
19  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
20  // OF THE POSSIBILITY OF SUCH DAMAGE.
21  
22  package net.grinder.console.swingui;
23  
24  import java.awt.Dimension;
25  import java.awt.Point;
26  import java.awt.Rectangle;
27  import java.io.File;
28  
29  import javax.swing.JFrame;
30  
31  import net.grinder.console.common.Resources;
32  import net.grinder.console.common.ResourcesImplementation;
33  import net.grinder.console.model.ConsoleProperties;
34  import net.grinder.testutility.AbstractFileTestCase;
35  import net.grinder.testutility.AssertUtilities;
36  
37  
38  /**
39   * Unit tests for {@link FrameBounds}.
40   *
41   * @author Philip Aston
42   */
43  public class TestFrameBounds extends AbstractFileTestCase {
44    private static final Resources s_resources =
45      new ResourcesImplementation(
46        "net.grinder.console.common.resources.Console");
47  
48    private File m_file;
49  
50    protected void setUp() throws Exception {
51      super.setUp();
52      m_file = new File(getDirectory(), "properties");
53    }
54  
55    public void testFrameBounds() throws Exception {
56      final ConsoleProperties properties =
57        new ConsoleProperties(s_resources, m_file);
58  
59      final JFrame frame = new JFrame();
60  
61      final FrameBounds frameBounds = new FrameBounds(properties, frame);
62      frameBounds.restore();
63  
64      final Rectangle bounds1 = frame.getBounds();
65      assertEquals(new Dimension(900, 600), frame.getSize());
66      AssertUtilities.assertNotEquals(new Point(0, 0), frame.getLocation());
67  
68      frameBounds.store();
69  
70      final ConsoleProperties properties2 =
71        new ConsoleProperties(s_resources, m_file);
72  
73      final FrameBounds frameBounds2 = new FrameBounds(properties2, frame);
74      frameBounds2.restore();
75  
76      assertEquals(bounds1, frame.getBounds());
77  
78      frame.setLocation(-1000, -1000);
79      frameBounds.store();
80  
81      frameBounds.restore();
82  
83      assertEquals(bounds1, frame.getBounds());
84    }
85  }