/* * Copyright (C) 2007-2012 Argeo GmbH * * 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 org.argeo.slc.runtime.test; import org.argeo.slc.UnsupportedException; import org.argeo.slc.test.TestData; import org.argeo.slc.test.TestDataProvider; /** Utilities for dealing with test datas. */ public class TestDataUtils { /** Extracts the test data from the given provider. */ public static T getFromProvider(Object obj, Class clss, String key) { if (obj instanceof TestDataProvider) { TestDataProvider testDataProvider = (TestDataProvider) obj; return testDataProvider.getTestData(clss, key); } else { throw new UnsupportedException("test data provider", obj); } } /** * Extracts the test data from the given provider using null * as key. */ public static T getFromProvider(Object obj, Class clss) { return getFromProvider(obj, clss, null); } /** * Returns it self after making the proper checks. Used for test data being * their own data providers. */ @SuppressWarnings("unchecked") public static T getItSelf(Class clss, TestData testDataObject) { if (clss.isAssignableFrom(testDataObject.getClass())) { return (T) testDataObject; } else { throw new UnsupportedException("test data", testDataObject); } } /** Makes sure this is an utility class. */ private TestDataUtils() { } }