DRILL-1879: Unit test failures on Windows
diff --git a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
index f75a574..17bcb79 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
@@ -18,26 +18,15 @@
 package org.apache.drill;
 
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.Array;
 import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import com.google.common.base.Joiner;
-import com.google.common.base.Strings;
-
 import org.apache.drill.common.config.DrillConfig;
-import org.apache.drill.common.types.TypeProtos;
-import org.apache.drill.common.types.Types;
 import org.apache.drill.common.util.TestTools;
 import org.apache.drill.exec.ExecConstants;
 import org.apache.drill.exec.ExecTest;
@@ -50,11 +39,7 @@
 import org.apache.drill.exec.memory.TopLevelAllocator;
 import org.apache.drill.exec.proto.UserBitShared.QueryId;
 import org.apache.drill.exec.proto.UserBitShared.QueryType;
-import org.apache.drill.exec.record.BatchSchema;
-import org.apache.drill.exec.record.HyperVectorWrapper;
-import org.apache.drill.exec.record.MaterializedField;
 import org.apache.drill.exec.record.RecordBatchLoader;
-import org.apache.drill.exec.record.VectorWrapper;
 import org.apache.drill.exec.rpc.RpcException;
 import org.apache.drill.exec.rpc.user.ConnectionThrottle;
 import org.apache.drill.exec.rpc.user.QueryResultBatch;
@@ -62,10 +47,7 @@
 import org.apache.drill.exec.server.Drillbit;
 import org.apache.drill.exec.server.RemoteServiceSet;
 import org.apache.drill.exec.util.VectorUtil;
-import org.apache.drill.exec.vector.ValueVector;
-import org.apache.hadoop.io.Text;
 import org.junit.AfterClass;
-import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.rules.TestRule;
 import org.junit.rules.TestWatcher;
@@ -74,9 +56,6 @@
 import com.google.common.base.Charsets;
 import com.google.common.io.Resources;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
 public class BaseTestQuery extends ExecTest{
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BaseTestQuery.class);
 
@@ -180,19 +159,19 @@
   }
 
   public static List<QueryResultBatch>  testRunAndReturn(QueryType type, String query) throws Exception{
-    query = query.replace("[WORKING_PATH]", TestTools.getWorkingPath());
+    query = normalizeQuery(query);
     return client.runQuery(type, query);
   }
 
   public static int testRunAndPrint(QueryType type, String query) throws Exception{
-    query = query.replace("[WORKING_PATH]", TestTools.getWorkingPath());
+    query = normalizeQuery(query);
     PrintingResultsListener resultListener = new PrintingResultsListener(client.getConfig(), Format.TSV, VectorUtil.DEFAULT_COLUMN_WIDTH);
     client.runQuery(type, query, resultListener);
     return resultListener.await();
   }
 
   protected void testWithListener(QueryType type, String query, UserResultsListener resultListener) {
-    query = query.replace("[WORKING_PATH]", TestTools.getWorkingPath());
+    query = normalizeQuery(query);
     client.runQuery(type, query, resultListener);
   }
 
@@ -216,7 +195,7 @@
   }
 
   public static void test(String query) throws Exception{
-    query = query.replaceAll(Pattern.quote("${WORKING_PATH}"), TestTools.getWorkingPath());
+    query = normalizeQuery(query);
     String[] queries = query.split(";");
     for (String q : queries) {
       if (q.trim().isEmpty()) {
@@ -226,6 +205,15 @@
     }
   }
 
+  public static String normalizeQuery(String query) {
+    if (query.contains("${WORKING_PATH}")) {
+      return query.replaceAll(Pattern.quote("${WORKING_PATH}"), Matcher.quoteReplacement(TestTools.getWorkingPath()));
+    } else if (query.contains("[WORKING_PATH]")) {
+      return query.replaceAll(Pattern.quote("[WORKING_PATH]"), Matcher.quoteReplacement(TestTools.getWorkingPath()));
+    }
+    return query;
+  }
+
   protected int testLogical(String query) throws Exception{
     return testRunAndPrint(QueryType.LOGICAL, query);
   }
diff --git a/exec/java-exec/src/test/java/org/apache/drill/PlanTestBase.java b/exec/java-exec/src/test/java/org/apache/drill/PlanTestBase.java
index 580a1f0..c52545d 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/PlanTestBase.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/PlanTestBase.java
@@ -47,7 +47,7 @@
    */
   public void testPhysicalPlan(String sql, String... expectedSubstrs)
       throws Exception {
-    sql = "EXPLAIN PLAN for " + sql.replace("[WORKING_PATH]", TestTools.getWorkingPath());
+    sql = "EXPLAIN PLAN for " + normalizeQuery(sql);
 
     String planStr = getPlanInString(sql, JSON_FORMAT);
 
@@ -184,7 +184,7 @@
     }
 
     sql = "EXPLAIN PLAN " + levelStr + " " + depthStr + "  for "
-        + sql.replace("[WORKING_PATH]", TestTools.getWorkingPath());
+        + normalizeQuery(sql);
 
     return getPlanInString(sql, OPTIQ_FORMAT);
   }
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestBuilder.java b/exec/java-exec/src/test/java/org/apache/drill/TestBuilder.java
index 99cf707..978e565 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestBuilder.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestBuilder.java
@@ -124,7 +124,7 @@
   }
 
   public TestBuilder sqlQuery(String query) {
-    this.query = query.replaceAll(Pattern.quote("${WORKING_PATH}"), TestTools.getWorkingPath());
+    this.query = BaseTestQuery.normalizeQuery(query);
     this.queryType = UserBitShared.QueryType.SQL;
     return this;
   }