Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit f2fcd58

Browse files
committed
Managed to get everything to build and tests passing with only JUnit5 in place.
1 parent 7585af0 commit f2fcd58

84 files changed

Lines changed: 387 additions & 359 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

buildSrc/src/main/groovy/org/apache/polygene/gradle/code/CodePlugin.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class CodePlugin implements Plugin<Project>
8282
}
8383
}
8484
}
85+
def junitEngine = declaration.libraries.get("junit_engine")
86+
project.dependencies.add "testRuntime", junitEngine
8587
}
8688

8789
private static void configureTest( Project project )
@@ -104,6 +106,7 @@ class CodePlugin implements Plugin<Project>
104106
def workDir = new File( testDir, 'work' )
105107
def tmpDir = new File( testDir, 'tmp' )
106108
def homeDir = new File( testDir, 'home' )
109+
testTask.useJUnitPlatform()
107110
testTask.workingDir = workDir
108111
testTask.systemProperties << ( [
109112
'user.dir' : workDir.absolutePath,

core/bootstrap/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ dependencies {
2626
api polygene.core.spi
2727

2828
testRuntimeOnly polygene.core.runtime
29+
30+
testRuntime libraries.kotlin
2931
}

core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ClassScanner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static Stream<? extends Class<?>> findClasses( final Class<?> seedClass )
100100
{
101101
return seedClass.getClassLoader().loadClass( name );
102102
}
103-
catch( ClassNotFoundException e )
103+
catch( ClassNotFoundException | NoClassDefFoundError e )
104104
{
105105
return null;
106106
}
@@ -175,7 +175,7 @@ private static class ValidClass
175175
@Override
176176
public boolean test( Class<?> item )
177177
{
178-
return ( item.isInterface() || !Modifier.isAbstract( item.getModifiers() ) )
178+
return item != null && ( item.isInterface() || !Modifier.isAbstract( item.getModifiers() ) )
179179
&& ( !item.isEnum() && !item.isAnonymousClass() );
180180
}
181181
}

core/bootstrap/src/test/java/org/apache/polygene/bootstrap/ClassScannerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ public void testClassScannerFiles()
5252
@Test
5353
public void testClassScannerJar()
5454
{
55-
assertThat( findClasses( Test.class ).count(), equalTo( 185 ) );
55+
assertThat( findClasses( Test.class ).count(), equalTo( 89L ) );
5656
}
5757
}

