package org.argeo.slc.runtime.test; import org.argeo.api.slc.UnsupportedException; import org.argeo.api.slc.test.TestData; import org.argeo.api.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() { } }