Request extends RemoteClusterControllerTask { public Result getResult() throws StateRestApiException, OtherMasterIndexException { if (failure != null) { if (failure instanceof OtherMasterIndexException) { throw (OtherMasterIndexException) failure; } else { throw (StateRestApiException) failure; } } if (!isCompleted()) { throw new InternalFailure("Attempt to fetch result before it has been calculated"); } if (!resultSet) { throw new InternalFailure("Expected result to be set at this point."); } return result; } Request(MasterState state); Result getResult(); @Override final void doRemoteFleetControllerTask(Context context); @Override void handleFailure(Failure failure); @Override boolean isFailed(); abstract Result calculateResult(Context context);  }
@Test public void testGetResultBeforeCompletion() { Request<String> r = new Request<>(Request.MasterState.MUST_BE_MASTER) { @Override public String calculateResult(Context context) { return "foo"; } }; try{ r.getResult(); fail(); } catch (InternalFailure e) { } catch (Exception e) { fail(); } r.notifyCompleted(); try{ r.getResult(); fail(); } catch (InternalFailure e) { } catch (Exception e) { fail(); } }