@Test public void testExceptions() { assertThatExceptionOfType(JSONStructureException.class).isThrownBy(() -> { JsonRequestTranslator.load(new File(folder.getRoot().getAbsolutePath() + "/idontexist.json")); }); assertThatExceptionOfType(JSONStructureException.class).isThrownBy(() -> { JsonRequestTranslator.load("iamnot a json string at all"); }); assertThatExceptionOfType(JSONStructureException.class).isThrownBy(() -> { try (ByteArrayInputStream is = new ByteArrayInputStream("fjskfjdskalfjdkslajdf".getBytes())) { JsonRequestTranslator.load(is); } }); }
public static Request load(String jsonString) throws JSONStructureException { try { GsonJsonRequest gsonRequest = gson.fromJson(new StringReader(jsonString), GsonJsonRequest.class); gsonRequest.postFromJsonDeserialization(); return gsonRequest.toXacmlRequest(); } catch (JsonSyntaxException | JsonIOException e) { throw new JSONStructureException("Failed to load json string " + jsonString.substring(0, 10), e); } }
JsonRequestTranslator { public static Request load(String jsonString) throws JSONStructureException { try { GsonJsonRequest gsonRequest = gson.fromJson(new StringReader(jsonString), GsonJsonRequest.class); gsonRequest.postFromJsonDeserialization(); return gsonRequest.toXacmlRequest(); } catch (JsonSyntaxException | JsonIOException e) { throw new JSONStructureException("Failed to load json string " + jsonString.substring(0, 10), e); } } }
JsonRequestTranslator { public static Request load(String jsonString) throws JSONStructureException { try { GsonJsonRequest gsonRequest = gson.fromJson(new StringReader(jsonString), GsonJsonRequest.class); gsonRequest.postFromJsonDeserialization(); return gsonRequest.toXacmlRequest(); } catch (JsonSyntaxException | JsonIOException e) { throw new JSONStructureException("Failed to load json string " + jsonString.substring(0, 10), e); } } private  JsonRequestTranslator(); }
JsonRequestTranslator { public static Request load(String jsonString) throws JSONStructureException { try { GsonJsonRequest gsonRequest = gson.fromJson(new StringReader(jsonString), GsonJsonRequest.class); gsonRequest.postFromJsonDeserialization(); return gsonRequest.toXacmlRequest(); } catch (JsonSyntaxException | JsonIOException e) { throw new JSONStructureException("Failed to load json string " + jsonString.substring(0, 10), e); } } private  JsonRequestTranslator(); static Request load(String jsonString); static Request load(File fileRequest); static Request load(InputStream is); static String toString(Request request, boolean prettyPrint); }
JsonRequestTranslator { public static Request load(String jsonString) throws JSONStructureException { try { GsonJsonRequest gsonRequest = gson.fromJson(new StringReader(jsonString), GsonJsonRequest.class); gsonRequest.postFromJsonDeserialization(); return gsonRequest.toXacmlRequest(); } catch (JsonSyntaxException | JsonIOException e) { throw new JSONStructureException("Failed to load json string " + jsonString.substring(0, 10), e); } } private  JsonRequestTranslator(); static Request load(String jsonString); static Request load(File fileRequest); static Request load(InputStream is); static String toString(Request request, boolean prettyPrint);  }