From bffef05e46073f9f6571eda34719edbcc842e74b Mon Sep 17 00:00:00 2001
From: Joachim Nilsson <Joachim.Nilsson@molybden.se>
Date: Tue, 28 Aug 2012 14:43:44 +0200
Subject: [PATCH] JUnit tests now runs under win7, added replace of CR+NL to
 NL when reading stories from file.

---
 .../eclipse/preferences/PreferenceInitializer.java |    2 +-
 .../editor/story/scanner/PartitionScannerTest.java |    2 +-
 .../editor/story/scanner/StepParserTest.java       |    6 ++--
 .../eclipse/parser/VisitingStoryParserTest.java    |   21 ++++++++++++++-----
 4 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/org.jbehave.eclipse/src/org/jbehave/eclipse/preferences/PreferenceInitializer.java b/org.jbehave.eclipse/src/org/jbehave/eclipse/preferences/PreferenceInitializer.java
index 365be65..88da868 100644
--- a/org.jbehave.eclipse/src/org/jbehave/eclipse/preferences/PreferenceInitializer.java
+++ b/org.jbehave.eclipse/src/org/jbehave/eclipse/preferences/PreferenceInitializer.java
@@ -80,7 +80,7 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer {
     protected void initializeDefaultProjectPreferences() {
         ProjectPreferences projectPreferences = new ProjectPreferences(DefaultScope.INSTANCE);
         projectPreferences.setStoryLanguage("en");
-        projectPreferences.setAvailableStoryLanguages("de", "en", "fr", "it", "pt", "tr", "zh_TW");
+        projectPreferences.setAvailableStoryLanguages("de", "en", "fr", "it", "no", "pt", "sv", "tr", "zh_TW");
         projectPreferences.setParameterPrefix("$");
         try {
             projectPreferences.store();
diff --git a/org.jbehave.eclipse/test/org/jbehave/eclipse/editor/story/scanner/PartitionScannerTest.java b/org.jbehave.eclipse/test/org/jbehave/eclipse/editor/story/scanner/PartitionScannerTest.java
index bc66775..6a84e31 100644
--- a/org.jbehave.eclipse/test/org/jbehave/eclipse/editor/story/scanner/PartitionScannerTest.java
+++ b/org.jbehave.eclipse/test/org/jbehave/eclipse/editor/story/scanner/PartitionScannerTest.java
@@ -28,7 +28,7 @@ public class PartitionScannerTest {
     
     @Before
     public void setUp () throws IOException {
-        storyAsText = IOUtils.toString(getClass().getResourceAsStream("/data/UseCaseEx01.story"));
+        storyAsText = IOUtils.toString(getClass().getResourceAsStream("/data/UseCaseEx01.story")).replace("\r\n", "\n");
         jbehaveProject = mock(JBehaveProject.class);
         localizedSupport = new LocalizedStepSupport();
         localizedSupport.setStoryLocale(Locale.ENGLISH);
diff --git a/org.jbehave.eclipse/test/org/jbehave/eclipse/editor/story/scanner/StepParserTest.java b/org.jbehave.eclipse/test/org/jbehave/eclipse/editor/story/scanner/StepParserTest.java
index d8c623e..89ee153 100644
--- a/org.jbehave.eclipse/test/org/jbehave/eclipse/editor/story/scanner/StepParserTest.java
+++ b/org.jbehave.eclipse/test/org/jbehave/eclipse/editor/story/scanner/StepParserTest.java
@@ -138,7 +138,7 @@ public class StepParserTest {
     public void usecase_ex2_light() throws Exception {
         StepCandidate user = givenStep("a user named $username");
         
-        storyAsText = IOUtils.toString(getClass().getResourceAsStream("/data/UseCaseEx03-light.story"));
+        storyAsText = IOUtils.toString(getClass().getResourceAsStream("/data/UseCaseEx03-light.story")).replace("\r\n", "\n");
         when(locator.findFirstStep("a user named $username")).thenReturn(user);
         
         IDocument document= new Document(storyAsText);
@@ -164,7 +164,7 @@ public class StepParserTest {
         StepCandidate credits = whenStep("user credits is $amount dollars");
         StepCandidate clicks = whenStep("user clicks on $button button");
         
-        storyAsText = IOUtils.toString(getClass().getResourceAsStream("/data/UseCaseEx03.story"));
+        storyAsText = IOUtils.toString(getClass().getResourceAsStream("/data/UseCaseEx03.story")).replace("\r\n", "\n");
         when(locator.findFirstStep("a user named $username")).thenReturn(user);
         when(locator.findFirstStep("user clicks on $button button")).thenReturn(clicks);
         when(locator.findFirstStep("user credits is 5 dollars")).thenReturn(credits);
@@ -208,7 +208,7 @@ public class StepParserTest {
         StepCandidate user = givenStep("a user named $username");
         StepCandidate credits = whenStep("user credits is $amount dollars");
         
-        storyAsText = IOUtils.toString(getClass().getResourceAsStream("/data/UseCaseEx03.story"));
+        storyAsText = IOUtils.toString(getClass().getResourceAsStream("/data/UseCaseEx03.story")).replace("\r\n", "\n");
         when(locator.findFirstStep("a user named $username")).thenReturn(user);
         when(locator.findFirstStep("user credits is 5 dollars")).thenReturn(credits);
         when(locator.findFirstStep("a user named username")).thenReturn(user);
diff --git a/org.jbehave.eclipse/test/org/jbehave/eclipse/parser/VisitingStoryParserTest.java b/org.jbehave.eclipse/test/org/jbehave/eclipse/parser/VisitingStoryParserTest.java
index 69845b9..87a155c 100644
--- a/org.jbehave.eclipse/test/org/jbehave/eclipse/parser/VisitingStoryParserTest.java
+++ b/org.jbehave.eclipse/test/org/jbehave/eclipse/parser/VisitingStoryParserTest.java
@@ -28,7 +28,8 @@ public class VisitingStoryParserTest {
 
     @Test
     public void parse_case1() throws IOException {
-        String storyAsText = IOUtils.toString(getClass().getResourceAsStream("/data/UseCaseEx01.story"));
+        String story = "/data/UseCaseEx01.story";
+		String storyAsText = readToString(story);
 
         String[] expected = {
                 "offset: 0, length: 11, content: >>Narrative:\n<<", //
@@ -55,7 +56,8 @@ public class VisitingStoryParserTest {
 
     @Test
     public void parse_case4() throws IOException {
-        String storyAsText = IOUtils.toString(getClass().getResourceAsStream("/data/UseCaseEx04.story"));
+        String story = "/data/UseCaseEx04.story";
+		String storyAsText = readToString(story);
         String[] expected = {
                 "offset: 0, length: 219, content: >>Given a new account named 'networkAgent' with the following properties (properties not set will be completed) \n|key|value|\n|Login|networkAgentLogin|\n|Password|networkAgentPassword|\n!-- Test login using a bad password !\n<<", //
                 "offset: 219, length: 31, content: >>When agent displays Login page\n<<", //
@@ -70,7 +72,8 @@ public class VisitingStoryParserTest {
 
     @Test
     public void parse_case5_exampleTable() throws IOException {
-        String storyAsText = IOUtils.toString(getClass().getResourceAsStream("/data/UseCaseEx05-exampletable.story"));
+        String story = "/data/UseCaseEx05-exampletable.story";
+		String storyAsText = readToString(story);
         String[] expected = {
                 "offset: 0, length: 42, content: >>Given that Larry has done <trades> trades\n<<", //
                 "offset: 42, length: 87, content: >>Then the traders activity is: \n|name|trades|\n|Larry|<trades>|\n|Moe|1000|\n|Curly|2000|\n\n<<", //
@@ -80,7 +83,8 @@ public class VisitingStoryParserTest {
 
     @Test
     public void parse_case6_exampleTable() throws IOException {
-        String storyAsText = IOUtils.toString(getClass().getResourceAsStream("/data/UseCaseEx06-exampletable.story"));
+        String story = "/data/UseCaseEx06-exampletable.story";
+		String storyAsText = readToString(story);
         String[] expected = {
                 "offset: 0, length: 220, content: >>Given a new account named 'networkAgent' with the following properties (properties not set will be completed) \n|key|value|\n|Login|networkAgentLogin|\n|Password|networkAgentPassword|\n\n!-- Test login using a bad password !\n<<",//
                 "offset: 220, length: 31, content: >>When agent displays Login page\n<<",//
@@ -90,10 +94,11 @@ public class VisitingStoryParserTest {
         assertElements(expected, parser.parse(storyAsText));
     }
 
+
     @Test
     public void parse_case7_exampleTable() throws IOException {
-        String storyAsText = IOUtils.toString(getClass().getResourceAsStream(
-                "/data/UseCaseEx07-exampletable-comment.story"));
+    	String story = "/data/UseCaseEx07-exampletable-comment.story";
+        String storyAsText = readToString(story);
         String[] expected = {
                 "offset: 0, length: 199, content: >>Given a new account named 'networkAgent' with the following properties (properties not set will be completed) \n|key|value|\n!-- Some comment\n|Login|networkAgentLogin|\n|Password|networkAgentPassword|\n\n<<",//
                 "offset: 199, length: 96, content: >>Examples:\n|foo|foo|\n|bar|whatever|\n|-- a comment\n|bar2|whatever|\n|-- yet another\n|bar3|whatever|<<"
@@ -101,6 +106,10 @@ public class VisitingStoryParserTest {
         assertElements(expected, parser.parse(storyAsText));
     }
 
+    private String readToString(String story) throws IOException {
+    	return IOUtils.toString(getClass().getResourceAsStream(story),"UTF-8").replace("\r\n", "\n");
+    }
+    
     private void assertElements(String[] expected, List<StoryElement> elements) {
         int index = 0;
         for (StoryElement element : elements) {
-- 
1.7.7.1.msysgit.0

