[jscover] 14/69: Use @BeforeClass where appropriate

Sylvestre Ledru sylvestre at moszumanska.debian.org
Fri Aug 22 05:54:02 UTC 2014


This is an automated email from the git hooks/post-receive script.

sylvestre pushed a commit to branch master
in repository jscover.

commit 57ca85b553f6dcec640d8c528569b8d9184d8604
Author: tntim96 <tntim96 at gmail.com>
Date:   Sat Jun 7 19:53:19 2014 +1000

    Use @BeforeClass where appropriate
---
 ...ServerUnloadedJSProxyOnlyInstrumentRegTest.java | 80 +++++++++++-----------
 .../server/HtmlServerUnloadedJSProxyTest.java      | 71 +++++++++----------
 .../HtmlServerUnloadedJSProxyUriToFileTest.java    | 72 +++++++++----------
 .../jscover/server/HtmlServerUnloadedJSTest.java   | 40 ++++++-----
 .../java/jscover/server/HtmlUnitJSTest.java        | 28 ++++----
 .../jscover/server/HtmlUnitLocalStorageTest.java   | 42 ++++++------
 .../java/jscover/server/HtmlUnitMergeTest.java     | 34 +++++----
 .../java/jscover/server/HtmlUnitProxyTest.java     | 72 +++++++++----------
 .../HtmlUnitServerBranchAndFunctionTest.java       | 37 +++++-----
 .../java/jscover/server/HtmlUnitServerTest.java    | 43 ++++++------
 .../java/jscover/server/WebDaemonTest.java         | 21 +++---
 11 files changed, 268 insertions(+), 272 deletions(-)

diff --git a/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyOnlyInstrumentRegTest.java b/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyOnlyInstrumentRegTest.java
index 476d739..9cfc13e 100644
--- a/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyOnlyInstrumentRegTest.java
+++ b/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyOnlyInstrumentRegTest.java
@@ -358,6 +358,7 @@ import jscover.util.IoUtils;
 
 import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import java.io.File;
@@ -373,59 +374,48 @@ public class HtmlServerUnloadedJSProxyOnlyInstrumentRegTest {
     private static Main main = new Main();
     private static ServerSocket serverSocket;
     private static int proxyPort = 3129;
+    private static String reportDir = "target/proxy-only-instrument-reg-report";
 
     protected WebClient webClient = new WebClient();
     protected IoUtils ioUtils = IoUtils.getInstance();
 
-    private String[] args = new String[]{
+    private static String[] args = new String[]{
             "-ws",
             "--document-root=src/test-integration/resources/jsSearch",
             "--port=" + proxyPort,
             "--proxy",
             "--only-instrument-reg=/level1/.*",
             "--include-unloaded-js",
-            "--report-dir=" + getReportDir()
+            "--report-dir=" + reportDir
     };
 
-    protected String getReportDir() {
-        return "target/proxy-only-instrument-reg-report";
-    }
-
-    @Before
-    public void setUp() throws IOException {
-        if (proxyServer == null) {
-            proxyServer = new Thread(new Runnable() {
-                public void run() {
-                    try {
-                        main.runMain(args);
-                    } catch (IOException e) {
-                        throw new RuntimeException(e);
-                    }
+    @BeforeClass
+    public static void setUpOnce() throws IOException {
+        proxyServer = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    main.runMain(args);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
                 }
-            });
-            proxyServer.start();
-        }
-        if (webServer == null) {
-            webServer = new Thread(new Runnable() {
-                public void run() {
-                    try {
-                        serverSocket = new ServerSocket(9001);
-                        File wwwRoot = new File("src/test-integration/resources/jsSearch");
-                        while (true) {
-                            Socket socket = serverSocket.accept();
-                            (new HttpServer(socket, wwwRoot, "testVersion")).start();
-                        }
-                    } catch (IOException e) {
-                        //throw new RuntimeException(e);
+            }
+        });
+        proxyServer.start();
+        webServer = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    serverSocket = new ServerSocket(9001);
+                    File wwwRoot = new File("src/test-integration/resources/jsSearch");
+                    while (true) {
+                        Socket socket = serverSocket.accept();
+                        (new HttpServer(socket, wwwRoot, "testVersion")).start();
                     }
+                } catch (IOException e) {
+                    //throw new RuntimeException(e);
                 }
-            });
-            webServer.start();
-        }
-        ProxyConfig proxyConfig = new ProxyConfig("localhost", proxyPort);
-        proxyConfig.addHostsToProxyBypass("127.0.0.1");
-        webClient.getOptions().setProxyConfig(proxyConfig);
-        webClient.getOptions().setTimeout(1000);
+            }
+        });
+        webServer.start();
     }
 
     @AfterClass
