package de.retest.recheck;

import de.retest.recheck.persistence.FileNamer;

/**
 * Determines the paths under which Golden Master and result files should be persisted. Default implementation derives
 * suit and test name from test class name and test method, working for both JUnit and TestNG.
 */
public interface FileNamerStrategy {

	/**
	 * Creates a file namer for the given base names. For Golden Master files, these typically follow the format
	 * <code>${TEST_CLASS_NAME}/${TEST_METHOD_NAME}.${STEP_NAME}</code>, whereas result files only use
	 * <code>${TEST_CLASS_NAME}</code>.
	 *
	 * @param baseNames
	 *            the base names to be used
	 * @return a file namer using the given base names
	 */
	FileNamer createFileNamer( String... baseNames );

	/**
	 * Determines the current test class name.
	 *
	 * @return name of the current test class
	 */
	default String getTestClassName() {
		final StackTraceElement testMethodStack = TestCaseFinder.findTestCaseMethodInStack();
		if ( testMethodStack != null ) {
			return testMethodStack.getClassName();
		}
		throw new RuntimeException( "Couldn't identify test class in call stack. \n"
				+ "This name is needed to dynamically name the Golden Master files. \n "
				+ "Please instantiate RecheckImpl with RecheckOptions, and provide a different FileNamerStrategy." );
	}

	/**
	 * Determines the current test method name.
	 *
	 * @return name of the current test method
	 */
	default String getTestMethodName() {
		final StackTraceElement testMethodStack = TestCaseFinder.findTestCaseMethodInStack();
		if ( testMethodStack != null ) {
			return testMethodStack.getMethodName();
		}
		throw new RuntimeException( "Couldn't identify test method in call stack. \n"
				+ "This name is needed to dynamically name the Golden Master files. \n"
				+ "Please call `startTest(\"name\")`, giving an explicit name, "
				+ "or instantiate RecheckImpl with RecheckOptions, and provide a different FileNamerStrategy." );
	}

}

@@ -1068,38 +1068,43 @@
 %09%09%7D%0A%09%09throw new 
-Runtim
+IllegalStat
 eException( %22Cou
@@ -1152,37 +1152,32 @@
 %5Cn%22%0A%09%09%09%09+ %22This 
-name 
 is needed to dyn
@@ -1657,14 +1657,19 @@
 new 
-Runtim
+IllegalStat
 eExc
@@ -1738,21 +1738,16 @@
 + %22This 
-name 
 is neede

Use IllegalStateException instead of generic runtime