### Question:
CoreTokenResource implements CollectionResourceProvider { public Promise<ResourceResponse, ResourceException> createInstance(Context serverContext, CreateRequest createRequest) { String principal = PrincipalRestUtils.getPrincipalNameFromServerContext(serverContext); String json = createRequest.getContent().toString(); Token token = serialisation.deserialise(json, Token.class); try { store.createAsync(token); Map<String, String> result = new HashMap<String, String>(); result.put(TOKEN_ID, token.getTokenId()); ResourceResponse resource = newResourceResponse( token.getTokenId(), String.valueOf(currentTimeMillis()), new JsonValue(result)); debug("CREATE by {0}: Stored token with ID: {1}", principal, token.getTokenId()); return newResultPromise(resource); } catch (IllegalArgumentException e) { return new BadRequestException(e.getMessage()).asPromise(); } catch (CoreTokenException e) { error(e, "CREATE by {0}: Error creating token resource with ID: {1}", principal, token.getTokenId()); return generateException(e).asPromise(); } } CoreTokenResource(JSONSerialisation serialisation, CTSPersistentStore store, Debug debug); Promise<ResourceResponse, ResourceException> createInstance(Context serverContext,
            CreateRequest createRequest); Promise<ResourceResponse, ResourceException> deleteInstance(Context serverContext, String tokenId,
            DeleteRequest deleteRequest); Promise<ResourceResponse, ResourceException> readInstance(Context serverContext, String tokenId,
            ReadRequest readRequest); Promise<ResourceResponse, ResourceException> updateInstance(Context serverContext, String tokenId,
            UpdateRequest updateRequest); Promise<QueryResponse, ResourceException> queryCollection(Context serverContext,
            QueryRequest queryRequest, QueryResourceHandler queryResultHandler); Promise<ResourceResponse, ResourceException> patchInstance(Context serverContext, String s,
            PatchRequest patchRequest); Promise<ActionResponse, ResourceException> actionInstance(Context serverContext, String s,
            ActionRequest actionRequest); Promise<ActionResponse, ResourceException> actionCollection(Context serverContext,
            ActionRequest actionRequest); static final String DEBUG_HEADER; }### Answer:
@Test public void shouldCreateTokenInCTS() throws CoreTokenException { CreateRequest request = mock(CreateRequest.class); given(request.getContent()).willReturn(new JsonValue("")); given(mockSerialisation.deserialise(nullable(String.class), ArgumentMatchers.<Class<Object>>any())).willReturn(mockToken); resource.createInstance(null, request); verify(mockStore).createAsync(mockToken); }
@Test public void shouldGetBadRequestForMissingTokenId() throws CoreTokenException { CreateRequest request = mock(CreateRequest.class); given(request.getContent()).willReturn(new JsonValue("")); doThrow(IllegalArgumentException.class).when(mockStore).createAsync(nullable(Token.class)); Promise<ResourceResponse, ResourceException> promise = resource.createInstance(null, request); assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class); }