001/** 002 * Powerunit - A JDK1.8 test framework 003 * Copyright (C) 2014 Mathieu Boretti. 004 * 005 * This file is part of Powerunit 006 * 007 * Powerunit is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License as published by 009 * the Free Software Foundation, either version 3 of the License, or 010 * (at your option) any later version. 011 * 012 * Powerunit is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * along with Powerunit. If not, see <http://www.gnu.org/licenses/>. 019 */ 020package ch.powerunit.rules; 021 022import ch.powerunit.TestContext; 023 024/** 025 * Default Rule to do some stuff before the test, and after (always). 026 * <p> 027 * This interface is provided here as a facility for rule provider, which will 028 * implement the {@link #before()} and {@link #after()} methods. The idea is to 029 * support use case that access some external system which need preparation and 030 * cleanup between each test. 031 * <p> 032 * To use this interface, implementer should : 033 * <ul> 034 * <li>Implement the method {@link #before()} with the code that prepare the 035 * external resource (creation of folder, start of server, etc).</li> 036 * <li>Implement the method {@link #after()} with the code that cleanup the 037 * external resource (destruction of folder, shutdown of server, etc). This 038 * method is used even in case the test is in failure or error.</li> 039 * </ul> 040 * 041 * @author borettim 042 */ 043public interface ExternalResource extends TestListenerRule { 044 045 @Override 046 default void onStart(TestContext<Object> context) { 047 before(); 048 } 049 050 @Override 051 default void onEnd(TestContext<Object> context) { 052 after(); 053 } 054 055 /** 056 * Code to be done before 057 */ 058 default void before() { 059 // Do nothing as default 060 } 061 062 /** 063 * Code to be done after. 064 */ 065 default void after() { 066 // Do nothing as default 067 } 068}