From 822e76cf7e9716fbdc89ae56078c29c2b74ff245 Mon Sep 17 00:00:00 2001 From: Lorenzo Bettini Date: Mon, 6 Mar 2017 11:54:25 +0100 Subject: [PATCH] Added tests for .xtext.testing.Flaky Since now Flaky is also part of .xtext.testing, I copied the tests for Flaky from .junit4.tests project Signed-off-by: Lorenzo Bettini --- .../testing/tests/FlakyFailsFourTimes.java | 54 +++++++++++++++++++ .../testing/tests/FlakyFailsTwoTimes.java | 30 +++++++++++ .../testing/tests/IllegalFlakyConfigTest.java | 54 +++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 org.eclipse.xtext.testing/tests/org/eclipse/xtext/testing/tests/FlakyFailsFourTimes.java create mode 100644 org.eclipse.xtext.testing/tests/org/eclipse/xtext/testing/tests/FlakyFailsTwoTimes.java create mode 100644 org.eclipse.xtext.testing/tests/org/eclipse/xtext/testing/tests/IllegalFlakyConfigTest.java diff --git a/org.eclipse.xtext.testing/tests/org/eclipse/xtext/testing/tests/FlakyFailsFourTimes.java b/org.eclipse.xtext.testing/tests/org/eclipse/xtext/testing/tests/FlakyFailsFourTimes.java new file mode 100644 index 000000000..990e07ea1 --- /dev/null +++ b/org.eclipse.xtext.testing/tests/org/eclipse/xtext/testing/tests/FlakyFailsFourTimes.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.xtext.testing.tests; + +import org.eclipse.xtext.testing.Flaky; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +/** + * @author Sebastian Zarnekow + */ +public class FlakyFailsFourTimes { + @Rule + public Flaky.Rule rule = new Flaky.Rule(); + + @Rule + public TestRule verifier = new TestRule() { + + public Statement apply(final Statement base, Description description) { + return new Statement() { + + @Override + public void evaluate() throws Throwable { + try { + base.evaluate(); + Assert.fail("Expected exception"); + } catch(IllegalStateException e) { + // expected + } + } + }; + } + }; + + static int fails = 4; + + @Test + @Flaky + public void flakyTest() { + fails--; + if (fails > 0) { + throw new IllegalStateException(); + } + } +} \ No newline at end of file diff --git a/org.eclipse.xtext.testing/tests/org/eclipse/xtext/testing/tests/FlakyFailsTwoTimes.java b/org.eclipse.xtext.testing/tests/org/eclipse/xtext/testing/tests/FlakyFailsTwoTimes.java new file mode 100644 index 000000000..bea94bc1e --- /dev/null +++ b/org.eclipse.xtext.testing/tests/org/eclipse/xtext/testing/tests/FlakyFailsTwoTimes.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.xtext.testing.tests; + +import org.eclipse.xtext.testing.Flaky; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +/** + * @author Sebastian Zarnekow + */ +public class FlakyFailsTwoTimes { + @Rule + public Flaky.Rule rule = new Flaky.Rule(); + + static int fails = 2; + + @Test + @Flaky + public void flakyTest() { + fails--; + Assert.assertTrue(fails <= 0); + } +} \ No newline at end of file diff --git a/org.eclipse.xtext.testing/tests/org/eclipse/xtext/testing/tests/IllegalFlakyConfigTest.java b/org.eclipse.xtext.testing/tests/org/eclipse/xtext/testing/tests/IllegalFlakyConfigTest.java new file mode 100644 index 000000000..1200979d4 --- /dev/null +++ b/org.eclipse.xtext.testing/tests/org/eclipse/xtext/testing/tests/IllegalFlakyConfigTest.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.xtext.testing.tests; + +import org.eclipse.xtext.testing.Flaky; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +/** + * @author Sebastian Zarnekow + */ +public class IllegalFlakyConfigTest { + + @Rule + public Flaky.Rule rule = new Flaky.Rule(); + + @Rule + public TestRule verifier = new TestRule() { + + public Statement apply(final Statement base, Description description) { + return new Statement() { + + @Override + public void evaluate() throws Throwable { + try { + base.evaluate(); + Assert.fail("Expected exception"); + } catch(IllegalArgumentException expected) { + // ok + } + } + }; + } + + }; + + @Test + @Flaky(trials = 1) + public void testIllegalNumberOfTrials_01() {} + + @Test + @Flaky(trials = 101) + public void testIllegalNumberOfTrials_02() {} + +}