-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
105 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
core/deployment/src/test/java/io/quarkus/deployment/CapabilityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.quarkus.deployment; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Modifier; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
public class CapabilityTest { | ||
private static final String CAPABILITY_ILLEGAL_START = "Capability %s (%s) must start with '%s'."; | ||
private static final String CAPABILITY_DOUBLE_DOT = "Capability %s (%s) contains subsequent dots."; | ||
|
||
private static Stream<Arguments> capabilityFields() { | ||
Field[] declaredFields = Capability.class.getDeclaredFields(); | ||
return Stream.of(declaredFields) | ||
.filter(field -> Modifier.isStatic(field.getModifiers())) | ||
.filter(field -> field.getType().equals(String.class)) | ||
.filter(field -> !getString(field).equals(Capability.QUARKUS_PREFIX)) | ||
.map(field -> Arguments.of(field)); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("capabilityFields") | ||
void validateCapabilityString(Field field) { | ||
if (Modifier.isStatic(field.getModifiers()) && field.getType().equals(String.class)) { | ||
String value = getString(field); | ||
if (!value.startsWith(Capability.QUARKUS_PREFIX + ".")) { | ||
var failMessage = String.format(CAPABILITY_ILLEGAL_START, field.getName(), | ||
value, Capability.QUARKUS_PREFIX); | ||
fail(failMessage); | ||
} | ||
if (value.contains("..")) { | ||
var failMessage = String.format(CAPABILITY_DOUBLE_DOT, field.getName(), | ||
value); | ||
fail(failMessage); | ||
} | ||
} | ||
} | ||
|
||
private static String getString(Field field) { | ||
try { | ||
return (String) field.get(null); | ||
} catch (IllegalArgumentException | IllegalAccessException e) { | ||
fail(e); | ||
return ""; | ||
} | ||
} | ||
} |