package com.temenos.interaction.rimdsl.formatting;

import java.io.IOException;
import java.net.URL;

import javax.inject.Inject;

import junit.framework.Assert;

import org.eclipse.xtext.formatting.INodeModelFormatter;
import org.eclipse.xtext.junit4.InjectWith;
import org.eclipse.xtext.junit4.XtextRunner;
import org.eclipse.xtext.junit4.util.ParseHelper;
import org.eclipse.xtext.nodemodel.ICompositeNode;
import org.eclipse.xtext.parser.IParseResult;
import org.eclipse.xtext.resource.XtextResource;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import com.temenos.interaction.rimdsl.RIMDslInjectorProvider;
import com.temenos.interaction.rimdsl.rim.DomainModel;

/**
 * Tests Formatting.
 * 
 * @author aphethean
 */
@RunWith(XtextRunner.class)
@InjectWith(RIMDslInjectorProvider.class)
public class FormatterTest {

	@Inject
	ParseHelper<DomainModel> parser;
	
	@Inject INodeModelFormatter formatter;
	
	
	@Test
	public void testFormatting() throws Exception {
		String text = loadTestRIM("Simple.rim");
		DomainModel domainModel = parser.parse(text);
        IParseResult parseResult = ((XtextResource) domainModel.eResource()).getParseResult();
        Assert.assertNotNull(parseResult);
		ICompositeNode rootNode = parseResult.getRootNode();
		String formattedText = formatter.format(rootNode, 0, text.length()).getFormattedText();
		Assert.assertEquals(text, formattedText);
	}

	@Test
	public void testFormattingWithDomain() throws Exception {
		String text = loadTestRIM("TestDomain.rim");
		DomainModel domainModel = parser.parse(text);
        IParseResult parseResult = ((XtextResource) domainModel.eResource()).getParseResult();
        Assert.assertNotNull(parseResult);
		ICompositeNode rootNode = parseResult.getRootNode();
		String formattedText = formatter.format(rootNode, 0, text.length()).getFormattedText();
		Assert.assertEquals(text, formattedText);
	}

	private String loadTestRIM(String rimPath) throws IOException {
		URL url = Resources.getResource(rimPath);
		String rim = Resources.toString(url, Charsets.UTF_8);
		return rim;
	}

}
@@ -45,16 +45,108 @@
 tting;%0A%0A
+import static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertNotNull;%0A%0A
 import j
@@ -220,40 +220,8 @@
 t;%0A%0A
-import junit.framework.Assert;%0A%0A
 impo
@@ -1297,39 +1297,32 @@
 sult();%0A        
-Assert.
 assertNotNull(pa
@@ -1325,32 +1325,32 @@
 l(parseResult);%0A
+
 %09%09ICompositeNode
@@ -1472,39 +1472,32 @@
 mattedText();%0A%09%09
-Assert.
 assertEquals(tex
@@ -1783,23 +1783,16 @@
         
-Assert.
 assertNo
@@ -1960,17 +1960,10 @@
 ();%0A
+
 %09%09
-Assert.
 asse

Fix compilation errors with assert usage in new test