### 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()) { throw new ContractContextException(assetId + " does not exist"); } InternalAsset internal = (InternalAsset) asset.get(); Base64.Encoder encoder = Base64.getEncoder(); return Json.createObjectBuilder() .add("id", internal.id()) .add("age", internal.age()) .add("data", internal.data()) .add("input", internal.input()) .add("contract_id", internal.contractId()) .add("argument", internal.argument()) .add("signature", encoder.encodeToString(internal.signature())) .add( "prev_hash", (internal.prevHash() != null) ? encoder.encodeToString(internal.prevHash()) : "") .add("hash", encoder.encodeToString(internal.hash())) .build(); }  @Override JsonObject invoke(Ledger ledger, JsonObject argument, Optional<JsonObject> property);  }### Answer:
@Test public void getContract_AssetIdNotGiven_ShouldThrowContractContextException() { assertThatThrownBy( () -> get.invoke(ledger, Json.createObjectBuilder().build(), Optional.empty())) .isInstanceOf(ContractContextException.class) .hasMessage("asset_id attribute is missing"); }
@Test public void getContract_AssetDoesNotExistInLedger_ShouldThrowContractContextException() { JsonObject argument = Json.createObjectBuilder().add("asset_id", "asset").build(); Mockito.when(ledger.get("asset")).thenReturn(Optional.empty()); assertThatThrownBy(() -> get.invoke(ledger, argument, Optional.empty())) .isInstanceOf(ContractContextException.class) .hasMessage("asset does not exist"); }
@Test public void getContract_AssetIdIsPresent_ShouldReturnAssetJsonObject() { Base64.Encoder encoder = Base64.getEncoder(); InternalAsset asset = createInternalAsset(); Mockito.when(ledger.get("asset")).thenReturn(Optional.of(asset)); JsonObject argument = Json.createObjectBuilder().add("asset_id", "asset").build(); JsonObject result = get.invoke(ledger, argument, Optional.empty()); assertThat(asset.id()).isEqualTo(result.getString("id")); assertThat(asset.age()).isEqualTo(result.getInt("age")); assertThat(asset.data()).isEqualTo(result.getJsonObject("data")); assertThat(asset.input()).isEqualTo(result.getJsonObject("input")); assertThat(asset.contractId()).isEqualTo(result.getString("contract_id")); assertThat(asset.argument()).isEqualTo(result.getJsonObject("argument")); assertThat(encoder.encodeToString(asset.signature())).isEqualTo(result.getString("signature")); assertThat(encoder.encodeToString(asset.prevHash())).isEqualTo(result.getString("prev_hash")); assertThat(encoder.encodeToString(asset.hash())).isEqualTo(result.getString("hash")); }