001 /*
002 * Created on Jan 17, 2009
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
005 * the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
010 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
011 * specific language governing permissions and limitations under the License.
012 *
013 * Copyright @2009 the original author or authors.
014 */
015 package org.fest.swing.junit.testcase;
016
017 import org.fest.swing.core.Robot;
018 import org.fest.swing.edt.FailOnThreadViolationRepaintManager;
019 import org.fest.swing.testing.FestSwingTestCaseTemplate;
020 import org.junit.*;
021
022 /**
023 * Understands a template for test cases that use FEST-Swing and JUnit. This template installs a
024 * <code>{@link FailOnThreadViolationRepaintManager}</code> to catch violations of Swing thread rules and manages both
025 * creation and clean up of a <code>{@link Robot}</code>.
026 * @since 1.1
027 *
028 * @author Alex Ruiz
029 */
030 public abstract class FestSwingJUnitTestCase extends FestSwingTestCaseTemplate {
031
032 /**
033 * Installs a <code>{@link FailOnThreadViolationRepaintManager}</code> to catch violations of Swing threading rules.
034 */
035 @BeforeClass
036 public static final void setUpOnce() {
037 FailOnThreadViolationRepaintManager.install();
038 }
039
040 /**
041 * Sets up this test's fixture, starting from creation of a new <code>{@link Robot}</code>.
042 * @see #setUpRobot()
043 * @see #onSetUp()
044 */
045 @Before
046 public final void setUp() {
047 setUpRobot();
048 onSetUp();
049 }
050
051 /**
052 * Subclasses need set up their own test fixture in this method. This method is called <strong>after</strong>
053 * executing <code>{@link #setUp()}</code>.
054 */
055 protected abstract void onSetUp();
056
057 /**
058 * Cleans up any resources used in this test. After calling <code>{@link #onTearDown()}</code>, this method cleans up
059 * resources used by this test's <code>{@link Robot}</code>.
060 * @see #cleanUp()
061 * @see #onTearDown()
062 */
063 @After
064 public final void tearDown() {
065 try {
066 onTearDown();
067 } finally {
068 cleanUp();
069 }
070 }
071
072 /**
073 * Subclasses need to clean up resources in this method. This method is called <strong>before</strong> executing
074 * <code>{@link #tearDown()}</code>.
075 */
076 protected void onTearDown() {}
077 }