Skip to content

Commit f8b68d8

Browse files
gscheibeldariuszkuc
authored andcommitted
Reconfigure surefire plugin to be sure that all the unit tests are executed properly (#70)
1 parent bf4452d commit f8b68d8

File tree

5 files changed

+77
-25
lines changed

5 files changed

+77
-25
lines changed

pom.xml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@
7474
<kotlin.version>1.2.71</kotlin.version>
7575
<kotlin-ktlint.version>0.29.0</kotlin-ktlint.version>
7676
<kotlin-detekt.version>1.0.0.RC8</kotlin-detekt.version>
77-
<junit.version>4.12</junit.version>
7877
<mockk.version>1.8.9.kotlin13</mockk.version>
78+
<surefire-plugin.version>2.22.1</surefire-plugin.version>
79+
<junit-jupiter.version>5.3.1</junit-jupiter.version>
7980
</properties>
8081

8182
<pluginRepositories>
@@ -124,6 +125,37 @@
124125
</execution>
125126
</executions>
126127
</plugin>
128+
<plugin>
129+
<groupId>org.apache.maven.plugins</groupId>
130+
<artifactId>maven-surefire-plugin</artifactId>
131+
<version>${surefire-plugin.version}</version>
132+
<configuration>
133+
<failIfNoTests>true</failIfNoTests>
134+
<includes>
135+
<include>**/*Test.java</include>
136+
<include>**/*Test.kt</include>
137+
<include>**/*Tests.java</include>
138+
<include>**/*Tests.kt</include>
139+
</includes>
140+
<properties>
141+
<excludeTags>integration-test</excludeTags>
142+
</properties>
143+
</configuration>
144+
<dependencies>
145+
<dependency>
146+
<groupId>org.junit.jupiter</groupId>
147+
<artifactId>junit-jupiter-api</artifactId>
148+
<version>${junit-jupiter.version}</version>
149+
<scope>runtime</scope>
150+
</dependency>
151+
<dependency>
152+
<groupId>org.junit.jupiter</groupId>
153+
<artifactId>junit-jupiter-engine</artifactId>
154+
<version>${junit-jupiter.version}</version>
155+
<scope>runtime</scope>
156+
</dependency>
157+
</dependencies>
158+
</plugin>
127159
<plugin>
128160
<groupId>org.apache.maven.plugins</groupId>
129161
<artifactId>maven-antrun-plugin</artifactId>
@@ -245,6 +277,18 @@
245277
<version>2.1.0</version>
246278
<scope>test</scope>
247279
</dependency>
280+
<dependency>
281+
<groupId>org.junit.jupiter</groupId>
282+
<artifactId>junit-jupiter-api</artifactId>
283+
<version>${junit-jupiter.version}</version>
284+
<scope>test</scope>
285+
</dependency>
286+
<dependency>
287+
<groupId>org.junit.jupiter</groupId>
288+
<artifactId>junit-jupiter-engine</artifactId>
289+
<version>${junit-jupiter.version}</version>
290+
<scope>test</scope>
291+
</dependency>
248292
</dependencies>
249293

250294
<profiles>

src/main/kotlin/com/expedia/graphql/schema/extensions/annotationExtensions.kt

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import kotlin.reflect.full.findAnnotation
1515
import com.expedia.graphql.annotations.GraphQLDirective as DirectiveAnnotation
1616

1717
internal fun KAnnotatedElement.graphQLDescription(): String? {
18-
val directiveNames = listOfDirectives().map { normalizeDirectiveName(it) }
18+
val directiveNames = listOfDirectives().map { it.normalizeDirectiveName() }
1919

2020
val description = this.findAnnotation<GraphQLDescription>()?.value
2121

@@ -36,13 +36,8 @@ private fun KAnnotatedElement.listOfDirectives(): List<String> {
3636

3737
return this.annotations.asSequence()
3838
.mapNotNull { it.getDirectiveInfo() }
39-
.map {
40-
val directiveName = it.getDirectiveInfo()?.name
41-
val simpleName = it.annotationClass.simpleName
42-
43-
when {
44-
directiveName.isNullOrEmpty().not() -> "@$directiveName"
45-
simpleName.isNullOrEmpty().not() -> "@$simpleName"
39+
.map { when {
40+
it.effectiveName != null -> "@${it.effectiveName}"
4641
else -> null
4742
}
4843
}
@@ -66,8 +61,13 @@ internal fun KAnnotatedElement.isGraphQLIgnored() = this.findAnnotation<GraphQLI
6661

6762
internal fun KAnnotatedElement.isGraphQLID() = this.findAnnotation<GraphQLID>() != null
6863

69-
internal fun Annotation.getDirectiveInfo(): DirectiveAnnotation? =
70-
this.annotationClass.annotations.find { it is DirectiveAnnotation } as? DirectiveAnnotation
64+
private fun Annotation.getDirectiveInfo(): DirectiveInfo? {
65+
val directiveAnnotation = this.annotationClass.annotations.find { it is DirectiveAnnotation } as? DirectiveAnnotation
66+
return when {
67+
directiveAnnotation != null -> DirectiveInfo(this.annotationClass.simpleName ?: "", directiveAnnotation)
68+
else -> null
69+
}
70+
}
7171

7272
internal fun KAnnotatedElement.directives() =
7373
this.annotations.asSequence()
@@ -76,19 +76,16 @@ internal fun KAnnotatedElement.directives() =
7676
.toList()
7777

7878
@Throws(CouldNotGetNameOfAnnotationException::class)
79-
private fun DirectiveAnnotation.getGraphQLDirective(): GraphQLDirective {
80-
val kClass: KClass<out DirectiveAnnotation> = this.annotationClass
79+
private fun DirectiveInfo.getGraphQLDirective(): GraphQLDirective {
80+
val kClass: KClass<out DirectiveAnnotation> = this.annotation.annotationClass
8181
val builder = GraphQLDirective.newDirective()
82-
val name: String = if (this.name.isNotEmpty()) {
83-
this.name
84-
} else {
85-
kClass.simpleName ?: throw CouldNotGetNameOfAnnotationException(kClass)
86-
}
82+
val name: String = this.effectiveName ?: throw CouldNotGetNameOfAnnotationException(kClass)
8783

8884
@Suppress("Detekt.SpreadOperator")
89-
builder.name(normalizeDirectiveName(name))
90-
.validLocations(*this.locations)
91-
.description(this.description)
85+
86+
builder.name(name.normalizeDirectiveName())
87+
.validLocations(*this.annotation.locations)
88+
.description(this.annotation.description)
9289

9390
kClass.getValidFunctions().forEach { kFunction ->
9491
val propertyName = kFunction.name
@@ -106,4 +103,12 @@ private fun DirectiveAnnotation.getGraphQLDirective(): GraphQLDirective {
106103
return builder.build()
107104
}
108105

109-
private fun normalizeDirectiveName(string: String) = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, string)
106+
private fun String.normalizeDirectiveName() = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, this)
107+
108+
private data class DirectiveInfo(private val name: String, val annotation: DirectiveAnnotation) {
109+
val effectiveName: String? = when {
110+
annotation.name.isNotEmpty() -> annotation.name
111+
name.isNotEmpty() -> name
112+
else -> null
113+
}
114+
}

src/test/kotlin/com/expedia/graphql/schema/generator/DirectiveTests.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ class DirectiveTests {
7070
assertNotNull(schema.getDirective("renamedDirective"))
7171
val directiveOnFunction = schema.getDirective("directiveOnFunction")
7272
assertNotNull(directiveOnFunction)
73-
assertEquals(directiveOnFunction.validLocations()?.toSet(), setOf(Introspection.DirectiveLocation.FIELD_DEFINITION, Introspection.DirectiveLocation.FIELD))
73+
assertEquals(
74+
directiveOnFunction.validLocations()?.toSet(),
75+
setOf(Introspection.DirectiveLocation.FIELD_DEFINITION, Introspection.DirectiveLocation.FIELD)
76+
)
7477
}
7578
}
7679

src/test/kotlin/com/expedia/graphql/schema/generator/SchemaGeneratorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class SchemaGeneratorTest {
269269

270270
@Test
271271
fun `SchemaGenerator supports Scalar GraphQLID for input types`() {
272-
val schema = toSchema(queries = emptyList(), mutations = listOf(TopLevelObjectDef(MutationWithId())), config = testSchemaConfig)
272+
val schema = toSchema(queries = listOf(TopLevelObjectDef(QueryObject())), mutations = listOf(TopLevelObjectDef(MutationWithId())), config = testSchemaConfig)
273273

274274
val furnitureType = schema.getObjectType("Furniture")
275275
val serialField = furnitureType.getFieldDefinition("serial").type as? GraphQLNonNull

src/test/kotlin/com/expedia/graphql/schema/hooks/SchemaGeneratorHooksTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class SchemaGeneratorHooksTest {
198198

199199
val hooks = MockSchemaGeneratorHooks()
200200
val schema = toSchema(
201-
queries = emptyList(),
201+
queries = listOf(TopLevelObjectDef(TestQuery())),
202202
mutations = listOf(TopLevelObjectDef(TestQuery())),
203203
config = getTestSchemaConfigWithHooks(hooks)
204204
)

0 commit comments

Comments
 (0)