Skip to content

Commit

Permalink
refactor fixture interfaces into classes
Browse files Browse the repository at this point in the history
refactor rename ParameterResolverImpl to DefaultParameterResolver
refactor rename TestExecutionListenerImpl to DefaultTestExecutionListener
  • Loading branch information
silkentrance committed Oct 31, 2018
1 parent 7abe5bd commit 5d88368
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 52 deletions.
31 changes: 17 additions & 14 deletions junit-common/src/test/java/eu/coldrye/junit/util/Fixtures.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,53 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

public interface Fixtures {
public class Fixtures {

private Fixtures() {

}

@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@interface Provided {
public @interface Provided {

}

@Provided
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@interface CustomProvided {
public @interface CustomProvided {

}

@Provided
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@interface CustomProvided2 {
public @interface CustomProvided2 {

}

class Custom1 {
@CustomProvided
public interface Iface1 {

}

class Custom2 {
public interface DerivedIface extends Iface1 {

}

@CustomProvided
interface Iface1 {
public static class Custom1 {

}

interface DerivedIface extends Iface1 {
public static class Custom2 {

}

abstract class TestCaseBase {
public static abstract class TestCaseBase {

@CustomProvided
Custom1 custom1;
Expand All @@ -78,12 +82,12 @@ public void setCustom2(@CustomProvided Custom2 custom2) {
}

@Provided
class FirstTestCase implements DerivedIface {
public static class FirstTestCase implements DerivedIface {

}

@CustomProvided
class SecondTestCase extends TestCaseBase {
public static class SecondTestCase extends TestCaseBase {

@Provided
Custom1 custom;
Expand All @@ -94,8 +98,7 @@ public void setCustom1(@CustomProvided Custom1 custom) {
}
}

class ThirdTestCase {
public static class ThirdTestCase {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import java.util.List;

/**
* The final class ParameterResolverImpl models a resolver for parameters.
* The final class DefaultParameterResolver models a resolver for parameters.
* <p>
* It does so by querying available {@link EnvProvider}S.
*
* @since 1.0.0
*/
class ParameterResolverImpl {
class DefaultParameterResolver {

/**
* @param parameterContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import org.junit.platform.launcher.TestPlan;

/**
* The final class TestExecutionListenerImpl provides a means to be able to shut down
* The final class DefaultTestExecutionListener provides a means to be able to shut down
* existing environments after that all tests have been run.
* <p>
* It gets registered via {@code META-INF/services/org.junit.platform.launcher.TestExecutionListener}.
* <p>
* This class is internal and must not be used directly.
* NOTE: This class is internal and must not be used directly.
*
* @since 1.0.0
*/
public final class TestExecutionListenerImpl implements TestExecutionListener {
public final class DefaultTestExecutionListener implements TestExecutionListener {

@Override
public void testPlanExecutionFinished(TestPlan testPlan) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public final class EnvExtension implements TestInstancePostProcessor, ParameterR

private final FieldInjector fieldInjector;

private final ParameterResolverImpl parameterResolver;
private final DefaultParameterResolver parameterResolver;

/**
* Default constructor
*/
//NOSONAR
public EnvExtension() {

this(EnvProviderManager.getInstance(), new FieldInjector(), new ParameterResolverImpl());
this(EnvProviderManager.getInstance(), new FieldInjector(), new DefaultParameterResolver());
}

/**
Expand All @@ -58,7 +58,7 @@ public EnvExtension() {
*/
// For testing only
EnvExtension(EnvProviderManager providerManager, FieldInjector fieldInjector,
ParameterResolverImpl parameterResolver) {
DefaultParameterResolver parameterResolver) {

Preconditions.notNull(providerManager, "providerManager must not be null");
Preconditions.notNull(fieldInjector, "fieldInjector must not be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static synchronized EnvProviderManager getInstance() {
}

/**
* Destroys the instance. Called by {@link TestExecutionListenerImpl#testPlanExecutionFinished(TestPlan)} at the end
* Destroys the instance. Called by {@link DefaultTestExecutionListener#testPlanExecutionFinished(TestPlan)} at the end
* of the test execution.
*/
static void destroyInstance() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
eu.coldrye.junit.env.TestExecutionListenerImpl
eu.coldrye.junit.env.DefaultTestExecutionListener
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
import java.util.Arrays;
import java.util.List;

public class ParameterResolverImplTest {
public class DefaultParameterResolverTest {

private ParameterResolverImpl sut;
private DefaultParameterResolver sut;

private List<EnvProvider> providers;

@BeforeEach
public void setUp() {

sut = new ParameterResolverImpl();
sut = new DefaultParameterResolver();
providers = Arrays.asList(new EnvProvider[]{
new EnvProvider1(), new EnvProvider2()
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

import java.util.Collections;

public class TestExecutionListenerImplTest {
public class DefaultTestExecutionListenerTest {

@Test
public void testPlanExecutionFinishedMustInstructManagerToShutdown() {

EnvProviderManager mockManager = Mockito.mock(EnvProviderManager.class);
EnvProviderManager.INSTANCE.set(mockManager);
TestPlan testPlan = TestPlan.from(Collections.emptyList());
new TestExecutionListenerImpl().testPlanExecutionFinished(testPlan);
new DefaultTestExecutionListener().testPlanExecutionFinished(testPlan);
Mockito.verify(mockManager).shutdown();
Assertions.assertNull(EnvProviderManager.INSTANCE.get());
}
Expand All @@ -41,6 +41,6 @@ public void testPlanExecutionFinishedMustNotFailOnMissingManagerInstance() {

TestPlan testPlan = TestPlan.from(Collections.emptyList());
EnvProviderManager.destroyInstance();
new TestExecutionListenerImpl().testPlanExecutionFinished(testPlan);
new DefaultTestExecutionListener().testPlanExecutionFinished(testPlan);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class EnvExtensionTest {

protected FieldInjector mockInjector;

protected ParameterResolverImpl mockResolver;
protected DefaultParameterResolver mockResolver;

protected ExtensionContext mockContext;

Expand All @@ -46,7 +46,7 @@ public class EnvExtensionTest {
@BeforeEach
public void setUp() {

mockResolver = Mockito.mock(ParameterResolverImpl.class);
mockResolver = Mockito.mock(DefaultParameterResolver.class);
mockInjector = Mockito.mock(FieldInjector.class);
mockManager = Mockito.mock(EnvProviderManager.class);
mockContext = JunitExtensionTestUtils.createExtensionContextMock(FirstTestCase.class, Mockito.mock(Store.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
import java.lang.annotation.Target;
import java.lang.reflect.AnnotatedElement;

public interface Fixtures {
public class Fixtures {

private Fixtures() {

}

@Environment(EnvProvider2.class)
interface AnotherEnvProvidingInterface extends SomethingInBetween {
Expand Down Expand Up @@ -60,20 +64,20 @@ interface EnvProvidingInterface {

}

interface SomethingInBetween extends EnvProvidingInterface {
public interface SomethingInBetween extends EnvProvidingInterface {

}

class EnvProvider1ProvidedBoundaryInterface {
public static class EnvProvider1ProvidedBoundaryInterface {

}

class EnvProvider2ProvidedBoundaryInterface {
public static class EnvProvider2ProvidedBoundaryInterface {

}

@Environment(EnvProvider1.class)
abstract class AbstractTestCaseBase {
public static abstract class AbstractTestCaseBase {

@EnvProvider1Provided
public EnvProvider1ProvidedBoundaryInterface service;
Expand All @@ -92,7 +96,7 @@ public void setService(EnvProvider1ProvidedBoundaryInterface service) {
}
}

abstract class AbstractTestEnvProvider extends AbstractEnvProvider {
public static abstract class AbstractTestEnvProvider extends AbstractEnvProvider {

@Override
public boolean canProvideInstance(AnnotatedElement annotated, Class<?> classOrInterface) {
Expand All @@ -117,7 +121,7 @@ public void tearDownEnvironment(EnvPhase phase, AnnotatedElement annotated) thro
}
}

class EnvProvider1 extends AbstractTestEnvProvider {
public static class EnvProvider1 extends AbstractTestEnvProvider {

@Override
public boolean canProvideInstance(AnnotatedElement annotated, Class<?> classOrInterface) {
Expand All @@ -133,7 +137,7 @@ public Object getOrCreateInstance(AnnotatedElement annotated, Class<?> classOrIn
}
}

class EnvProvider2 extends AbstractTestEnvProvider {
public static class EnvProvider2 extends AbstractTestEnvProvider {

@Override
public boolean canProvideInstance(AnnotatedElement annotated, Class<?> classOrInterface) {
Expand All @@ -149,27 +153,27 @@ public Object getOrCreateInstance(AnnotatedElement annotated, Class<?> classOrIn
}
}

class EnvProvider3 extends AbstractTestEnvProvider {
public static class EnvProvider3 extends AbstractTestEnvProvider {

}

class EnvProvider4 extends AbstractTestEnvProvider {
public static class EnvProvider4 extends AbstractTestEnvProvider {

}

class EnvProvider5 extends AbstractTestEnvProvider {
public static class EnvProvider5 extends AbstractTestEnvProvider {

}

@Environment(EnvProvider3.class)
class FirstTestCase extends AbstractTestCaseBase implements EnvProvidingInterface {
public static class FirstTestCase extends AbstractTestCaseBase implements EnvProvidingInterface {

}

@Environment(EnvProvider2.class)
@Environment(EnvProvider4.class)
@Environment(EnvProvider5.class)
class SecondTestCase extends AbstractTestCaseBase implements AnotherEnvProvidingInterface {
public static class SecondTestCase extends AbstractTestCaseBase implements AnotherEnvProvidingInterface {

@EnvProvider2Provided
public EnvProvider2ProvidedBoundaryInterface service2;
Expand Down Expand Up @@ -205,21 +209,21 @@ public void testing4(@NotEnvProvided Object notEnvProvided) {
}
}

class ThirdTestCase {
public static class ThirdTestCase {

}

@Environment(AbstractTestEnvProvider.class)
class FourthTestCase {
public static class FourthTestCase {

}

@Environment(EnvProvider.class)
class FifthTestCase {
public static class FifthTestCase {

}

class SimpleEnvProvider extends AbstractEnvProvider {
public static class SimpleEnvProvider extends AbstractEnvProvider {

@Override
public boolean canProvideInstance(AnnotatedElement annotated, Class<?> classOrInterface) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

public interface Fixtures {
public class Fixtures {

private Fixtures() {

}

@Configuration
@ComponentScan("eu.coldrye.junit.env")
class TestConfig {
public static class TestConfig {

}

@Component
class SimpleComponent {}
public static class SimpleComponent {

}
}

0 comments on commit 5d88368

Please sign in to comment.