core/runtime/src/test/java/org/apache/polygene/runtime/entity/associations/ImmutableAssociationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void givenEntityWithImmutableAssociationWhenBuildingThenNoException()
7373
public void givenEntityWithImmutableAssociationWhenChangingValueThenThrowException()
7474
throws Exception
7575
{
76-
assertThrows( ConstraintViolationException.class, () -> {
76+
assertThrows( IllegalStateException.class, () -> {
7777
UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork();
7878
try
7979
{

core/runtime/src/test/java/org/apache/polygene/runtime/mixin/InitializableTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import org.apache.polygene.bootstrap.ModuleAssembly;
2828
import org.apache.polygene.test.AbstractPolygeneTest;
2929
import org.apache.polygene.test.EntityTestAssembler;
30-
import org.apache.polygene.test.util.NotYetImplemented;
3130
import org.junit.jupiter.api.BeforeEach;
31+
import org.junit.jupiter.api.Disabled;
3232
import org.junit.jupiter.api.Test;
3333

3434
import static org.hamcrest.CoreMatchers.equalTo;
@@ -87,12 +87,13 @@ public void givenObjectImplementingInitializableWhenInstantiatedThenInvokeInitia
8787
assertThat( "object has been initialized", instance.ok(), equalTo( true ) );
8888
}
8989

90-
@NotYetImplemented( reason = "Mixin of types with no method are not scrutinized for Initializable implementation" )
90+
// TODO: (niclas) This is part of the whole lifecycle mess, that needs to be worked out once and for all.
91+
@Disabled( "Mixin of types with no method are not scrutinized for Initializable implementation" )
9192
@Test
9293
public void givenTypeWithNoMethodsAndInitializableMixinWhenInstantiatedThenInvokeInitialize()
9394
{
9495
NoMethod instance = transientBuilderFactory.newTransient( NoMethod.class );
95-
assertThat( "mixin has been initialized", noMethodMixinOk, equalTo( true ) );
96+
assertThat( "mixin has not been initialized", noMethodMixinOk, equalTo( true ) );
9697
}
9798

9899
@Mixins( TestMixin.class )

core/runtime/src/test/java/org/apache/polygene/runtime/query/QueryBuilderFactoryImplTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void givenPlainQueryWhenFindEntityExpectFirstEntityReturned()
7575
{
7676
Query<TestComposite> query = queryBuilderFactory.newQueryBuilder( TestComposite.class ).newQuery( composites );
7777
assertThat( query.find().a().get(), equalTo( "A" ) );
78-
assertThat( query.count(), equalTo( 6 ) );
78+
assertThat( query.count(), equalTo( 6L ) );
7979
}
8080

8181
@Test
@@ -137,13 +137,13 @@ public void givenWhereQueryWhenWhereClauseLimitsToRangeExpectLimitedResult()
137137

138138
private void verifyOrder( Query<TestComposite> query, String expected )
139139
{
140-
String actual = "";
140+
StringBuilder actual = new StringBuilder();
141141
for( TestComposite testComposite : query )
142142
{
143-
actual = actual + testComposite.b().get();
143+
actual.append( testComposite.b().get() );
144144
}
145145

146-
assertThat( "Query is correct", actual, equalTo( expected ) );
146+
assertThat( "Query is correct", actual.toString(), equalTo( expected ) );
147147
assertThat( "Count is correct", query.count(), equalTo( (long) expected.length() ) );
148148
}
149149

core/runtime/src/test/java/org/apache/polygene/runtime/structure/TypeToCompositeLookupTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ public void assemble( ModuleAssembly module )
372372

373373
}.module();
374374

375-
assertThat( module.findServices( SomeOtherFoo.class ).count(), equalTo( 1 ) );
376-
assertThat( module.findServices( BasicFoo.class ).count(), equalTo( 2 ) );
377-
assertThat( module.findServices( Foo.class ).count(), equalTo( 2 ) );
375+
assertThat( module.findServices( SomeOtherFoo.class ).count(), equalTo( 1L ) );
376+
assertThat( module.findServices( BasicFoo.class ).count(), equalTo( 2L ) );
377+
assertThat( module.findServices( Foo.class ).count(), equalTo( 2L ) );
378378

379379
assertThat( module.findService( SomeOtherFoo.class ).get().bar(), equalTo( CATHEDRAL ) );
380380

core/testsupport/src/main/java/org/apache/polygene/test/AbstractPolygeneBaseTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
public abstract class AbstractPolygeneBaseTest
3434
{
35-
// @Rule public NotYetImplemented.Rule notYetImplementedRule = new NotYetImplemented.Rule();
36-
3735
protected PolygeneAPI api;
3836
protected PolygeneSPI spi;
3937

core/testsupport/src/main/java/org/apache/polygene/test/PolygeneUnitExtension.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
*/
2020
package org.apache.polygene.test;
2121

22+
import java.lang.reflect.Field;
23+
import java.lang.reflect.Modifier;
24+
import java.lang.reflect.UndeclaredThrowableException;
25+
import java.util.Optional;
2226
import org.apache.polygene.api.structure.Application;
2327
import org.apache.polygene.bootstrap.Assembler;
2428
import org.apache.polygene.bootstrap.ModuleAssembly;
@@ -49,6 +53,30 @@ private PolygeneUnitExtension( Assembler assembler )
4953
this.assembler = assembler;
5054
}
5155

56+
static void setField( Field f, Object injectable, ExtensionContext context )
57+
{
58+
try
59+
{
60+
f.setAccessible( true );
61+
Optional<Object> possibleInstance = context.getTestInstance();
62+
if( possibleInstance.isPresent() )
63+
{
64+
f.set( possibleInstance.get(), injectable );
65+
}
66+
else
67+
{
68+
if( Modifier.isStatic( f.getModifiers() ) )
69+
{
70+
f.set( null, injectable );
71+
}
72+
}
73+
}
74+
catch( IllegalAccessException e )
75+
{
76+
throw new UndeclaredThrowableException( e );
77+
}
78+
}
79+
5280
@Override
5381
public void beforeTestExecution( ExtensionContext context )
5482
throws Exception

0 commit comments

Comments
 (0)