Skip to content

Commit c81907d

Browse files
author
Vitor Hugo Salgado
committed
refactor: move annotation presence check to core
1 parent 809a590 commit c81907d

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

puma4j-core/src/main/java/io/github/vitorsalgado/puma4j/core/Puma4j.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
88
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
99
import com.google.gson.Gson;
10+
import io.github.vitorsalgado.puma4j.annotations.Res;
1011
import io.github.vitorsalgado.puma4j.core.unmarshallers.BinaryUnmarshaller;
1112
import io.github.vitorsalgado.puma4j.core.unmarshallers.JsonUnmarshaller;
1213
import io.github.vitorsalgado.puma4j.core.unmarshallers.PropertiesUnmarshaller;
1314
import io.github.vitorsalgado.puma4j.core.unmarshallers.TextUnmarshaller;
1415
import io.github.vitorsalgado.puma4j.core.unmarshallers.YamlUnmarshaller;
16+
import java.lang.reflect.AnnotatedElement;
1517
import java.util.Arrays;
1618
import java.util.Optional;
1719

@@ -62,6 +64,10 @@ public static Puma4j instance() {
6264
return Puma4jSingleton.INSTANCE;
6365
}
6466

67+
public static boolean isResourceAnnotationPresent(final AnnotatedElement annotatedElement) {
68+
return annotatedElement.isAnnotationPresent(Res.class);
69+
}
70+
6571
public Provider resourceProvider() {
6672
return new DefaultResourceProvider();
6773
}
@@ -71,27 +77,28 @@ public void registerMarshallerForExtension(
7177
READER_REGISTRY.registerMarshallerForExtension(extension, unmarshaller);
7278
}
7379

80+
@SuppressWarnings("squid:S1452")
7481
public Optional<Unmarshaller<?>> getMarshallerByExtension(final String extension) {
7582
return READER_REGISTRY.getMarshallerByExtension(extension);
7683
}
7784

78-
public Unmarshaller<?> jsonMarshaller() {
85+
public JsonUnmarshaller jsonMarshaller() {
7986
return this.jsonMarshaller;
8087
}
8188

82-
public Unmarshaller<?> yamlMarshaller() {
89+
public YamlUnmarshaller yamlMarshaller() {
8390
return this.yamlMarshaller;
8491
}
8592

86-
public Unmarshaller<?> propertiesMarshaller() {
93+
public PropertiesUnmarshaller propertiesMarshaller() {
8794
return this.propertiesMarshaller;
8895
}
8996

90-
public Unmarshaller<?> textMarshaller() {
97+
public TextUnmarshaller textMarshaller() {
9198
return this.textMarshaller;
9299
}
93100

94-
public Unmarshaller<?> binaryMarshaller() {
101+
public BinaryUnmarshaller binaryMarshaller() {
95102
return this.binaryMarshaller;
96103
}
97104

puma4j-junit5-extension/src/main/java/io/github/vitorsalgado/puma4j/junit5/Puma4jBeforeAllCallback.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.vitorsalgado.puma4j.junit5;
22

3+
import static io.github.vitorsalgado.puma4j.core.Puma4j.isResourceAnnotationPresent;
4+
35
import io.github.vitorsalgado.puma4j.annotations.Res;
46
import io.github.vitorsalgado.puma4j.core.Context;
57
import io.github.vitorsalgado.puma4j.core.Provider;
@@ -23,7 +25,7 @@ public void beforeAll(final ExtensionContext extensionContext) throws Exception
2325

2426
for (final Field field : extensionContext.getRequiredTestClass().getDeclaredFields()) {
2527
if (Modifier.isStatic(field.getModifiers())
26-
&& field.isAnnotationPresent(Res.class)
28+
&& isResourceAnnotationPresent(field)
2729
&& !Modifier.isFinal(field.getModifiers())
2830
&& !field.isEnumConstant()
2931
&& !field.isSynthetic()) {

puma4j-junit5-extension/src/main/java/io/github/vitorsalgado/puma4j/junit5/Puma4jBeforeEachCallback.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.vitorsalgado.puma4j.junit5;
22

3+
import static io.github.vitorsalgado.puma4j.core.Puma4j.isResourceAnnotationPresent;
4+
35
import io.github.vitorsalgado.puma4j.annotations.Res;
46
import io.github.vitorsalgado.puma4j.core.Context;
57
import io.github.vitorsalgado.puma4j.core.Provider;
@@ -23,7 +25,7 @@ public void beforeEach(final ExtensionContext extensionContext) throws Exception
2325

2426
for (final Field field : extensionContext.getRequiredTestClass().getDeclaredFields()) {
2527
if (!Modifier.isStatic(field.getModifiers())
26-
&& field.isAnnotationPresent(Res.class)
28+
&& isResourceAnnotationPresent(field)
2729
&& !Modifier.isFinal(field.getModifiers())
2830
&& !field.isEnumConstant()
2931
&& !field.isSynthetic()) {

puma4j-junit5-extension/src/main/java/io/github/vitorsalgado/puma4j/junit5/Puma4jResourceParameterResolver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.vitorsalgado.puma4j.junit5;
22

3+
import static io.github.vitorsalgado.puma4j.core.Puma4j.isResourceAnnotationPresent;
4+
35
import io.github.vitorsalgado.puma4j.annotations.Res;
46
import io.github.vitorsalgado.puma4j.core.Context;
57
import io.github.vitorsalgado.puma4j.core.Provider;
@@ -18,7 +20,7 @@ public class Puma4jResourceParameterResolver implements ParameterResolver {
1820
@Override
1921
public boolean supportsParameter(
2022
final ParameterContext parameterContext, final ExtensionContext extensionContext) {
21-
return parameterContext.getParameter().isAnnotationPresent(Res.class);
23+
return isResourceAnnotationPresent(parameterContext.getParameter());
2224
}
2325

2426
@Override

0 commit comments

Comments
 (0)