|
18 | 18 | import static java.util.Collections.emptyList;
|
19 | 19 | import static org.junit.Assert.assertEquals;
|
20 | 20 | import static org.junit.Assert.fail;
|
| 21 | +import static org.mockito.Matchers.anyString; |
21 | 22 | import static org.mockito.Mockito.mock;
|
22 | 23 | import static org.mockito.Mockito.when;
|
23 | 24 |
|
@@ -116,6 +117,26 @@ public void loads_features_specified_in_rerun_file() throws Exception {
|
116 | 117 | assertEquals("Scenario: scenario 2", features.get(1).getFeatureElements().get(0).getVisualName());
|
117 | 118 | }
|
118 | 119 |
|
| 120 | + @Test |
| 121 | + public void loads_no_features_when_rerun_file_is_empty() throws Exception { |
| 122 | + String feature = "" + |
| 123 | + "Feature: bar\n" + |
| 124 | + " Scenario: scenario bar\n" + |
| 125 | + " * step\n"; |
| 126 | + String rerunPath = "path/rerun.txt"; |
| 127 | + String rerunFile = ""; |
| 128 | + ResourceLoader resourceLoader = mockFeatureFileResourceForAnyFeaturePath(feature); |
| 129 | + mockFileResource(resourceLoader, rerunPath, null, rerunFile); |
| 130 | + |
| 131 | + List<CucumberFeature> features = CucumberFeature.load( |
| 132 | + resourceLoader, |
| 133 | + asList("@" + rerunPath), |
| 134 | + new ArrayList<Object>(), |
| 135 | + new PrintStream(new ByteArrayOutputStream())); |
| 136 | + |
| 137 | + assertEquals(0, features.size()); |
| 138 | + } |
| 139 | + |
119 | 140 | @Test
|
120 | 141 | public void loads_features_specified_in_rerun_file_from_classpath_when_not_in_file_system() throws Exception {
|
121 | 142 | String featurePath = "path/bar.feature";
|
@@ -214,6 +235,16 @@ private ResourceLoader mockFeatureFileResource(String featurePath, String featur
|
214 | 235 | return resourceLoader;
|
215 | 236 | }
|
216 | 237 |
|
| 238 | + private ResourceLoader mockFeatureFileResourceForAnyFeaturePath(String feature) |
| 239 | + throws IOException, UnsupportedEncodingException { |
| 240 | + ResourceLoader resourceLoader = mock(ResourceLoader.class); |
| 241 | + Resource resource = mock(Resource.class); |
| 242 | + when(resource.getPath()).thenReturn(""); |
| 243 | + when(resource.getInputStream()).thenReturn(new ByteArrayInputStream(feature.getBytes("UTF-8"))); |
| 244 | + when(resourceLoader.resources(anyString(), anyString())).thenReturn(asList(resource)); |
| 245 | + return resourceLoader; |
| 246 | + } |
| 247 | + |
217 | 248 | private void mockFeatureFileResource(ResourceLoader resourceLoader, String featurePath, String feature)
|
218 | 249 | throws IOException, UnsupportedEncodingException {
|
219 | 250 | mockFileResource(resourceLoader, featurePath, ".feature", feature);
|
|
0 commit comments