package press;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import play.Play;
import play.mvc.Router;

import java.util.Properties;

import static org.junit.Assert.assertEquals;

public class PluginTest {
  @Test
  public void addCssWithoutMedia() {
    assertEquals("<link href=\"/test/main.css\" rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\"></link>\n",
        Plugin.addCSS("main.css", false, null));
  }

  @Test
  public void addCssWithMedia() {
    assertEquals("<link href=\"/test/main.css\" rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"screen\"></link>\n",
        Plugin.addCSS("main.css", false, "screen"));
  }

  @Test
  public void addSingleCss() {
    assertEquals("<link href=\"/test/main.css\" rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\"></link>\n",
        Plugin.addSingleCSS("main.css", null));
  }

  @Test
  public void addSingleCssWithMedia() {
    assertEquals("<link href=\"/test/main.css\" rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"print\"></link>\n",
        Plugin.addSingleCSS("main.css", "print"));
  }

  @Before
  public void setUp() {
    Play.configuration = new Properties();
    PluginConfig.readConfig();

    PluginConfig.js.srcDir = "test";
    PluginConfig.css.srcDir = "test";
    Router.addRoute("GET", "/test/", "staticDir:test");

    new Plugin().beforeActionInvocation(null);
  }

  @After
  public void tearDown() {
    new Plugin().afterActionInvocation();
  }
}

@@ -124,16 +124,94 @@
 outer;%0A%0A
+import java.io.File;%0Aimport java.net.URISyntaxException;%0Aimport java.net.URL;%0A
 import j
@@ -1223,19 +1223,45 @@
  setUp()
+ throws URISyntaxException
  %7B%0A
-
     Play
@@ -1323,24 +1323,226 @@
 dConfig();%0A%0A
+    URL mainCss = Thread.currentThread().getContextClassLoader().getResource(%22main.css%22);%0A    File cssDir = new File(mainCss.toURI()).getParentFile();%0A    Play.applicationPath = cssDir.getParentFile();%0A
     PluginCo
@@ -1554,30 +1554,40 @@
 js.srcDir = 
-%22test%22
+cssDir.getName()
 ;%0A    Plugin
@@ -1610,14 +1610,24 @@
 r = 
-%22test%22
+cssDir.getName()
 ;%0A  
@@ -1676,13 +1676,28 @@
 Dir:
-test%22
+%22 + cssDir.getName()
 );%0A%0A

use relative path in unit-tests to make them runnable within other projects