Skip to content

Commit

Permalink
Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Oct 12, 2018
1 parent de47415 commit 42166dc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
Expand Up @@ -27,8 +27,8 @@
import org.neo4j.test.rule.TestDirectory;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.neo4j.test.extension.ExecutionSharedContext.CONTEXT;
import static org.neo4j.test.extension.ExecutionSharedContext.FAILED_TEST_FILE_KEY;
import static org.neo4j.test.extension.ExecutionSharedContext.INSTANCE;
import static org.neo4j.test.extension.ExecutionSharedContext.SUCCESSFUL_TEST_FILE_KEY;

/**
Expand All @@ -39,21 +39,21 @@
class DirectoryExtensionLifecycleVerification
{
@Inject
TestDirectory directory;
private TestDirectory directory;

@Test
void executeAndCleanupDirectory()
{
File file = directory.createFile( "a" );
assertTrue( file.exists() );
INSTANCE.setValue( SUCCESSFUL_TEST_FILE_KEY, file );
CONTEXT.setValue( SUCCESSFUL_TEST_FILE_KEY, file );
}

@Test
void failAndKeepDirectory()
{
File file = directory.createFile( "b" );
INSTANCE.setValue( FAILED_TEST_FILE_KEY, file );
CONTEXT.setValue( FAILED_TEST_FILE_KEY, file );
throw new RuntimeException( "simulate test failure" );
}
}
Expand Up @@ -23,16 +23,21 @@

public class ExecutionSharedContext
{
public static final String FAILED_TEST_FILE_KEY = "failedFileName";
public static final String SUCCESSFUL_TEST_FILE_KEY = "successfulFileName";
private static final ConcurrentHashMap<String,Object> context = new ConcurrentHashMap();
static final String FAILED_TEST_FILE_KEY = "failedFileName";
static final String SUCCESSFUL_TEST_FILE_KEY = "successfulFileName";
private static final ConcurrentHashMap<String,Object> context = new ConcurrentHashMap<>();

public static final ExecutionSharedContext INSTANCE = new ExecutionSharedContext();
public static final ExecutionSharedContext CONTEXT = new ExecutionSharedContext();

private ExecutionSharedContext()
{
}

public void clear()
{
context.clear();
}

public <T> T getValue( String key )
{
return (T) context.get( key );
Expand Down
Expand Up @@ -36,12 +36,11 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod;
import static org.neo4j.test.extension.ExecutionSharedContext.CONTEXT;
import static org.neo4j.test.extension.ExecutionSharedContext.FAILED_TEST_FILE_KEY;
import static org.neo4j.test.extension.ExecutionSharedContext.INSTANCE;
import static org.neo4j.test.extension.ExecutionSharedContext.SUCCESSFUL_TEST_FILE_KEY;

@ExtendWith( {DefaultFileSystemExtension.class, TestDirectoryExtension.class} )
Expand Down Expand Up @@ -85,27 +84,27 @@ void createTestFile()
@Test
void failedTestShouldKeepDirectory()
{
assertNull( INSTANCE.getValue( FAILED_TEST_FILE_KEY ) );
CONTEXT.clear();
execute( "failAndKeepDirectory" );
File failedFile = INSTANCE.getValue( FAILED_TEST_FILE_KEY );
File failedFile = CONTEXT.getValue( FAILED_TEST_FILE_KEY );
assertNotNull( failedFile );
assertTrue( failedFile.exists() );
}

@Test
void successfulTestShouldCleanupDirectory()
{
assertNull( INSTANCE.getValue( SUCCESSFUL_TEST_FILE_KEY ) );
CONTEXT.clear();
execute( "executeAndCleanupDirectory" );
File greenTestFail = INSTANCE.getValue( SUCCESSFUL_TEST_FILE_KEY );
File greenTestFail = CONTEXT.getValue( SUCCESSFUL_TEST_FILE_KEY );
assertNotNull( greenTestFail );
assertFalse( greenTestFail.exists() );
}

private static void execute( String failAndKeepDirectory )
private static void execute( String testName )
{
LauncherDiscoveryRequest discoveryRequest = LauncherDiscoveryRequestBuilder.request().selectors(
selectMethod( DirectoryExtensionLifecycleVerification.class, failAndKeepDirectory ) ).build();
selectMethod( DirectoryExtensionLifecycleVerification.class, testName ) ).build();
Launcher launcher = LauncherFactory.create();
launcher.execute( discoveryRequest );
}
Expand Down

0 comments on commit 42166dc

Please sign in to comment.