### Question:
ServerInfoResource extends RealmAwareResource { @Override public Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request) { return internalHandleAction(context, request); } @Inject  ServerInfoResource(@Named("frRest") Debug debug, ConsoleConfigHandler configHandler, 
            RestSecurityProvider restSecurityProvider, @Named("CoreRest") RedirectUrlValidator<String> urlValidator); @Override Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request); @Override Promise<ActionResponse, ResourceException> actionInstance(Context context, String s,
            ActionRequest request); @Override Promise<ResourceResponse, ResourceException> createInstance(Context context, CreateRequest request); @Override Promise<ResourceResponse, ResourceException> deleteInstance(Context context, String s,
            DeleteRequest request); @Override Promise<ResourceResponse, ResourceException> patchInstance(Context context, String s,
            PatchRequest request); @Override Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request,
            QueryResourceHandler handler); @Override Promise<ResourceResponse, ResourceException> readInstance(Context context, String resourceId,
            ReadRequest request); @Override Promise<ResourceResponse, ResourceException> updateInstance(Context context, String s,
            UpdateRequest request); static final String VALIDATE_GOTO_ACTION_ID; }### Answer:
@Test public void validateGotoShouldReturnUrlWhenNoSetting() throws InterruptedException, ExecutionException { JsonValue requestJson = json(object(field("goto", VALID_URL))); Context context = mock(Context.class); ActionRequest request = mock(ActionRequest.class); given(request.getAction()).willReturn("validateGoto"); given(request.getContent()).willReturn(requestJson); given(mockDomainExtractor.extractValidDomains(any(String.class))).willReturn(null); Promise<ActionResponse, ResourceException> promise = serverInfoResource.actionCollection(context, request); assertThat(promise.get().getJsonContent().get("validatedUrl").asString()).isEqualTo(VALID_URL); }
@Test public void validateGotoShouldReturnUrlWithValidUrl() throws InterruptedException, ExecutionException { JsonValue requestJson = json(object(field("goto", VALID_URL))); Context context = mock(Context.class); ActionRequest request = mock(ActionRequest.class); given(request.getAction()).willReturn("validateGoto"); given(request.getContent()).willReturn(requestJson); given(mockDomainExtractor.extractValidDomains(any(String.class))).willReturn(asSet(VALID_URL)); Promise<ActionResponse, ResourceException> promise = serverInfoResource.actionCollection(context, request); assertThat(promise.get().getJsonContent().get("validatedUrl").asString()).isEqualTo(VALID_URL); }
@Test public void validateGotoShouldReturnNullWithInvalidUrl() throws InterruptedException, ExecutionException { JsonValue requestJson = json(object(field("goto", INVALID_URL))); Context context = mock(Context.class); ActionRequest request = mock(ActionRequest.class); given(request.getAction()).willReturn("validateGoto"); given(request.getContent()).willReturn(requestJson); given(mockDomainExtractor.extractValidDomains(nullable(String.class))).willReturn(asSet(VALID_URL)); Promise<ActionResponse, ResourceException> promise = serverInfoResource.actionCollection(context, request); assertThat(promise.get().getJsonContent().get("validatedUrl").asString()).isEqualTo(null); }