public static void addStory ( File caseManager , String storyName , String testPath , String user , String feature , String benefit ) throws BeastException { FileWriter caseManagerWriter ; String storyClass = SystemReader . createClassName ( storyName ) ; try { BufferedReader reader = new BufferedReader ( new FileReader ( caseManager ) ) ; String targetLine1 = " public void " + MASReader . createFirstLowCaseName ( storyName ) + "() {" ; String targetLine2 = " Result result = JUnitCore.runClasses(" + testPath + "." + storyClass + ".class);" ; String in ; while ( ( in = reader . readLine ( ) ) != null ) { if ( in . equals ( targetLine1 ) ) { while ( ( in = reader . readLine ( ) ) != null ) { if ( in . equals ( targetLine2 ) ) { reader . close ( ) ; // This test is already written in the case manager. return ; } } reader . close ( ) ; throw new BeastException ( "Two different stories with the same name (same method name) are being created in the same CaseManager file. That is not possible. Please, change the name of the story: " + testPath + "." + storyClass + ".java" ) ; } } reader . close ( ) ; caseManagerWriter = new FileWriter ( caseManager , true ) ; caseManagerWriter . write ( " /**\n" ) ; caseManagerWriter . write ( " * This is the story: " + storyName + "\n" ) ; caseManagerWriter . write ( " * requested by: " + user + "\n" ) ; caseManagerWriter . write ( " * providing the feature: " + feature + "\n" ) ; caseManagerWriter . write ( " * so the user gets the benefit: " + benefit + "\n" ) ; caseManagerWriter . write ( " */\n" ) ; caseManagerWriter . write ( " @Test\n" ) ; caseManagerWriter . write ( " public void " + MASReader . createFirstLowCaseName ( storyName ) + "() {\n" ) ; caseManagerWriter . write ( " Result result = JUnitCore.runClasses(" + testPath + "." + storyClass + ".class);\n" ) ; caseManagerWriter . write ( " Assert.assertTrue(result.wasSuccessful());\n" ) ; caseManagerWriter . write ( " }\n" ) ; caseManagerWriter . write ( "\n" ) ; caseManagerWriter . flush ( ) ; caseManagerWriter . close ( ) ; } catch ( IOException e ) { Logger logger = Logger . getLogger ( "CreateMASCaseManager.createTest" ) ; logger . info ( "ERROR writing the file" ) ; } }
The third method to write caseManager . Its task is to write the call to the story to be run .