Skip to content

Commit

Permalink
Fixed #1277 - NPE when attempting to directly call the JsonPath or XP…
Browse files Browse the repository at this point in the history
…ath handlebars helpers
  • Loading branch information
tomakehurst committed Mar 2, 2020
1 parent 117472c commit 6971f18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ private String formatMessage(String message) {
}

protected static RenderCache getRenderCache(Options options) {
return options.get("renderCache", null);
return options.get("renderCache", new RenderCache());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.github.tomakehurst.wiremock.extension.responsetemplating.helpers;

import com.github.jknack.handlebars.Context;
import com.github.jknack.handlebars.Options;
import com.github.tomakehurst.wiremock.common.ConsoleNotifier;
import com.github.tomakehurst.wiremock.common.FileSource;
import com.github.tomakehurst.wiremock.common.LocalNotifier;
Expand All @@ -27,6 +29,7 @@
import org.junit.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
Expand Down Expand Up @@ -266,4 +269,16 @@ public void returnsCorrectResultWhenDifferentExpressionsUsedOnSameDocument() thr
assertThat(two, is(2));
}

@Test
public void helperCanBeCalledDirectlyWithoutSupplyingRenderCache() throws Exception {
Context context = Context.newBuilder(null).build();
Options options = new Options(null, null, null, context, null, null,
new Object[] { "$.stuff" }, null, new ArrayList<String>(0));

Object result = helper.apply("{\"stuff\":1}", options);

assertThat(result, instanceOf(Integer.class));
assertThat((Integer) result, is(1));
}

}

0 comments on commit 6971f18

Please sign in to comment.