Skip to content

Commit

Permalink
Upgrade neo4j-logging tests to junit 5.
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Jun 19, 2018
1 parent e1b8c82 commit 4153672
Show file tree
Hide file tree
Showing 11 changed files with 307 additions and 197 deletions.
Expand Up @@ -19,28 +19,12 @@
*/
package org.neo4j.test.extension;

import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;

import org.neo4j.io.fs.DefaultFileSystemAbstraction;

public class DefaultFileSystemExtension extends StatefullFieldExtension<DefaultFileSystemAbstraction> implements AfterEachCallback
public class DefaultFileSystemExtension extends FileSystemExtension<DefaultFileSystemAbstraction>
{
static final String FILE_SYSTEM = "fileSystem";
static final Namespace FILE_SYSTEM_NAMESPACE = Namespace.create( FILE_SYSTEM );

@Override
public void afterEach( ExtensionContext context ) throws Exception
{
getStoredValue( context ).close();
}

@Override
protected String getFieldKey()
{
return FILE_SYSTEM;
}

@Override
protected Class<DefaultFileSystemAbstraction> getFieldType()
Expand All @@ -53,10 +37,4 @@ protected DefaultFileSystemAbstraction createField( ExtensionContext extensionCo
{
return new DefaultFileSystemAbstraction();
}

@Override
protected Namespace getNameSpace()
{
return FILE_SYSTEM_NAMESPACE;
}
}
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.test.extension;

import org.junit.jupiter.api.extension.ExtensionContext;

import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction;

public class EphemeralFileSystemExtension extends FileSystemExtension<EphemeralFileSystemAbstraction>
{
@Override
protected Class<EphemeralFileSystemAbstraction> getFieldType()
{
return EphemeralFileSystemAbstraction.class;
}

@Override
protected EphemeralFileSystemAbstraction createField( ExtensionContext extensionContext )
{
return new EphemeralFileSystemAbstraction();
}
}
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.test.extension;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;

@ExtendWith( EphemeralFileSystemExtension.class )
class EphemeralFileSystemExtensionTest
{
@Inject
EphemeralFileSystemAbstraction rootFileSystem;

@Test
void fileSystemInjectionCreateFileSystem()
{
assertNotNull( rootFileSystem );
}

@Nested
class NestedFileSystemTest
{
@Inject
EphemeralFileSystemAbstraction nestedFileSystem;

@Test
void nestedFileSystemInjection()
{
assertNotNull( nestedFileSystem );
}

@Test
void rootFileSystemAvailable()
{
assertNotNull( rootFileSystem );
}

@Test
void nestedAndRootFileSystemsAreTheSame()
{
assertSame( nestedFileSystem, rootFileSystem );
}
}
}
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.test.extension;

import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;

import org.neo4j.io.fs.FileSystemAbstraction;

abstract class FileSystemExtension<T extends FileSystemAbstraction> extends StatefullFieldExtension<T> implements AfterEachCallback
{
static final String FILE_SYSTEM = "fileSystem";
static final Namespace FILE_SYSTEM_NAMESPACE = Namespace.create( FILE_SYSTEM );

@Override
public void afterEach( ExtensionContext context ) throws Exception
{
getStoredValue( context ).close();
}

@Override
protected String getFieldKey()
{
return FILE_SYSTEM;
}

@Override
protected Namespace getNameSpace()
{
return FILE_SYSTEM_NAMESPACE;
}
}
4 changes: 4 additions & 0 deletions community/logging/pom.xml
Expand Up @@ -89,6 +89,10 @@ the relevant Commercial Agreement.
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-logger-api</artifactId>
Expand Down
Expand Up @@ -19,16 +19,16 @@
*/
package org.neo4j.logging;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class DuplicatingLogProviderTest
class DuplicatingLogProviderTest
{
@Test
public void shouldReturnSameLoggerForSameClass()
void shouldReturnSameLoggerForSameClass()
{
// Given
DuplicatingLogProvider logProvider = new DuplicatingLogProvider();
Expand All @@ -39,7 +39,7 @@ public void shouldReturnSameLoggerForSameClass()
}

@Test
public void shouldReturnSameLoggerForSameContext()
void shouldReturnSameLoggerForSameContext()
{
// Given
DuplicatingLogProvider logProvider = new DuplicatingLogProvider();
Expand All @@ -50,7 +50,7 @@ public void shouldReturnSameLoggerForSameContext()
}

@Test
public void shouldRemoveLogProviderFromDuplication()
void shouldRemoveLogProviderFromDuplication()
{
// Given
AssertableLogProvider logProvider1 = new AssertableLogProvider();
Expand All @@ -61,7 +61,7 @@ public void shouldRemoveLogProviderFromDuplication()
// When
Log log = logProvider.getLog( getClass() );
log.info( "When the going gets weird" );
assertThat( logProvider.remove( logProvider1 ), is( true ) );
assertTrue( logProvider.remove( logProvider1 ) );
log.info( "The weird turn pro" );

// Then
Expand Down
Expand Up @@ -19,12 +19,12 @@
*/
package org.neo4j.logging;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class DuplicatingLogTest
class DuplicatingLogTest
{
@Test
public void shouldOutputToMultipleLogs()
void shouldOutputToMultipleLogs()
{
// Given
AssertableLogProvider logProvider = new AssertableLogProvider();
Expand All @@ -44,7 +44,7 @@ public void shouldOutputToMultipleLogs()
}

@Test
public void shouldBulkOutputToMultipleLogs()
void shouldBulkOutputToMultipleLogs()
{
// Given
AssertableLogProvider logProvider = new AssertableLogProvider();
Expand All @@ -64,7 +64,7 @@ public void shouldBulkOutputToMultipleLogs()
}

@Test
public void shouldRemoveLogFromDuplication()
void shouldRemoveLogFromDuplication()
{
// Given
AssertableLogProvider logProvider = new AssertableLogProvider();
Expand All @@ -87,7 +87,7 @@ public void shouldRemoveLogFromDuplication()
}

@Test
public void shouldRemoveLoggersFromDuplication()
void shouldRemoveLoggersFromDuplication()
{
// Given
AssertableLogProvider logProvider = new AssertableLogProvider();
Expand Down
Expand Up @@ -19,6 +19,8 @@
*/
package org.neo4j.logging;

import org.junit.jupiter.api.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
Expand All @@ -27,21 +29,18 @@
import java.util.Date;
import java.util.Map;

import org.junit.Test;

import org.neo4j.function.Suppliers;

import static java.lang.String.format;

import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

public class FormattedLogProviderTest
class FormattedLogProviderTest
{
@Test
public void shouldReturnSameLoggerForSameClass()
void shouldReturnSameLoggerForSameClass()
{
// Given
FormattedLogProvider logProvider = FormattedLogProvider.toOutputStream( new ByteArrayOutputStream() );
Expand All @@ -52,7 +51,7 @@ public void shouldReturnSameLoggerForSameClass()
}

@Test
public void shouldReturnSameLoggerForSameContext()
void shouldReturnSameLoggerForSameContext()
{
// Given
FormattedLogProvider logProvider = FormattedLogProvider.toOutputStream( new ByteArrayOutputStream() );
Expand All @@ -63,7 +62,7 @@ public void shouldReturnSameLoggerForSameContext()
}

@Test
public void shouldLogWithAbbreviatedClassNameAsContext()
void shouldLogWithAbbreviatedClassNameAsContext()
{
// Given
StringWriter writer = new StringWriter();
Expand All @@ -78,7 +77,7 @@ public void shouldLogWithAbbreviatedClassNameAsContext()
}

@Test
public void shouldSetLevelForLogWithMatchingContext()
void shouldSetLevelForLogWithMatchingContext()
{
// Given
StringWriter writer = new StringWriter();
Expand All @@ -98,7 +97,7 @@ public void shouldSetLevelForLogWithMatchingContext()
}

@Test
public void shouldSetLevelForLogWithPartiallyMatchingContext()
void shouldSetLevelForLogWithPartiallyMatchingContext()
{
// Given
StringWriter writer = new StringWriter();
Expand Down

0 comments on commit 4153672

Please sign in to comment.