@@ -18,15 +18,11 @@ class DefaultResourceProvider implements Provider {
18
18
public Object provide (final Args args ) {
19
19
requireNonNull (args );
20
20
21
- final String resourceName = args
22
- .getResourceFilename ()
23
- .orElse ("" );
21
+ final String resourceName = args .getResourceFilename ().orElse ("" );
24
22
final String filename ;
25
23
26
24
if (resourceName .isEmpty ()) {
27
- final Res res = args
28
- .getTargetElement ()
29
- .getAnnotation (Res .class );
25
+ final Res res = args .getTargetElement ().getAnnotation (Res .class );
30
26
filename = res .value ();
31
27
} else {
32
28
filename = resourceName ;
@@ -38,73 +34,43 @@ public Object provide(final Args args) {
38
34
final Class <?> type = args .getTargetElementClass ();
39
35
final Unmarshaller <?> unmarshaller ;
40
36
41
- final Optional <Use > optUse =
42
- lookForAnnotation (Use .class , args .getTargetElement (),
43
- args .getTestClass ());
37
+ final Optional <Use > optUse = lookForAnnotation (Use .class , args .getTargetElement (), args .getTestClass ());
44
38
45
39
if (optUse .isPresent ()) {
46
40
final Use use = optUse .get ();
47
41
48
42
try {
49
- unmarshaller = use
50
- .value ()
51
- .getDeclaredConstructor ()
52
- .newInstance ();
43
+ unmarshaller = use .value ().getDeclaredConstructor ().newInstance ();
53
44
} catch (final Exception ex ) {
54
- throw new InvalidMarshallerClassException (use
55
- .value ()
56
- .getSimpleName (), ex );
45
+ throw new InvalidMarshallerClassException (use .value ().getSimpleName (), ex );
57
46
}
58
47
} else {
59
48
if (type .isAssignableFrom (String .class )) {
60
- unmarshaller = Puma4j
61
- .instance ()
62
- .textMarshaller ();
49
+ unmarshaller = Puma4j .instance ().textMarshaller ();
63
50
} else if (type .isAssignableFrom (byte [].class ) || type .isAssignableFrom (Byte [].class )) {
64
- unmarshaller = Puma4j
65
- .instance ()
66
- .binaryMarshaller ();
51
+ unmarshaller = Puma4j .instance ().binaryMarshaller ();
67
52
} else if (type .isAssignableFrom (Properties .class )) {
68
- unmarshaller = Puma4j
69
- .instance ()
70
- .propertiesMarshaller ();
53
+ unmarshaller = Puma4j .instance ().propertiesMarshaller ();
71
54
} else {
72
55
if (hasExtension ) {
73
- unmarshaller =
74
- Puma4j
75
- .instance ()
76
- .getMarshallerByExtension (extension )
77
- .orElseThrow (() -> newExtNotSupportedException (args , filename , extension ));
56
+ unmarshaller = Puma4j .instance ()
57
+ .getMarshallerByExtension (extension )
58
+ .orElseThrow (() -> newExtNotSupportedException (args , filename , extension ));
78
59
} else {
79
60
throw new NoMarshallerException (
80
- buildErrorMessage (
81
- "Unable to find a properly marshaller for specified resource." ,
82
- args , filename ));
61
+ buildErrorMessage ("Unable to find a properly marshaller for specified resource." , args , filename ));
83
62
}
84
63
}
85
64
}
86
65
87
- final String path = Paths
88
- .get (args
89
- .getContext ()
90
- .getBasePath (), filename )
91
- .toString ();
66
+ final String path = Paths .get (args .getContext ().getBasePath (), filename ).toString ();
92
67
93
- try (final InputStream input = args
94
- .getTestClass ()
95
- .getResourceAsStream (path )) {
68
+ try (final InputStream input = args .getTestClass ().getResourceAsStream (path )) {
96
69
return unmarshaller .unmarshal (
97
- new Unmarshaller .Args (
98
- input ,
99
- args .getTargetElementType (),
100
- args .getTestClass (),
101
- args .getTargetElement ()));
70
+ new Unmarshaller .Args (input , args .getTargetElementType (), args .getTestClass (), args .getTargetElement ()));
102
71
} catch (final Exception ex ) {
103
72
throw new UnmarshallingException (
104
- buildErrorMessage (
105
- "Error unmarshalling resource to specified type." ,
106
- args ,
107
- filename ), ex );
73
+ buildErrorMessage ("Error unmarshalling resource to specified type." , args , filename ), ex );
108
74
}
109
75
}
110
76
}
0 commit comments