001    /*
002     * Created on Mar 13, 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.v4_5.runner;
016    
017    import org.fest.swing.junit.runner.FailureScreenshotTaker;
018    import org.fest.swing.junit.runner.ImageFolderCreator;
019    import org.junit.runners.BlockJUnit4ClassRunner;
020    import org.junit.runners.model.*;
021    
022    /**
023     * Understands a JUnit 4.5 test runner that takes a screenshot of a failed GUI test.
024     *
025     * @author Alex Ruiz
026     * @author Yvonne Wang
027     */
028    public class GUITestRunner extends BlockJUnit4ClassRunner {
029    
030      private final FailureScreenshotTaker screenshotTaker;
031    
032      /**
033       * Creates a new <code>{@link GUITestRunner}</code>.
034       * @param testClass the class containing the tests to run.
035       * @throws InitializationError if something goes wrong when creating this runner.
036       */
037      public GUITestRunner(Class<?> testClass) throws InitializationError {
038        super(testClass);
039        screenshotTaker = new FailureScreenshotTaker(new ImageFolderCreator().createImageFolder());
040      }
041    
042      /**
043       * Returns a <code>{@link Statement}</code> that invokes {@code method} on {@code test}. The created statement will
044       * take and save the screenshot of the desktop in case of a failure.
045       */
046      @Override
047      protected Statement methodInvoker(FrameworkMethod method, Object test) {
048        return new MethodInvoker(method, test, screenshotTaker);
049      }
050    }