@@ -156,11 +156,13 @@ public WireMockContainer withMapping(String name, String json) {
156156 * Loads mapping stub from the class resource
157157 * @param name Name of the mapping stub
158158 * @param resource Resource class. Name of the class will be appended to the resource path
159- * @param resourceJson Mapping definition file
159+ * @param resourceJson Reference to the mapping definition file, starting from the {@code resource} root
160+ * (normally package)
160161 * @return this instance
161162 */
162163 public WireMockContainer withMappingFromResource (String name , Class <?> resource , String resourceJson ) {
163- return withMapping (name , resource .getSimpleName () + "/" + resourceJson );
164+ final URL url = Resources .getResource (resource , resourceJson );
165+ return withMappingFromResource (name , url );
164166 }
165167
166168 /**
@@ -171,15 +173,16 @@ public WireMockContainer withMappingFromResource(String name, Class<?> resource,
171173 */
172174 public WireMockContainer withMappingFromResource (Class <?> resource , String resourceJson ) {
173175 final String id = resource .getName () + "_" + resourceJson ;
174- return withMapping (id , resource .getSimpleName () + "/" + resourceJson );
176+ return withMappingFromResource (id , resource .getSimpleName () + "/" + resourceJson );
175177 }
176178
177179 /**
178- * @deprecated use {@link #withMappingFromResource(String, Class, String)}
180+ * @deprecated use {@link #withMappingFromResource(String, Class, String)}.
181+ * Note that the new method scopes to the package, not to class
179182 */
180183 @ Deprecated
181184 public WireMockContainer withMapping (String name , Class <?> resource , String resourceJson ) {
182- return withMappingFromResource (name , resource , resourceJson );
185+ return withMappingFromResource (name , resource , resource . getSimpleName () + "/" + resourceJson );
183186 }
184187
185188 /**
@@ -189,15 +192,12 @@ public WireMockContainer withMapping(String name, Class<?> resource, String reso
189192 * @return this instance
190193 */
191194 public WireMockContainer withMappingFromResource (String name , String resourceName ) {
192- try {
193- URL url = Resources .getResource (resourceName );
194- String text = Resources .toString (url , StandardCharsets .UTF_8 );
195- return withMapping (name , text );
196- } catch (IOException ex ) {
197- throw new IllegalArgumentException (ex );
198- }
195+ final URL url = Resources .getResource (resourceName );
196+ return withMappingFromResource (name , url );
199197 }
200198
199+
200+
201201 /**
202202 * Loads mapping stub from the resource file
203203 * @param resourceName Resource name and path
0 commit comments