Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 70187200828 for ; Fri, 13 May 2016 17:06:57 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6E98216099F; Fri, 13 May 2016 15:06:57 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 68C171602BE for ; Fri, 13 May 2016 17:06:56 +0200 (CEST) Received: (qmail 13071 invoked by uid 500); 13 May 2016 15:06:55 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 13062 invoked by uid 99); 13 May 2016 15:06:55 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 May 2016 15:06:55 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 2A24DC0A45 for ; Fri, 13 May 2016 15:06:55 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.221 X-Spam-Level: X-Spam-Status: No, score=-3.221 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id G7F_tiZeXLOc for ; Fri, 13 May 2016 15:06:52 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 37D4D5F1D5 for ; Fri, 13 May 2016 15:06:51 +0000 (UTC) Received: (qmail 12511 invoked by uid 99); 13 May 2016 15:06:50 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 May 2016 15:06:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 48972DFF10; Fri, 13 May 2016 15:06:50 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jensdeppe@apache.org To: commits@geode.incubator.apache.org Message-Id: <703db3063d454078a6008a61fd861b4c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-geode git commit: GEODE-1350: Provide local fix for Category and Parameterized test issue Date: Fri, 13 May 2016 15:06:50 +0000 (UTC) archived-at: Fri, 13 May 2016 15:06:57 -0000 Repository: incubator-geode Updated Branches: refs/heads/develop 819bf650b -> 973c86c7a GEODE-1350: Provide local fix for Category and Parameterized test issue Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/973c86c7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/973c86c7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/973c86c7 Branch: refs/heads/develop Commit: 973c86c7a2706f1737c39ffc4fa2feaf0fc08801 Parents: 819bf65 Author: Jens Deppe Authored: Wed May 11 08:05:33 2016 -0700 Committer: Jens Deppe Committed: Fri May 13 07:54:30 2016 -0700 ---------------------------------------------------------------------- .../CategoryWithParameterizedRunner.java | 44 +++++ .../CategoryWithParameterizedRunnerFactory.java | 42 +++++ .../junit/runners/ExposedGetAnnotations.java | 23 +++ ...egoryWithParameterizedRunnerFactoryTest.java | 161 +++++++++++++++++++ 4 files changed, 270 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/973c86c7/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/runners/CategoryWithParameterizedRunner.java ---------------------------------------------------------------------- diff --git a/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/runners/CategoryWithParameterizedRunner.java b/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/runners/CategoryWithParameterizedRunner.java new file mode 100644 index 0000000..c96951b --- /dev/null +++ b/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/runners/CategoryWithParameterizedRunner.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 com.gemstone.gemfire.test.junit.runners; + +import org.junit.runner.RunWith; +import org.junit.runners.model.InitializationError; +import org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParameters; +import org.junit.runners.parameterized.TestWithParameters; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.List; + +public class CategoryWithParameterizedRunner extends BlockJUnit4ClassRunnerWithParameters implements ExposedGetAnnotations { + public CategoryWithParameterizedRunner(TestWithParameters test) throws InitializationError { + super(test); + } + + @Override + public Annotation[] getRunnerAnnotations() { + Annotation[] allAnnotations = getTestClass().getAnnotations(); + List annotationsWithoutRunWith = new ArrayList<>(); + for (Annotation annotation: allAnnotations) { + if (!annotation.annotationType().equals(RunWith.class)) { + annotationsWithoutRunWith.add(annotation); + } + } + return annotationsWithoutRunWith.toArray(new Annotation[0]); + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/973c86c7/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/runners/CategoryWithParameterizedRunnerFactory.java ---------------------------------------------------------------------- diff --git a/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/runners/CategoryWithParameterizedRunnerFactory.java b/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/runners/CategoryWithParameterizedRunnerFactory.java new file mode 100644 index 0000000..84882f0 --- /dev/null +++ b/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/runners/CategoryWithParameterizedRunnerFactory.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 com.gemstone.gemfire.test.junit.runners; + +import org.junit.runner.RunWith; +import org.junit.runner.Runner; +import org.junit.runners.model.InitializationError; +import org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParameters; +import org.junit.runners.parameterized.ParametersRunnerFactory; +import org.junit.runners.parameterized.TestWithParameters; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.List; + +/** + * This class provides an early fix for JUnit issue GEODE-1350 + */ +public class CategoryWithParameterizedRunnerFactory implements ParametersRunnerFactory { + @Override + public Runner createRunnerForTestWithParameters(TestWithParameters test) throws InitializationError { + return new CategoryWithParameterizedRunner(test); + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/973c86c7/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/runners/ExposedGetAnnotations.java ---------------------------------------------------------------------- diff --git a/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/runners/ExposedGetAnnotations.java b/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/runners/ExposedGetAnnotations.java new file mode 100644 index 0000000..f5906f2 --- /dev/null +++ b/geode-junit/src/main/java/com/gemstone/gemfire/test/junit/runners/ExposedGetAnnotations.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 com.gemstone.gemfire.test.junit.runners; + +import java.lang.annotation.Annotation; + +public interface ExposedGetAnnotations { + Annotation[] getRunnerAnnotations(); +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/973c86c7/geode-junit/src/test/java/com/gemstone/gemfire/test/junit/runners/CategoryWithParameterizedRunnerFactoryTest.java ---------------------------------------------------------------------- diff --git a/geode-junit/src/test/java/com/gemstone/gemfire/test/junit/runners/CategoryWithParameterizedRunnerFactoryTest.java b/geode-junit/src/test/java/com/gemstone/gemfire/test/junit/runners/CategoryWithParameterizedRunnerFactoryTest.java new file mode 100644 index 0000000..63a579b --- /dev/null +++ b/geode-junit/src/test/java/com/gemstone/gemfire/test/junit/runners/CategoryWithParameterizedRunnerFactoryTest.java @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 com.gemstone.gemfire.test.junit.runners; + +import com.gemstone.gemfire.test.junit.categories.UnitTest; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.Description; +import org.junit.runner.JUnitCore; +import org.junit.runner.Request; +import org.junit.runner.Result; +import org.junit.runner.RunWith; +import org.junit.runner.Runner; +import org.junit.runner.manipulation.Filter; +import org.junit.runners.Parameterized; +import org.junit.runners.model.InitializationError; +import org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParameters; +import org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParametersFactory; +import org.junit.runners.parameterized.TestWithParameters; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class CategoryWithParameterizedRunnerFactoryTest { + + /** + * So much hacking in order to expose JUnit internals. I have no words... + */ + public static class ExposedBlockJUnit4ClassRunnerWithParameters extends BlockJUnit4ClassRunnerWithParameters implements ExposedGetAnnotations { + public ExposedBlockJUnit4ClassRunnerWithParameters(TestWithParameters test) throws InitializationError { + super(test); + } + + @Override + public Annotation[] getRunnerAnnotations() { + return super.getRunnerAnnotations(); + } + } + + public static class ExposedBlockJUnit4ClassRunnerWithParametersFactory extends + BlockJUnit4ClassRunnerWithParametersFactory { + public Runner createRunnerForTestWithParameters(TestWithParameters test) throws InitializationError { + return new ExposedBlockJUnit4ClassRunnerWithParameters(test); + } + } + + public static class ExposedParameterized extends Parameterized { + public ExposedParameterized(Class klass) throws Throwable { + super(klass); + } + + @Override + protected List getChildren() { + return super.getChildren(); + } + } + + @Category(UnitTest.class) + @RunWith(ExposedParameterized.class) + @Parameterized.UseParametersRunnerFactory(ExposedBlockJUnit4ClassRunnerWithParametersFactory.class) + public static class BrokenCategoryClass { + @Parameterized.Parameters + public static Iterable getParams() { + return Arrays.asList("one", "two"); + } + + @Parameterized.Parameter + public String value; + + @Test + public void insanity() { + assertTrue(true); + } + } + + @Category(UnitTest.class) + @RunWith(ExposedParameterized.class) + @Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class) + public static class WorkingCategoryClass { + @Parameterized.Parameters + public static Iterable getParams() { + return Arrays.asList("one", "two"); + } + + @Parameterized.Parameter + public String value; + + @Test + public void insanity() { + assertTrue(true); + } + } + + @Test + public void testBrokenCategoryAndParameterized() { + Request request = Request.aClass(BrokenCategoryClass.class); + ExposedParameterized runner = (ExposedParameterized) request.getRunner(); + request = request.filterWith(new CategoryFilter((ExposedBlockJUnit4ClassRunnerWithParameters) runner.getChildren().get(0))); + Result result = new JUnitCore().run(request); + assertEquals("Yeah!! This might actually mean we've upgraded to JUnit 4.13. Hurry up already and delete this hack.", 1, result.getRunCount()); + } + + @Test + public void testWorkingCategoryAndParameterized() { + Request request = Request.aClass(WorkingCategoryClass.class); + ExposedParameterized runner = (ExposedParameterized) request.getRunner(); + request = request.filterWith(new CategoryFilter((ExposedGetAnnotations) runner.getChildren().get(0))); + Result result = new JUnitCore().run(request); + assertEquals(2, result.getRunCount()); + } + + public static class CategoryFilter extends Filter { + + private ExposedGetAnnotations runner; + + public CategoryFilter(ExposedGetAnnotations runner) { + this.runner = runner; + } + + @Override + public boolean shouldRun(Description description) { + if (description.getChildren().size() == 0) { + return true; + } + + List runnerAnnotations = new ArrayList<>(); + Collections.addAll(runnerAnnotations, runner.getRunnerAnnotations()); + for (Annotation a : description.getAnnotations()) { + if (runnerAnnotations.contains(a)) { + return true; + } + } + return false; + } + + @Override + public String describe() { + return CategoryFilter.class.getSimpleName(); + } + } +}