private File getStoreFile() { return directory.createFile( "storeFile" ); }
@Test void failAndKeepDirectory() { File file = directory.createFile( "b" ); CONTEXT.setValue( FAILED_TEST_FILE_KEY, file ); throw new RuntimeException( "simulate test failure" ); }
@Test void executeAndCleanupDirectory() { File file = directory.createFile( "a" ); assertTrue( file.exists() ); CONTEXT.setValue( SUCCESSFUL_TEST_FILE_KEY, file ); }
@Test public void mustNotWarnAboutDuplicateJvmAdditionalSettings() throws Exception { Log log = mock( Log.class ); File confFile = testDirectory.createFile( "test.conf" ); Files.write( confFile.toPath(), Arrays.asList( ExternalSettings.additionalJvm.name() + "=-Dsysprop=val", ExternalSettings.additionalJvm.name() + "=-XX:+UseG1GC", ExternalSettings.additionalJvm.name() + "=-XX:+AlwaysPreTouch" ) ); Config config = Config.fromFile( confFile ).build(); config.setLogger( log ); // The ExternalSettings.additionalJvm setting is allowed to be specified more than once. verifyNoMoreInteractions( log ); }
@Test void createTestFile() { File file = testDirectory.createFile( "a" ); assertEquals( "a", file.getName() ); assertTrue( fileSystem.fileExists( file ) ); }
@Test public void mustWarnIfFileContainsDuplicateSettings() throws Exception { Log log = mock( Log.class ); File confFile = testDirectory.createFile( "test.conf" ); Files.write( confFile.toPath(), Arrays.asList( ExternalSettings.initialHeapSize.name() + "=5g", ExternalSettings.initialHeapSize.name() + "=4g", ExternalSettings.initialHeapSize.name() + "=3g", ExternalSettings.maxHeapSize.name() + "=10g", ExternalSettings.maxHeapSize.name() + "=10g" ) ); Config config = Config.fromFile( confFile ).build(); config.setLogger( log ); // We should only log the warning once for each. verify( log ).warn( "The '%s' setting is specified more than once. Settings only be specified once, to avoid ambiguity. " + "The setting value that will be used is '%s'.", ExternalSettings.initialHeapSize.name(), "5g" ); verify( log ).warn( "The '%s' setting is specified more than once. Settings only be specified once, to avoid ambiguity. " + "The setting value that will be used is '%s'.", ExternalSettings.maxHeapSize.name(), "10g" ); }
@Override public void afterEach( ExtensionContext context ) { Profiler profiler = getStoredValue( context ); try { profiler.finish(); if ( context.getExecutionException().isPresent() ) { ExtensionContext.Store testDirStore = getStore( context, TestDirectoryExtension.TEST_DIRECTORY_NAMESPACE ); TestDirectory testDir = (TestDirectory) testDirStore.get( TestDirectoryExtension.TEST_DIRECTORY ); File profileOutputFile = testDir.createFile( "profiler-output.txt" ); FileSystemAbstraction fs = testDir.getFileSystem(); try ( PrintStream out = new PrintStream( fs.openAsOutputStream( profileOutputFile, false ) ) ) { String displayName = context.getTestClass().map( Class::getSimpleName ).orElse( "class" ) + "." + context.getDisplayName(); profiler.printProfile( out, displayName ); } } } catch ( Exception e ) { throw new JUnitException( "Failed to finish profiling and/or produce profiling output.", e ); } } }