package com.autonomy.abc.base;

import com.hp.autonomy.frontend.selenium.framework.inclusion.RunOnlyIfDescription;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.runner.Description;

public class UserRoleStrategy implements RunOnlyIfDescription.Acceptable {

    private final UserRole configUserRole;

    public UserRoleStrategy() {
        this.configUserRole = UserRole.fromString(System.getProperty("userRole"));
    }

    @Override
    public Matcher<? super Description> asMatcher() {

        return new TypeSafeMatcher<Description>() {
            @Override
            protected boolean matchesSafely(Description item) {
                TestUserRole userRole = new TestUserRole();
                userRole.starting(item);
                UserRole testUserRole = userRole.getApplicationValue();

                return configUserRole == null || configUserRole.equals(UserRole.ALL) || configUserRole.equals(testUserRole);
            }

            @Override
            public void describeTo(org.hamcrest.Description description) {
                description.appendText("User Role correct within Config");
            }
        };
    }
}

@@ -388,78 +388,140 @@
     
-this.configUserRole = UserRole.fromString(System.getProperty(%22
+String userRole = System.getProperty(%22userRole%22);%0D%0A%0D%0A        configUserRole = userRole == null ? null : UserRole.fromString(
 userRole
 %22));
@@ -516,18 +516,16 @@
 userRole
-%22)
 );%0D%0A    
@@ -1206,39 +1206,45 @@
 xt(%22
-User Role correct within Config
+Tests run against User Role specified
 %22);%0D

Update UserRoleStrategy to deal with no property specified, and a better error message