@@ -434,9 +424,17 @@ public class HtmlServerUnloadedJSProxyOnlyInstrumentRegTest {
         IoUtils.getInstance().closeQuietly(serverSocket);
     }
 
+    @Before
+    public void setUp() throws IOException {
+        ProxyConfig proxyConfig = new ProxyConfig("localhost", proxyPort);
+        proxyConfig.addHostsToProxyBypass("127.0.0.1");
+        webClient.getOptions().setProxyConfig(proxyConfig);
+        webClient.getOptions().setTimeout(1000);
+    }
+
     @Test
     public void shouldIncludeUnloadJSInSavedReport() throws Exception {
-        File jsonFile = new File(getReportDir() + "/jscoverage.json");
+        File jsonFile = new File(reportDir + "/jscoverage.json");
         if (jsonFile.exists())
             jsonFile.delete();
 
@@ -455,14 +453,14 @@ public class HtmlServerUnloadedJSProxyOnlyInstrumentRegTest {
         webClient.waitForBackgroundJavaScript(2000);
         String result = page.getElementById("storeDiv").getTextContent();
 
-        assertThat(result, containsString("Coverage data stored at " + new File(getReportDir()).getPath()));
+        assertThat(result, containsString("Coverage data stored at " + new File(reportDir).getPath()));
 
         String json = ioUtils.toString(jsonFile);
         assertThat(json, not(containsString("/root.js")));
         assertThat(json, containsString("/level1/level1.js"));
         assertThat(json, containsString("/level1/level2/level2.js"));
 
-        String url = "file:///" + new File(getReportDir() + "/jscoverage.html").getAbsolutePath();
+        String url = "file:///" + new File(reportDir + "/jscoverage.html").getAbsolutePath();
         page = webClient.getPage(url);
         webClient.waitForBackgroundJavaScript(1000);
 
diff --git a/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyTest.java b/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyTest.java
index 5613f33..f992895 100644
--- a/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyTest.java
+++ b/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyTest.java
@@ -347,6 +347,7 @@ import jscover.Main;
 import jscover.util.IoUtils;
 import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 
 import java.io.File;
 import java.io.IOException;
@@ -359,57 +360,50 @@ public class HtmlServerUnloadedJSProxyTest extends HtmlServerUnloadedJSTest {
     private static Main main = new Main();
     private static ServerSocket serverSocket;
     private static int proxyPort = 3129;
+    private static String reportDir = "target/proxy-unloaded-report";
 
-    private String[] args = new String[]{
+    private static String[] args = new String[]{
             "-ws",
             "--document-root=src/test-integration/resources/jsSearch",
             "--port=" + proxyPort,
             "--proxy",
             "--no-instrument=noInstrument",
             "--include-unloaded-js",
-            "--report-dir=" + getReportDir()
+            "--report-dir=" + reportDir
     };
 
     @Override
     protected String getReportDir() {
-        return "target/proxy-unloaded-report";
+        return reportDir;
     }
 
-    @Before
-    public void setUp() throws IOException {
-        if (proxyServer == null) {
-            proxyServer = new Thread(new Runnable() {
-                public void run() {
-                    try {
-                        main.runMain(args);
-                    } catch (IOException e) {
-                        throw new RuntimeException(e);
-                    }
+    @BeforeClass
+    public static void setUpOnce() throws IOException {
+        proxyServer = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    main.runMain(args);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
                 }
-            });
-            proxyServer.start();
-        }
-        if (webServer == null) {
-            webServer = new Thread(new Runnable() {
-                public void run() {
-                    try {
-                        serverSocket = new ServerSocket(9001);
-                        File wwwRoot = new File("src/test-integration/resources/jsSearch");
-                        while (true) {
-                            Socket socket = serverSocket.accept();
-                            (new HttpServer(socket, wwwRoot, "testVersion")).start();
-                        }
-                    } catch (IOException e) {
-                        //throw new RuntimeException(e);
+            }
+        });
+        proxyServer.start();
+        webServer = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    serverSocket = new ServerSocket(9001);
+                    File wwwRoot = new File("src/test-integration/resources/jsSearch");
+                    while (true) {
+                        Socket socket = serverSocket.accept();
+                        (new HttpServer(socket, wwwRoot, "testVersion")).start();
                     }
+                } catch (IOException e) {
+                    //throw new RuntimeException(e);
                 }
-            });
-            webServer.start();
-        }
-        ProxyConfig proxyConfig = new ProxyConfig("localhost", proxyPort);
-        proxyConfig.addHostsToProxyBypass("127.0.0.1");
-        webClient.getOptions().setProxyConfig(proxyConfig);
-        webClient.getOptions().setTimeout(1000);
+            }
+        });
+        webServer.start();
     }
 
     @AfterClass
