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.testng.testcase;
016    
017    import org.testng.annotations.AfterMethod;
018    import org.testng.annotations.BeforeClass;
019    import org.testng.annotations.BeforeMethod;
020    
021    import org.fest.swing.core.Robot;
022    import org.fest.swing.edt.FailOnThreadViolationRepaintManager;
023    import org.fest.swing.testing.FestSwingTestCaseTemplate;
024    
025    /**
026     * Understands a template for test cases that use FEST-Swing and TestNG. This template installs a
027     * <code>{@link FailOnThreadViolationRepaintManager}</code> to catch violations of Swing thread rules and manages both
028     * creation and clean up of a <code>{@link Robot}</code>.
029     * @since 1.1
030     *
031     * @author Alex Ruiz
032     */
033    public abstract class FestSwingTestngTestCase extends FestSwingTestCaseTemplate {
034    
035      /**
036       * Installs a <code>{@link FailOnThreadViolationRepaintManager}</code> to catch violations of Swing threading rules.
037       */
038      @BeforeClass
039      public final void setUpOnce() {
040        FailOnThreadViolationRepaintManager.install();
041      }
042    
043      /**
044       * Sets up this test's fixture, starting from creation of a new <code>{@link Robot}</code>.
045       * @see #setUpRobot()
046       * @see #onSetUp()
047       */
048      @BeforeMethod
049      public final void setUp() {
050        setUpRobot();
051        onSetUp();
052      }
053    
054      /**
055       * Subclasses need set up their own test fixture in this method. This method is called <strong>after</strong>
056       * executing <code>{@link #setUp()}</code>.
057       */
058      protected abstract void onSetUp();
059    
060      /**
061       * Cleans up any resources used in this test. After calling <code>{@link #onTearDown()}</code>, this method cleans up
062       * resources used by this test's <code>{@link Robot}</code>.
063       * @see #cleanUp()
064       * @see #onTearDown()
065       */
066      @AfterMethod
067      public final void tearDown() {
068        try {
069          onTearDown();
070        } finally {
071          cleanUp();
072        }
073      }
074    
075      /**
076       * Subclasses need to clean up resources in this method. This method is called <strong>before</strong> executing
077       * <code>{@link #tearDown()}</code>.
078       */
079      protected void onTearDown() {}
080    }