[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [p2-dev] QueryUtil changes and their impact on testability

Hi Matt,
p2 is an OSGi based framework so when running test on it, you need to run them as "JUnit Plug-in tests". That has always been the case as far as I know. A lot of p2 relies on services being started etc.


Regards,
Thomas Hallgren



On 03/23/2010 04:07 PM, Matt Hughes wrote:
Now that many of the *Query classes have moved into static methods on
QueryUtil, there is a problem with unit testability.

QueryUtil has a static initializers that use ExpressionUtil.

ExpressionUtil has static initializers that *depend on running in an
OSGi environment* (not unit test):

public final class ExpressionUtil {
	private static final LDAPFilterParser ldapFilterParser = new
LDAPFilterParser(ExpressionFactory.INSTANCE);
	public static final IExpression TRUE_EXPRESSION =
getFactory().constant(Boolean.TRUE);
	public static final IExpression FALSE_EXPRESSION =
getFactory().constant(Boolean.FALSE);

	private ExpressionUtil() {
		//We don't want to ppl to instantiate this class
	}

	/**
	 * Returns the global expression factory
	 * @return The global expression factory.
	 */
	public static IExpressionFactory getFactory() {
		return MetadataActivator.getExpressionFactory();
	}

(As soon as one even references ExpressionUtil, its static
initializers are called which in turn invoke #getFactory which rely on
MetadataActivator to have been activated by OSGi context.)

Therefore, if any class uses QueryUtil in its implementation (which
many must do now since the *Query classes have gone away), those
classes cannot be unit tested.  One could try and get around this by
setting MetadataActivator.instance, but that would only get you so
far.  Metadata#getExpressionFactory would still fail and cannot be
stubbed out so far as I can tell.

Am I missing something? How are people testing this code that makes
use of QueryUtil?
_______________________________________________
p2-dev mailing list
p2-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/p2-dev