@@ -418,4 +412,11 @@ public class HtmlServerUnloadedJSProxyTest extends HtmlServerUnloadedJSTest {
         IoUtils.getInstance().closeQuietly(serverSocket);
     }
 
+    @Before
+    public void setUp() {
+        ProxyConfig proxyConfig = new ProxyConfig("localhost", proxyPort);
+        proxyConfig.addHostsToProxyBypass("127.0.0.1");
+        webClient.getOptions().setProxyConfig(proxyConfig);
+        webClient.getOptions().setTimeout(1000);
+    }
 }
diff --git a/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyUriToFileTest.java b/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyUriToFileTest.java
index 8128853..a1498bb 100644
--- a/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyUriToFileTest.java
+++ b/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSProxyUriToFileTest.java
@@ -347,6 +347,7 @@ import jscover.Main;
 import jscover.util.IoUtils;
 import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 
 import java.io.File;
 import java.io.IOException;
@@ -359,8 +360,9 @@ public class HtmlServerUnloadedJSProxyUriToFileTest extends HtmlServerUnloadedJS
     private static Main main = new Main();
     private static ServerSocket serverSocket;
     private static int proxyPort = 3129;
+    private static String reportDir = "target/proxy-report-uri-to-file";
 
-    private String[] args = new String[]{
+    private static String[] args = new String[]{
             "-ws",
             "--document-root=src/test-integration/resources/jsSearch",
             "--port=" + proxyPort,
@@ -369,12 +371,12 @@ public class HtmlServerUnloadedJSProxyUriToFileTest extends HtmlServerUnloadedJS
             "--uri-to-file-matcher=/exclude(.*)",
             "--uri-to-file-replace=$1",
             "--include-unloaded-js",
-            "--report-dir=" + getReportDir()
+            "--report-dir=" + reportDir
     };
 
     @Override
     protected String getReportDir() {
-        return "target/proxy-report-uri-to-file";
+        return reportDir;
     }
 
     @Override
@@ -387,41 +389,33 @@ public class HtmlServerUnloadedJSProxyUriToFileTest extends HtmlServerUnloadedJS
         return "/exclude";
     }
 
