All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gwtplatform.dispatch.rest.delegates.test.DelegateTestUtils Maven / Gradle / Ivy

The newest version!
/**
 * Copyright 2014 ArcBees Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.gwtplatform.dispatch.rest.delegates.test;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.gwtplatform.dispatch.rest.delegates.client.ResourceDelegate;

/**
 * Utility methods to help mocking {@link com.gwtplatform.dispatch.rest.delegates.client.ResourceDelegate}s.
 * 

* Important:

  • {@link #init()} must be called before each test. Not doing it may cause unexpected * results. Using JUnit's {@link org.junit.Before @Before} is perfect for that.
  • {@link * DelegateMocking#useResource(Object) useResource(Object)} must be called before any other methods exactly once * and before any other methods for the delegate is called. Assertion errors will be thrown otherwise.
  • *
*/ public class DelegateTestUtils { public static final Map, DelegateMocking> delegateMockings = Collections.synchronizedMap(new HashMap, DelegateMocking>()); /** * Initializes the mocking utils. Must be called before each test. */ public static void init() { delegateMockings.clear(); } /** * Access or create the mocking context of delegate. * * @return the mocking context of delegate */ @SuppressWarnings("unchecked") public static DelegateMocking givenDelegate(ResourceDelegate delegate) { DelegateMocking delegateMocking; if (delegateMockings.containsKey(delegate)) { delegateMocking = (DelegateMocking) delegateMockings.get(delegate); } else { delegateMocking = new DelegateMocking(delegate); delegateMockings.put(delegate, delegateMocking); } return delegateMocking; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy