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 /** 046 * This method delegate to the {@link #before()} method. 047 * 048 * @param context 049 * the context. 050 */ 051 @Override 052 default void onStart(TestContext<Object> context) { 053 before(); 054 } 055 056 /** 057 * This method delegate to the {@link #after()} method. 058 * 059 * @param context 060 * the context. 061 */ 062 @Override 063 default void onEnd(TestContext<Object> context) { 064 after(); 065 } 066 067 /** 068 * Code to be done before 069 */ 070 default void before() { 071 // Do nothing as default 072 } 073 074 /** 075 * Code to be done after. 076 */ 077 default void after() { 078 // Do nothing as default 079 } 080}