-    @Before
-    public void setUp() throws IOException {
-        if (server == null) {
-            server = new Thread(new Runnable() {
-                public void run() {
-                    try {
-                        main.runMain(args);
-                    } catch (IOException e) {
-                        throw new RuntimeException(e);
-                    }
+    @BeforeClass
+    public static void setUpOnce() throws IOException {
+        server = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    main.runMain(args);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
                 }
-            });
-            server.start();
-        }
-        if (webServer == null) {
-            webServer = new Thread(new Runnable() {
-                public void run() {
-                    try {
-                        serverSocket = new ServerSocket(9001);
-                        File wwwRoot = new File("src/test-integration/resources/jsSearch");
-                        while (true) {
-                            Socket socket = serverSocket.accept();
-                            (new WeirdHttpServer(socket, wwwRoot, "testVersion")).start();
-                        }
-                    } catch (IOException e) {
-                        //throw new RuntimeException(e);
+            }
+        });
+        server.start();
+        webServer = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    serverSocket = new ServerSocket(9001);
+                    File wwwRoot = new File("src/test-integration/resources/jsSearch");
+                    while (true) {
+                        Socket socket = serverSocket.accept();
+                        (new WeirdHttpServer(socket, wwwRoot, "testVersion")).start();
                     }
+                } catch (IOException e) {
+                    //throw new RuntimeException(e);
                 }
-            });
-            webServer.start();
-        }
-        ProxyConfig proxyConfig = new ProxyConfig("localhost", proxyPort);
-        proxyConfig.addHostsToProxyBypass("127.0.0.1");
-        webClient.getOptions().setProxyConfig(proxyConfig);
-        webClient.getOptions().setTimeout(1000);
+            }
+        });
+        webServer.start();
     }
 
     @AfterClass
@@ -429,4 +423,12 @@ public class HtmlServerUnloadedJSProxyUriToFileTest extends HtmlServerUnloadedJS
         main.stop();
         IoUtils.getInstance().closeQuietly(serverSocket);
     }
+
+    @Before
+    public void setUp() {
+        ProxyConfig proxyConfig = new ProxyConfig("localhost", proxyPort);
+        proxyConfig.addHostsToProxyBypass("127.0.0.1");
+        webClient.getOptions().setProxyConfig(proxyConfig);
+        webClient.getOptions().setTimeout(1000);
+    }
 }
diff --git a/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSTest.java b/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSTest.java
index f11e880..715a5b7 100644
--- a/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSTest.java
+++ b/src/test-acceptance/java/jscover/server/HtmlServerUnloadedJSTest.java
@@ -349,6 +349,7 @@ import jscover.Main;
 import jscover.util.IoUtils;
 import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import java.io.File;
@@ -363,37 +364,35 @@ import static org.junit.Assert.assertEquals;
 public class HtmlServerUnloadedJSTest {
     private static Thread server;
     private static Main main = new Main();
+    private static String reportDir = "target/ws-unloaded-report";
 
-    protected WebClient webClient = new WebClient();
-    protected IoUtils ioUtils = IoUtils.getInstance();
-    private String[] args = new String[]{
+    private static String[] args = new String[]{
             "-ws",
             "--document-root=src/test-integration/resources/jsSearch",
             "--port=9001",
             "--no-instrument=noInstrument",
             "--include-unloaded-js",
-            "--report-dir=" + getReportDir()
+            "--report-dir=" + reportDir
     };
+    protected WebClient webClient = new WebClient();
+    protected IoUtils ioUtils = IoUtils.getInstance();
 
     protected String getReportDir() {
         return "target/ws-unloaded-report";
     }
 
-    @Before
-    public void setUp() throws IOException {
-        if (server == null) {
-            server = new Thread(new Runnable() {
-                public void run() {
-                    try {
-                        main.runMain(args);
-                    } catch (IOException e) {
-                        throw new RuntimeException(e);
-                    }
+    @BeforeClass
+    public static void setUpOnce() throws IOException {
+        server = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    main.runMain(args);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
                 }
-            });
-            server.start();
-        }
-        webClient.getOptions().setTimeout(1000);
+            }
+        });
+        server.start();
     }
 
     @AfterClass
