From 287bf9b99240e2085a205496ead0b61181503462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Mon, 6 Feb 2012 22:13:19 +0000 Subject: [PATCH] Fail if no features are found. Closes #163 --- History.md | 1 + .../runtime/model/CucumberFeature.java | 4 ++++ .../cucumber/formatter/HTMLFormatterTest.java | 12 +--------- .../runtime/model/CucumberFeatureTest.java | 23 +++++++++++++++++++ .../java/cucumber/junit/CucumberTest.java | 6 ++--- 5 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 core/src/test/java/cucumber/runtime/model/CucumberFeatureTest.java diff --git a/History.md b/History.md index f028ef2a77..760d017b5e 100644 --- a/History.md +++ b/History.md @@ -1,5 +1,6 @@ ## In Git +* [Core] Fail if no features are found ([#163](https://github.com/cucumber/cucumber-jvm/issues/163) Aslak Hellesøy) * [Core] Fail if duplicate features are detected ([#165](https://github.com/cucumber/cucumber-jvm/issues/165) Aslak Hellesøy) ## [1.0.0.RC14](https://github.com/cucumber/cucumber-jvm/compare/v1.0.0.RC13...v1.0.0.RC14) diff --git a/core/src/main/java/cucumber/runtime/model/CucumberFeature.java b/core/src/main/java/cucumber/runtime/model/CucumberFeature.java index 19d6a0e8d6..0ef323640d 100644 --- a/core/src/main/java/cucumber/runtime/model/CucumberFeature.java +++ b/core/src/main/java/cucumber/runtime/model/CucumberFeature.java @@ -2,6 +2,7 @@ import cucumber.io.Resource; import cucumber.io.ResourceLoader; +import cucumber.runtime.CucumberException; import cucumber.runtime.FeatureBuilder; import gherkin.I18n; import gherkin.formatter.model.Background; @@ -32,6 +33,9 @@ public static List load(ResourceLoader resourceLoader, List noFeatures = emptyList(); - final File report = createFormatterJsReport(noFeatures); - - assertEquals(0, report.length()); - } - @Test public void oneFeatureProducesValidJavascript() throws IOException { final File report = createFormatterJsReport(asList("cucumber/formatter/HTMLFormatterTest.feature")); @@ -46,8 +37,7 @@ public void oneFeatureProducesValidJavascript() throws IOException { private File createFormatterJsReport(final List featurePaths) throws IOException { final File outputDir = runFeaturesWithFormatter(featurePaths); - final File report = new File(outputDir, "report.js"); - return report; + return new File(outputDir, "report.js"); } private File runFeaturesWithFormatter(final List featurePaths) throws IOException { diff --git a/core/src/test/java/cucumber/runtime/model/CucumberFeatureTest.java b/core/src/test/java/cucumber/runtime/model/CucumberFeatureTest.java new file mode 100644 index 0000000000..ec310f5d02 --- /dev/null +++ b/core/src/test/java/cucumber/runtime/model/CucumberFeatureTest.java @@ -0,0 +1,23 @@ +package cucumber.runtime.model; + +import cucumber.io.Resource; +import cucumber.io.ResourceLoader; +import cucumber.runtime.CucumberException; +import org.junit.Test; + +import java.util.Collections; + +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class CucumberFeatureTest { + @Test(expected = CucumberException.class) + public void fails_if_no_features_are_found() { + ResourceLoader resourceLoader = mock(ResourceLoader.class); + when(resourceLoader.resources(anyString(), anyString())).thenReturn(Collections.emptyList()); + CucumberFeature.load(resourceLoader, asList("does/not/exit"), emptyList()); + } +} diff --git a/junit/src/test/java/cucumber/junit/CucumberTest.java b/junit/src/test/java/cucumber/junit/CucumberTest.java index 844acdf691..3c21274d14 100644 --- a/junit/src/test/java/cucumber/junit/CucumberTest.java +++ b/junit/src/test/java/cucumber/junit/CucumberTest.java @@ -1,5 +1,6 @@ package cucumber.junit; +import cucumber.runtime.CucumberException; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -43,10 +44,9 @@ public void finds_features_based_on_explicit_root_package() throws IOException, assertEquals("Feature: In cucumber.junit", cucumber.getChildren().get(0).getName()); } - @Test + @Test(expected = CucumberException.class) public void finds_no_features_when_explicit_package_has_nothnig() throws IOException, InitializationError { - Cucumber cucumber = new Cucumber(ExplicitPackageWithNoFeatures.class); - assertEquals(0, cucumber.getChildren().size()); + new Cucumber(ExplicitPackageWithNoFeatures.class); } private class ImplicitPackage {