15
15
* See the License for the specific language governing permissions and
16
16
* limitations under the License.
17
17
*/
18
- package specs ;
18
+ package mustache . specs ;
19
19
20
20
import static org .junit .Assert .assertEquals ;
21
21
22
+ import java .io .File ;
22
23
import java .io .IOException ;
23
24
import java .net .URI ;
24
25
import java .util .ArrayList ;
25
26
import java .util .Collection ;
26
27
import java .util .List ;
27
28
import java .util .Map ;
28
29
30
+ import org .apache .commons .io .FileUtils ;
29
31
import org .junit .Before ;
30
32
import org .junit .ComparisonFailure ;
31
33
import org .junit .Test ;
@@ -82,7 +84,7 @@ public void run() throws HandlebarsException, IOException {
82
84
}
83
85
}
84
86
85
- public static Collection <Object []> data (final String filename ) {
87
+ public static Collection <Object []> data (final String filename ) throws IOException {
86
88
return data (SpecTest .class , filename );
87
89
}
88
90
@@ -92,25 +94,26 @@ public static String path(final Class<?> loader) {
92
94
93
95
@ SuppressWarnings ("unchecked" )
94
96
public static Collection <Object []> data (final Class <?> loader ,
95
- final String filename ) {
97
+ final String filename ) throws IOException {
96
98
Constructor constructor = new Constructor ();
97
99
constructor .addTypeDescription (new TypeDescription (Blog .class , "!blog" ));
98
100
constructor .addTypeDescription (new TypeDescription (Comment .class ,
99
101
"!comment" ));
102
+ constructor .addTypeDescription (new TypeDescription (Map .class ,
103
+ "!code" ));
100
104
101
105
Yaml yaml = new Yaml (constructor );
102
106
103
107
String location = path (loader ) + filename ;
104
- Map <String , Object > data =
105
- (Map <String , Object >) yaml .load (
106
- SpecTest .class .getResourceAsStream (location ));
108
+ String input = FileUtils .readFileToString (new File ("src/test/resources" , location ));
109
+ Map <String , Object > data = (Map <String , Object >) yaml .load (input );
107
110
List <Map <String , Object >> tests =
108
111
(List <Map <String , Object >>) data .get ("tests" );
109
112
int number = 0 ;
110
113
Collection <Object []> dataset = new ArrayList <Object []>();
111
114
for (Map <String , Object > test : tests ) {
112
115
test .put ("number" , number ++);
113
- dataset .add (new Object [] {new Spec (test ) });
116
+ dataset .add (new Object []{new Spec (test ) });
114
117
}
115
118
return dataset ;
116
119
}
@@ -153,7 +156,7 @@ private void run(final Spec spec) throws IOException {
153
156
assertEquals (expected , output );
154
157
report .append ("OUTPUT:" );
155
158
report .append (output );
156
- } catch (HandlebarsException ex ) {
159
+ } catch (HandlebarsException ex ) {
157
160
Handlebars .error (ex .getMessage ());
158
161
} catch (ComparisonFailure ex ) {
159
162
report .append ("FOUND:" );
0 commit comments