@@ -401,6 +400,11 @@ public class HtmlServerUnloadedJSTest {
         main.stop();
     }
 
+    @Before
+    public void setUp() {
+        webClient.getOptions().setTimeout(1000);
+    }
+
     protected String getIndex() {
         return "index.html";
     }
diff --git a/src/test-acceptance/java/jscover/server/HtmlUnitJSTest.java b/src/test-acceptance/java/jscover/server/HtmlUnitJSTest.java
index 23ba722..53c9cf9 100644
--- a/src/test-acceptance/java/jscover/server/HtmlUnitJSTest.java
+++ b/src/test-acceptance/java/jscover/server/HtmlUnitJSTest.java
@@ -348,7 +348,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage;
 import com.gargoylesoftware.htmlunit.html.HtmlSpan;
 import jscover.Main;
 import org.junit.AfterClass;
-import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import java.io.IOException;
@@ -363,7 +363,7 @@ public class HtmlUnitJSTest {
     private static Main main = new Main();
 
     protected WebClient webClient = new WebClient();
-    private String[] args = new String[]{
+    private static String[] args = new String[]{
             "-ws",
             "--port=8081",
             "--no-branch",
@@ -374,20 +374,18 @@ public class HtmlUnitJSTest {
             "--report-dir=target/reports/jscover"
     };
 
-    @Before
-    public void setUp() throws IOException {
-        if (server == null) {
-            server = new Thread(new Runnable() {
-                public void run() {
-                    try {
-                        main.runMain(args);
-                    } catch (IOException e) {
-                        throw new RuntimeException(e);
-                    }
+    @BeforeClass
+    public static void setUpOnce() throws IOException {
+        server = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    main.runMain(args);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
                 }
-            });
-            server.start();
-        }
+            }
+        });
+        server.start();
     }
 
     @AfterClass
diff --git a/src/test-acceptance/java/jscover/server/HtmlUnitLocalStorageTest.java b/src/test-acceptance/java/jscover/server/HtmlUnitLocalStorageTest.java
index 01ddb25..d0e1bd4 100644
--- a/src/test-acceptance/java/jscover/server/HtmlUnitLocalStorageTest.java
+++ b/src/test-acceptance/java/jscover/server/HtmlUnitLocalStorageTest.java
@@ -349,6 +349,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage;
 import jscover.Main;
 import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import java.io.File;
@@ -359,38 +360,34 @@ import static org.junit.Assert.assertEquals;
 public class HtmlUnitLocalStorageTest {
     private static Thread server;
     private static Main main = new Main();
+    private static String reportDir = "target/localStorage";
 
     protected WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24);
-    private String[] args = new String[]{
+    private static String[] args = new String[]{
             "-ws",
             "--document-root=src/test-acceptance/resources",
             "--port=9001",
             "--no-instrument=example/lib",
             "--local-storage",
-            "--report-dir=" + getReportDir()
+            "--report-dir=" + reportDir
     };
 
     protected String getReportDir() {
-        return "target/localStorage";
+        return reportDir;
     }
 
-    @Before
-    public void setUp() throws IOException {
-        File jsonFile = new File(getReportDir() + "/jscoverage.json");
-        if (jsonFile.exists())
-            jsonFile.delete();
-        if (server == null) {
-            server = new Thread(new Runnable() {
-                public void run() {
-                    try {
-                        main.runMain(getArgs());
-                    } catch (IOException e) {
-                        throw new RuntimeException(e);
-                    }
+    @BeforeClass
+    public static void setUpOnce() throws IOException {
+        server = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    main.runMain(args);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
                 }
-            });
-            server.start();
-        }
+            }
+        });
+        server.start();
     }
 
     @AfterClass
