### Question:
GetContract extends Contract { @Override public JsonObject invoke(Ledger ledger, JsonObject argument, Optional<JsonObject> property) { if (!argument.containsKey("asset_id")) { throw new ContractContextException("asset_id attribute is missing"); } String assetId = argument.getString("asset_id"); Optional<Asset> asset = ledger.get(assetId); if (!asset.isPresent()) { return Json.createObjectBuilder() .add("result", "failure") .add("message", assetId + " is not in the ledger") .build(); } return Json.createObjectBuilder() .add("asset_id", asset.get().id()) .add("age", asset.get().age()) .add("data", asset.get().data()) .build(); }  @Override JsonObject invoke(Ledger ledger, JsonObject argument, Optional<JsonObject> property);  }### Answer:
@Test public void invoke_AssetIdGiven_ShouldResultInSuccess() { addAssetToLedger(); JsonObject argument = Json.createObjectBuilder().add("asset_id", ASSET_ID).build(); JsonObject result = get.invoke(ledger, argument, Optional.empty()); assertThat(result.getString("asset_id")).isEqualTo(ASSET_ID); }
@Test public void invoke_AssetNotInLedger_ShouldResultInFailure() { JsonObject argument = Json.createObjectBuilder().add("asset_id", ASSET_ID).build(); JsonObject result = get.invoke(ledger, argument, Optional.empty()); assertThat(result.getString("result")).isEqualTo("failure"); assertThat(result.getString("message")).endsWith("is not in the ledger"); }
@Test public void invoke_AssetIdNotGiven_ShouldThrowContractContextException() { JsonObject argument = Json.createObjectBuilder().build(); assertThatThrownBy(() -> get.invoke(ledger, argument, Optional.empty())) .isInstanceOf(ContractContextException.class); }