package org.junit.experimental.categories;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TestName;
import org.junit.runner.Description;
import org.junit.runner.FilterFactoryParams;
import org.junit.runner.manipulation.Filter;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;

public class CategoryFilterFactoryTest {
    @Rule
    public ExpectedException expectedException = ExpectedException.none();

    @Rule
    public TestName testName = new TestName();

    @Test
    public void shouldCreateFilter() throws Exception {
        CategoryFilterFactory categoryFilterFactory = new CategoryFilterFactoryStub();
        FilterFactoryParams params = new FilterFactoryParams(
                Description.createSuiteDescription(testName.getMethodName()),
                CategoryFilterFactoryStub.class.getName());
        Filter filter = categoryFilterFactory.createFilter(params);

        assertThat(filter, instanceOf(DummyFilter.class));
    }

    private static class CategoryFilterFactoryStub extends CategoryFilterFactory {
        @Override
        protected Filter createFilter(Class<?>[] categories) {
            return new DummyFilter();
        }
    }

    private static class DummyFilter extends Filter {
        @Override
        public boolean shouldRun(Description description) {
            return false;
        }

        @Override
        public String describe() {
            return null;
        }
    }
}

@@ -194,32 +194,72 @@
 r.Description;%0D%0A
+import org.junit.runner.FilterFactory;%0D%0A
 import org.junit
@@ -645,79 +645,15 @@
     
-@Test%0D%0A    public void shouldCreateFilter() throws Exception %7B%0D%0A       
+private
  Cat
@@ -724,24 +724,94 @@
 toryStub();%0D
+%0A%0D%0A    @Test%0D%0A    public void shouldCreateFilter() throws Exception %7B%0D
 %0A        Fil
@@ -1134,32 +1134,431 @@
 ss));%0D%0A    %7D%0D%0A%0D%0A
+    @Test%0D%0A    public void shouldThrowException() throws Exception %7B%0D%0A        FilterFactoryParams params = new FilterFactoryParams(%0D%0A                Description.createSuiteDescription(testName.getMethodName()),%0D%0A                %22NonExistentFilter%22);%0D%0A%0D%0A        expectedException.expect(FilterFactory.FilterNotCreatedException.class);%0D%0A%0D%0A        categoryFilterFactory.createFilter(params);%0D%0A    %7D%0D%0A%0D%0A
     private stat

Test added.