@@ -398,8 +395,11 @@ public class HtmlUnitLocalStorageTest {
         main.stop();
     }
 
-    protected String[] getArgs() {
-        return args;
+    @Before
+    public void setUp() {
+        File jsonFile = new File(getReportDir() + "/jscoverage.json");
+        if (jsonFile.exists())
+            jsonFile.delete();
     }
 
     protected String getTestUrl() {
diff --git a/src/test-acceptance/java/jscover/server/HtmlUnitMergeTest.java b/src/test-acceptance/java/jscover/server/HtmlUnitMergeTest.java
index 7112e5b..04572d8 100644
--- a/src/test-acceptance/java/jscover/server/HtmlUnitMergeTest.java
+++ b/src/test-acceptance/java/jscover/server/HtmlUnitMergeTest.java
@@ -351,7 +351,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage;
 import jscover.Main;
 import jscover.util.IoUtils;
 import org.junit.AfterClass;
-import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import java.io.File;
@@ -366,10 +366,8 @@ import static org.junit.Assert.assertEquals;
 public class HtmlUnitMergeTest {
     private static Thread server;
     private static Main main = new Main();
-
-    private IoUtils ioUtils = IoUtils.getInstance();
-    private String reportDir = "target/ws-merge-report";
-    private String[] args = new String[]{
+    private static String reportDir = "target/ws-merge-report";
+    private static String[] args = new String[]{
             "-ws",
             "--document-root=src/test-integration/resources/jsSearch",
             "--port=9001",
@@ -378,20 +376,20 @@ public class HtmlUnitMergeTest {
             "--report-dir=" + reportDir
     };
 
-    @Before
-    public void setUp() throws IOException {
-        if (server == null) {
-            server = new Thread(new Runnable() {
-                public void run() {
-                    try {
-                        main.runMain(args);
-                    } catch (IOException e) {
-                        throw new RuntimeException(e);
-                    }
+    private IoUtils ioUtils = IoUtils.getInstance();
+
+    @BeforeClass
+    public static void setUpOnce() throws IOException {
+        server = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    main.runMain(args);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
                 }
-            });
-            server.start();
-        }
+            }
+        });
+        server.start();
     }
 
     @AfterClass
diff --git a/src/test-acceptance/java/jscover/server/HtmlUnitProxyTest.java b/src/test-acceptance/java/jscover/server/HtmlUnitProxyTest.java
index c82057b..d00acb3 100644
--- a/src/test-acceptance/java/jscover/server/HtmlUnitProxyTest.java
+++ b/src/test-acceptance/java/jscover/server/HtmlUnitProxyTest.java
@@ -347,6 +347,7 @@ import jscover.Main;
 import jscover.util.IoUtils;
 import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 
 import java.io.File;
 import java.io.IOException;
@@ -359,8 +360,9 @@ public class HtmlUnitProxyTest extends HtmlUnitServerTest {
     private static Main main = new Main();
     private static ServerSocket serverSocket;
     private static int proxyPort = 3129;
+    private static String reportDir = "target/proxy-report";
 
-    private String[] args = new String[]{
+    private static String[] args = new String[]{
             "-ws",
             "--document-root=src/test-acceptance/resources",
             "--port="+proxyPort,
@@ -368,49 +370,41 @@ public class HtmlUnitProxyTest extends HtmlUnitServerTest {
             "--no-branch",
             "--no-function",
             "--no-instrument=example/lib",
-            "--report-dir=" + getReportDir()
+            "--report-dir=" + reportDir
     };
 
     @Override
     protected String getReportDir() {
-        return "target/proxy-report";
+        return reportDir;
     }
 
-    @Before
-    public void setUp() throws IOException {
-        if (proxyServer == null) {
-            proxyServer = new Thread(new Runnable() {
-                public void run() {
-                    try {
-                        main.runMain(args);
-                    } catch (IOException e) {
-                        throw new RuntimeException(e);
-                    }
+    @BeforeClass
+    public static void setUpOnce() throws IOException {
+        proxyServer = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    main.runMain(args);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
                 }
-            });
-            proxyServer.start();
-        }
-        if (webServer == null) {
-            webServer = new Thread(new Runnable() {
-                public void run() {
-                    try {
-                        serverSocket = new ServerSocket(9001);
-                        File wwwRoot = new File("src/test-acceptance/resources");
-                        while (true) {
-                            Socket socket = serverSocket.accept();
-                            (new HttpServer(socket, wwwRoot, "testVersion")).start();
-                        }
-                    } catch (IOException e) {
-                        //throw new RuntimeException(e);
+            }
+        });
+        proxyServer.start();
+        webServer = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    serverSocket = new ServerSocket(9001);
+                    File wwwRoot = new File("src/test-acceptance/resources");
+                    while (true) {
+                        Socket socket = serverSocket.accept();
+                        (new HttpServer(socket, wwwRoot, "testVersion")).start();
                     }
+                } catch (IOException e) {
+                    //throw new RuntimeException(e);
                 }
-            });
-            webServer.start();
-        }
-        ProxyConfig proxyConfig = new ProxyConfig("localhost", proxyPort);
-        proxyConfig.addHostsToProxyBypass("127.0.0.1");
-        webClient.getOptions().setProxyConfig(proxyConfig);
-        webClient.getOptions().setTimeout(1000);
+            }
+        });
+        webServer.start();
     }
 
     @AfterClass
@@ -419,6 +413,14 @@ public class HtmlUnitProxyTest extends HtmlUnitServerTest {
         IoUtils.getInstance().closeQuietly(serverSocket);
     }
 
+    @Before
+    public void setUp() {
+        ProxyConfig proxyConfig = new ProxyConfig("localhost", proxyPort);
+        proxyConfig.addHostsToProxyBypass("127.0.0.1");
+        webClient.getOptions().setProxyConfig(proxyConfig);
+        webClient.getOptions().setTimeout(1000);
+    }
+
     @Override
     protected String getTestUrl() {
         return "http://localhost:9001/"+super.getTestUrl();
diff --git a/src/test-acceptance/java/jscover/server/HtmlUnitServerBranchAndFunctionTest.java b/src/test-acceptance/java/jscover/server/HtmlUnitServerBranchAndFunctionTest.java
index fb2a839..0fe8175 100644
--- a/src/test-acceptance/java/jscover/server/HtmlUnitServerBranchAndFunctionTest.java
+++ b/src/test-acceptance/java/jscover/server/HtmlUnitServerBranchAndFunctionTest.java
@@ -350,7 +350,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlTable;
 import com.gargoylesoftware.htmlunit.html.HtmlTableCell;
 import jscover.Main;
 import org.junit.AfterClass;
-import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import java.io.IOException;
@@ -362,30 +362,27 @@ import static org.hamcrest.Matchers.equalTo;
 public class HtmlUnitServerBranchAndFunctionTest extends HtmlUnitServerTest {
     private static Thread server;
     private static Main main = new Main();
-
-    protected String[] args = new String[]{
+    private static String reportDir = "target/ws-branch-report";
+    protected static String[] args = new String[]{
             "-ws",
             "--document-root=src/test-acceptance/resources",
             "--port=9001",
             "--no-instrument=example/lib",
-            "--report-dir=" + getReportDir()
+            "--report-dir=" + reportDir
     };
 
-    @Before
-    public void setUp() throws IOException {
-        if (server == null) {
-            server = new Thread(new Runnable() {
-                public void run() {
-                    try {
-                        main.runMain(getArgs());
-                    } catch (IOException e) {
-                        throw new RuntimeException(e);
-                    }
+    @BeforeClass
+    public static void setUpOnce() throws IOException {
+        server = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    main.runMain(args);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
                 }
-            });
-            server.start();
-        }
-        webClient.getOptions().setTimeout(1000);
+            }
+        });
+        server.start();
     }
 
     @AfterClass
@@ -394,8 +391,8 @@ public class HtmlUnitServerBranchAndFunctionTest extends HtmlUnitServerTest {
     }
 
     @Override
-    protected String[] getArgs() {
-        return args;
+    protected String getReportDir() {
+        return reportDir;
     }
 
     @Test
diff --git a/src/test-acceptance/java/jscover/server/HtmlUnitServerTest.java b/src/test-acceptance/java/jscover/server/HtmlUnitServerTest.java
index a0e3d72..9906140 100644
--- a/src/test-acceptance/java/jscover/server/HtmlUnitServerTest.java
+++ b/src/test-acceptance/java/jscover/server/HtmlUnitServerTest.java
@@ -353,6 +353,7 @@ import jscover.Main;
 import jscover.util.IoUtils;
 import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import java.io.File;
@@ -366,38 +367,35 @@ import static org.junit.Assert.assertEquals;
 public class HtmlUnitServerTest {
     private static Thread server;
     private static Main main = new Main();
-
-    protected WebClient webClient = new WebClient();
-    protected IoUtils ioUtils = IoUtils.getInstance();
-    private String[] args = new String[]{
+    private static String reportDir = "target/ws-report";
+    private static String[] args = new String[]{
             "-ws",
             "--document-root=src/test-acceptance/resources",
             "--port=9001",
             "--no-branch",
             "--no-function",
             "--no-instrument=example/lib",
-            "--report-dir=" + getReportDir()
+            "--report-dir=" + reportDir
     };
 
+    protected WebClient webClient = new WebClient();
+    protected IoUtils ioUtils = IoUtils.getInstance();
     protected String getReportDir() {
-        return "target/ws-report";
+        return reportDir;
     }
 
-    @Before
-    public void setUp() throws IOException {
-        if (server == null) {
-            server = new Thread(new Runnable() {
-                public void run() {
-                    try {
-                        main.runMain(getArgs());
-                    } catch (IOException e) {
-                        throw new RuntimeException(e);
-                    }
+    @BeforeClass
+    public static void setUpOnce() throws IOException {
+        server = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    main.runMain(args);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
                 }
-            });
-            server.start();
-        }
-        webClient.getOptions().setTimeout(1000);
+            }
+        });
+        server.start();
     }
 
     @AfterClass
@@ -405,8 +403,9 @@ public class HtmlUnitServerTest {
         main.stop();
     }
 
-    protected String[] getArgs() {
-        return args;
+    @Before
+    public void setUp() {
+        webClient.getOptions().setTimeout(1000);
     }
 
     protected String getTestUrl() {
diff --git a/src/test-acceptance/java/jscover/server/WebDaemonTest.java b/src/test-acceptance/java/jscover/server/WebDaemonTest.java
index 6cecae5..7c69073 100644
--- a/src/test-acceptance/java/jscover/server/WebDaemonTest.java
+++ b/src/test-acceptance/java/jscover/server/WebDaemonTest.java
@@ -23,18 +23,16 @@ public class WebDaemonTest {
 
     @Before
     public void setUp() throws IOException {
-        if (server == null) {
-            server = new Thread(new Runnable() {
-                public void run() {
-                    try {
-                        main.runMain(args);
-                    } catch (IOException e) {
-                        throw new RuntimeException(e);
-                    }
+        server = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    main.runMain(args);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
                 }
-            });
-            server.start();
-        }
+            }
+        });
+        server.start();
     }
 
     @Test
@@ -45,5 +43,4 @@ public class WebDaemonTest {
         server.join(1000);
         assertThat(server.getState(), equalTo(Thread.State.TERMINATED));
     }
-
 }
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jscover.git



More information about the pkg-java-commits mailing list