Index: contrib/analyzers/common/src/test/org/apache/lucene/analysis/compound/TestCompoundWordTokenFilter.java
===================================================================
--- contrib/analyzers/common/src/test/org/apache/lucene/analysis/compound/TestCompoundWordTokenFilter.java	(revision 922799)
+++ contrib/analyzers/common/src/test/org/apache/lucene/analysis/compound/TestCompoundWordTokenFilter.java	(working copy)
@@ -30,9 +30,6 @@
 import org.apache.lucene.analysis.tokenattributes.TermAttribute;
 
 public class TestCompoundWordTokenFilter extends BaseTokenStreamTestCase {
-  static final File dataDir = new File(System.getProperty("dataDir", "./bin"));
-  static final File testFile = new File(dataDir, "org/apache/lucene/analysis/compound/da_UTF8.xml");
-
   public void testHyphenationCompoundWordsDA() throws Exception {
     String[] dict = { "læse", "hest" };
 
@@ -143,6 +140,6 @@
   }
 
   private Reader getHyphenationReader() throws Exception {
-    return new InputStreamReader(new FileInputStream(testFile), "UTF-8");
+    return new InputStreamReader(getClass().getResourceAsStream("da_UTF8.xml"), "UTF-8");
   }
 }
Index: contrib/analyzers/common/src/test/org/apache/lucene/analysis/cz/TestCzechAnalyzer.java
===================================================================
--- contrib/analyzers/common/src/test/org/apache/lucene/analysis/cz/TestCzechAnalyzer.java	(revision 922799)
+++ contrib/analyzers/common/src/test/org/apache/lucene/analysis/cz/TestCzechAnalyzer.java	(working copy)
@@ -35,8 +35,6 @@
  *
  */
 public class TestCzechAnalyzer extends BaseTokenStreamTestCase {
-  File dataDir = new File(System.getProperty("dataDir", "./bin"));
-  File customStopFile = new File(dataDir, "org/apache/lucene/analysis/cz/customStopWordFile.txt");
   
   /**
    * @deprecated Remove this test when support for 3.0 indexes is no longer needed.
@@ -105,7 +103,7 @@
     assertAnalyzesToReuse(cz, "Česká Republika", 
       new String[] { "česká", "republika" });
     
-    InputStream stopwords = new FileInputStream(customStopFile);
+    InputStream stopwords = getClass().getResourceAsStream("customStopWordFile.txt");
     cz.loadStopWords(stopwords, "UTF-8");
     
     assertAnalyzesToReuse(cz, "Česká Republika", new String[] { "česká" });
Index: contrib/analyzers/common/src/test/org/apache/lucene/analysis/de/TestGermanStemFilter.java
===================================================================
--- contrib/analyzers/common/src/test/org/apache/lucene/analysis/de/TestGermanStemFilter.java	(revision 922799)
+++ contrib/analyzers/common/src/test/org/apache/lucene/analysis/de/TestGermanStemFilter.java	(working copy)
@@ -41,10 +41,7 @@
     Tokenizer tokenizer = new KeywordTokenizer(new StringReader(""));
     TokenFilter filter = new GermanStemFilter(new LowerCaseFilter(TEST_VERSION_CURRENT, tokenizer));
     // read test cases from external file:
-    File dataDir = new File(System.getProperty("dataDir", "./bin"));
-    File testFile = new File(dataDir, "org/apache/lucene/analysis/de/data.txt");
-    FileInputStream fis = new FileInputStream(testFile);
-    InputStreamReader isr = new InputStreamReader(fis, "iso-8859-1");
+    InputStreamReader isr = new InputStreamReader(getClass().getResourceAsStream("data.txt"), "iso-8859-1");
     BufferedReader breader = new BufferedReader(isr);
     while(true) {
       String line = breader.readLine();
@@ -61,6 +58,5 @@
     }
     breader.close();
     isr.close();
-    fis.close();
   }
 }
Index: contrib/analyzers/common/src/test/org/apache/lucene/analysis/nl/TestDutchStemmer.java
===================================================================
--- contrib/analyzers/common/src/test/org/apache/lucene/analysis/nl/TestDutchStemmer.java	(revision 922799)
+++ contrib/analyzers/common/src/test/org/apache/lucene/analysis/nl/TestDutchStemmer.java	(working copy)
@@ -32,8 +32,6 @@
  * 
  */
 public class TestDutchStemmer extends BaseTokenStreamTestCase {
-  File dataDir = new File(System.getProperty("dataDir", "./bin"));
-  File customDictFile = new File(dataDir, "org/apache/lucene/analysis/nl/customStemDict.txt");
   
   public void testWithSnowballExamples() throws Exception {
 	 check("lichaamsziek", "lichaamsziek");
@@ -172,6 +170,7 @@
   public void testStemDictionaryReuse() throws Exception {
     DutchAnalyzer a = new DutchAnalyzer(TEST_VERSION_CURRENT);
     checkOneTermReuse(a, "lichamelijk", "licham");
+    File customDictFile = getDataFile("customStemDict.txt");
     a.setStemDictionary(customDictFile);
     checkOneTermReuse(a, "lichamelijk", "somethingentirelydifferent");
   }
Index: contrib/analyzers/common/src/test/org/apache/lucene/analysis/ru/TestRussianAnalyzer.java
===================================================================
--- contrib/analyzers/common/src/test/org/apache/lucene/analysis/ru/TestRussianAnalyzer.java	(revision 922799)
+++ contrib/analyzers/common/src/test/org/apache/lucene/analysis/ru/TestRussianAnalyzer.java	(working copy)
@@ -41,14 +41,6 @@
 
     private InputStreamReader sampleUnicode;
 
-    private File dataDir;
-
-    @Override
-    protected void setUp() throws Exception {
-      super.setUp();
-      dataDir = new File(System.getProperty("dataDir", "./bin"));
-    }
-
     /**
      * @deprecated remove this test and its datafiles in Lucene 4.0
      * the Snowball version has its own data tests.
@@ -59,12 +51,12 @@
         RussianAnalyzer ra = new RussianAnalyzer(Version.LUCENE_30);
         inWords =
             new InputStreamReader(
-                new FileInputStream(new File(dataDir, "/org/apache/lucene/analysis/ru/testUTF8.txt")),
+                getClass().getResourceAsStream("testUTF8.txt"),
                 "UTF-8");
 
         sampleUnicode =
             new InputStreamReader(
-                new FileInputStream(new File(dataDir, "/org/apache/lucene/analysis/ru/resUTF8.htm")),
+                getClass().getResourceAsStream("resUTF8.htm"),
                 "UTF-8");
 
         TokenStream in = ra.tokenStream("all", inWords);
Index: contrib/analyzers/common/src/test/org/apache/lucene/analysis/ru/TestRussianStem.java
===================================================================
--- contrib/analyzers/common/src/test/org/apache/lucene/analysis/ru/TestRussianStem.java	(revision 922799)
+++ contrib/analyzers/common/src/test/org/apache/lucene/analysis/ru/TestRussianStem.java	(working copy)
@@ -47,13 +47,11 @@
         //System.out.println(new java.util.Date());
         String str;
         
-        File dataDir = new File(System.getProperty("dataDir", "./bin"));
-
         // open and read words into an array list
         BufferedReader inWords =
             new BufferedReader(
                 new InputStreamReader(
-                    new FileInputStream(new File(dataDir, "/org/apache/lucene/analysis/ru/wordsUTF8.txt")),
+                    getClass().getResourceAsStream("wordsUTF8.txt"),
                     "UTF-8"));
         while ((str = inWords.readLine()) != null)
         {
@@ -65,7 +63,7 @@
         BufferedReader inStems =
             new BufferedReader(
                 new InputStreamReader(
-                    new FileInputStream(new File(dataDir, "/org/apache/lucene/analysis/ru/stemsUTF8.txt")),
+                    getClass().getResourceAsStream("stemsUTF8.txt"),
                     "UTF-8"));
         while ((str = inStems.readLine()) != null)
         {
Index: contrib/analyzers/common/src/test/org/apache/lucene/analysis/snowball/TestSnowballVocab.java
===================================================================
--- contrib/analyzers/common/src/test/org/apache/lucene/analysis/snowball/TestSnowballVocab.java	(revision 922799)
+++ contrib/analyzers/common/src/test/org/apache/lucene/analysis/snowball/TestSnowballVocab.java	(working copy)
@@ -35,18 +35,24 @@
  */
 public class TestSnowballVocab extends BaseTokenStreamTestCase {
   private Tokenizer tokenizer = new KeywordTokenizer(new StringReader(""));
-  static final File dataDir = new File(System.getProperty("dataDir", "./bin"));
-  static final File dataRoot = new File(dataDir, 
-      "org/apache/lucene/analysis/snowball/data");
+  File dataRoot = null;
   
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    try {
+      dataRoot = getDataFile("data");
+    } catch (IOException ioe) {
+      dataRoot = null;
+      System.err.println("WARN: This test was disabled, as the svn checkout of snowball test files is not supported on your system!");
+    }
+  }
+  
   /**
    * Run all languages against their snowball vocabulary tests.
    */
   public void testStemmers() throws IOException {
-    if (!dataRoot.exists()) {
-      System.err.println("WARN: This test was disabled, as the svn checkout of snowball test files is not supported on your system!");
-      return;
-    }
+    if (dataRoot == null) return;
     assertCorrectOutput("Danish", "danish");
     assertCorrectOutput("Dutch", "dutch");
     assertCorrectOutput("English", "english");
Index: contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
===================================================================
--- contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java	(revision 922799)
+++ contrib/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java	(working copy)
@@ -378,7 +378,7 @@
    * Test WriteLineDoc and LineDocSource.
    */
   public void testLineDocFile() throws Exception {
-    File lineFile = new File(System.getProperty("tempDir"), "test.reuters.lines.txt");
+    File lineFile = new File(TEMP_DIR, "test.reuters.lines.txt");
 
     // We will call WriteLineDocs this many times
     final int NUM_TRY_DOCS = 50;
Index: contrib/db/bdb-je/src/test/org/apache/lucene/store/je/JEStoreTest.java
===================================================================
--- contrib/db/bdb-je/src/test/org/apache/lucene/store/je/JEStoreTest.java	(revision 922799)
+++ contrib/db/bdb-je/src/test/org/apache/lucene/store/je/JEStoreTest.java	(working copy)
@@ -46,7 +46,7 @@
  *
  */
 public class JEStoreTest extends LuceneTestCase {
-    protected File dbHome = new File(System.getProperty("java.io.tmpdir"),"index");
+    protected File dbHome = new File(TEMP_DIR,"index");
 
     protected Environment env;
 
Index: contrib/db/bdb/src/test/org/apache/lucene/store/db/DbStoreTest.java
===================================================================
--- contrib/db/bdb/src/test/org/apache/lucene/store/db/DbStoreTest.java	(revision 922799)
+++ contrib/db/bdb/src/test/org/apache/lucene/store/db/DbStoreTest.java	(working copy)
@@ -43,7 +43,7 @@
  * Adapted from org.apache.lucene.StoreTest with larger files and random bytes.
  */
 public class DbStoreTest extends LuceneTestCase {
-    protected File dbHome = new File(System.getProperty("java.io.tmpdir"),"index");
+    protected File dbHome = new File(TEMP_DIR,"index");
     protected Environment env;
     protected Database index, blocks;
     
Index: contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
===================================================================
--- contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java	(revision 922799)
+++ contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java	(working copy)
@@ -51,6 +51,7 @@
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Similarity;
 import org.apache.lucene.store.RAMDirectory; // for javadocs
+import org.apache.lucene.util.Constants; // for javadocs
 
 /**
  * High-performance single-document main memory Apache Lucene fulltext search index. 
@@ -1207,7 +1208,7 @@
   ///////////////////////////////////////////////////////////////////////////////
   private static final class VM {
         
-    public static final int PTR = is64BitVM() ? 8 : 4;    
+    public static final int PTR = Constants.JRE_IS_64BIT ? 8 : 4;    
 
     // bytes occupied by primitive data types
     public static final int BOOLEAN = 1;
@@ -1272,18 +1273,6 @@
         return sizeOfObject(PTR + INT) + sizeOfIntArray(len);
     }
     
-    private static boolean is64BitVM() {
-        try {
-            int bits = Integer.getInteger("sun.arch.data.model", 0).intValue();
-            if (bits != 0) return bits == 64;
-
-            // fallback if sun.arch.data.model isn't available
-            return System.getProperty("java.vm.name").toLowerCase().indexOf("64") >= 0;
-        } catch (Throwable t) {
-            return false; // better safe than sorry (applets, security managers, etc.) ...
-        }
-    }
-    
     /** logarithm to the base 2. Example: log2(4) == 2, log2(8) == 3 */
     private static double log2(double value) {
       return Math.log(value) / Math.log(2);
Index: contrib/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java
===================================================================
--- contrib/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java	(revision 922799)
+++ contrib/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java	(working copy)
@@ -27,11 +27,10 @@
 
 public class TestIndexSplitter extends LuceneTestCase {
   public void test() throws Exception {
-    String tmpDir = System.getProperty("java.io.tmpdir");
-    File dir = new File(tmpDir, "testfilesplitter");
+    File dir = new File(TEMP_DIR, "testfilesplitter");
     _TestUtil.rmDir(dir);
     dir.mkdirs();
-    File destDir = new File(tmpDir, "testfilesplitterdest");
+    File destDir = new File(TEMP_DIR, "testfilesplitterdest");
     _TestUtil.rmDir(destDir);
     destDir.mkdirs();
     FSDirectory fsDir = FSDirectory.open(dir);
@@ -61,7 +60,7 @@
     assertEquals(50, r.maxDoc());
     
     // now test cmdline
-    File destDir2 = new File(tmpDir, "testfilesplitterdest2");
+    File destDir2 = new File(TEMP_DIR, "testfilesplitterdest2");
     _TestUtil.rmDir(destDir2);
     destDir2.mkdirs();
     IndexSplitter.main(new String[] {dir.getAbsolutePath(), destDir2.getAbsolutePath(), splitSegName});
Index: contrib/wordnet/src/test/org/apache/lucene/wordnet/TestSynonymTokenFilter.java
===================================================================
--- contrib/wordnet/src/test/org/apache/lucene/wordnet/TestSynonymTokenFilter.java	(revision 922799)
+++ contrib/wordnet/src/test/org/apache/lucene/wordnet/TestSynonymTokenFilter.java	(working copy)
@@ -30,11 +30,10 @@
 import org.apache.lucene.analysis.BaseTokenStreamTestCase;
 
 public class TestSynonymTokenFilter extends BaseTokenStreamTestCase {
-  File dataDir = new File(System.getProperty("dataDir", "./bin"));
-  File testFile = new File(dataDir, "org/apache/lucene/wordnet/testSynonyms.txt");
+  final String testFile = "testSynonyms.txt";
   
   public void testSynonyms() throws Exception {
-    SynonymMap map = new SynonymMap(new FileInputStream(testFile));
+    SynonymMap map = new SynonymMap(getClass().getResourceAsStream(testFile));
     /* all expansions */
     Analyzer analyzer = new SynonymWhitespaceAnalyzer(map, Integer.MAX_VALUE);
     assertAnalyzesTo(analyzer, "Lost in the woods",
@@ -45,7 +44,7 @@
   }
   
   public void testSynonymsSingleQuote() throws Exception {
-    SynonymMap map = new SynonymMap(new FileInputStream(testFile));
+    SynonymMap map = new SynonymMap(getClass().getResourceAsStream(testFile));
     /* all expansions */
     Analyzer analyzer = new SynonymWhitespaceAnalyzer(map, Integer.MAX_VALUE);
     assertAnalyzesTo(analyzer, "king",
@@ -53,7 +52,7 @@
   }
   
   public void testSynonymsLimitedAmount() throws Exception {
-    SynonymMap map = new SynonymMap(new FileInputStream(testFile));
+    SynonymMap map = new SynonymMap(getClass().getResourceAsStream(testFile));
     /* limit to one synonym expansion */
     Analyzer analyzer = new SynonymWhitespaceAnalyzer(map, 1);
     assertAnalyzesTo(analyzer, "Lost in the woods",
@@ -67,7 +66,7 @@
   }
   
   public void testReusableTokenStream() throws Exception {
-    SynonymMap map = new SynonymMap(new FileInputStream(testFile));
+    SynonymMap map = new SynonymMap(getClass().getResourceAsStream(testFile));
     /* limit to one synonym expansion */
     Analyzer analyzer = new SynonymWhitespaceAnalyzer(map, 1);
     assertAnalyzesToReuse(analyzer, "Lost in the woods",
Index: contrib/wordnet/src/test/org/apache/lucene/wordnet/TestWordnet.java
===================================================================
--- contrib/wordnet/src/test/org/apache/lucene/wordnet/TestWordnet.java	(revision 922799)
+++ contrib/wordnet/src/test/org/apache/lucene/wordnet/TestWordnet.java	(working copy)
@@ -33,17 +33,15 @@
 
 public class TestWordnet extends LuceneTestCase {
   private Searcher searcher;
-  
-  File dataDir = new File(System.getProperty("dataDir", "./bin"));
-  File testFile = new File(dataDir, "org/apache/lucene/wordnet/testSynonyms.txt");
-  
+    
   String storePathName = 
-    new File(System.getProperty("tempDir"),"testLuceneWordnet").getAbsolutePath();
+    new File(TEMP_DIR,"testLuceneWordnet").getAbsolutePath();
   
   @Override
   protected void setUp() throws Exception {
     super.setUp();
     // create a temporary synonym index
+    File testFile = getDataFile("testSynonyms.txt");
     String commandLineArgs[] = { testFile.getAbsolutePath(), storePathName };
     
     try {
Index: src/test/org/apache/lucene/analysis/TestPorterStemFilter.java
===================================================================
--- src/test/org/apache/lucene/analysis/TestPorterStemFilter.java	(revision 922799)
+++ src/test/org/apache/lucene/analysis/TestPorterStemFilter.java	(working copy)
@@ -36,8 +36,7 @@
   public void testPorterStemFilter() throws Exception {
     Tokenizer tokenizer = new KeywordTokenizer(new StringReader(""));
     TokenStream filter = new PorterStemFilter(tokenizer);   
-    ZipFile zipFile = new ZipFile(
-        new File(getClass().getResource("porterTestData.zip").toURI()));
+    ZipFile zipFile = new ZipFile(getDataFile("porterTestData.zip"));
     InputStream voc = zipFile.getInputStream(zipFile.getEntry("voc.txt"));
     InputStream out = zipFile.getInputStream(zipFile.getEntry("output.txt"));
     BufferedReader vocReader = new BufferedReader(new InputStreamReader(
Index: src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
===================================================================
--- src/test/org/apache/lucene/index/TestBackwardsCompatibility.java	(revision 922799)
+++ src/test/org/apache/lucene/index/TestBackwardsCompatibility.java	(working copy)
@@ -623,7 +623,7 @@
   }
 
   public static String fullDir(String dirName) throws IOException {
-    return new File(System.getProperty("tempDir"), dirName).getCanonicalPath();
+    return new File(TEMP_DIR, dirName).getCanonicalPath();
   }
 
   static final String TEXT_TO_COMPRESS = "this is a compressed field and should appear in 3.0 as an uncompressed field after merge";
Index: src/test/org/apache/lucene/index/TestCompoundFile.java
===================================================================
--- src/test/org/apache/lucene/index/TestCompoundFile.java	(revision 922799)
+++ src/test/org/apache/lucene/index/TestCompoundFile.java	(working copy)
@@ -57,7 +57,7 @@
     @Override
     protected void setUp() throws Exception {
        super.setUp();
-       File file = new File(System.getProperty("tempDir"), "testIndex");
+       File file = new File(TEMP_DIR, "testIndex");
        _TestUtil.rmDir(file);
        // use a simple FSDir here, to be sure to have SimpleFSInputs
        dir = new SimpleFSDirectory(file,null);
Index: src/test/org/apache/lucene/index/TestDoc.java
===================================================================
--- src/test/org/apache/lucene/index/TestDoc.java	(revision 922799)
+++ src/test/org/apache/lucene/index/TestDoc.java	(working copy)
@@ -58,7 +58,7 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        workDir = new File(System.getProperty("tempDir"),"TestDoc");
+        workDir = new File(TEMP_DIR,"TestDoc");
         workDir.mkdirs();
 
         indexDir = new File(workDir, "testIndex");
Index: src/test/org/apache/lucene/index/TestFieldsReader.java
===================================================================
--- src/test/org/apache/lucene/index/TestFieldsReader.java	(revision 922799)
+++ src/test/org/apache/lucene/index/TestFieldsReader.java	(working copy)
@@ -210,10 +210,8 @@
    * @throws Exception
    */
   public void testLazyPerformance() throws Exception {
-    String tmpIODir = System.getProperty("tempDir");
     String userName = System.getProperty("user.name");
-    String path = tmpIODir + File.separator + "lazyDir" + userName;
-    File file = new File(path);
+    File file = new File(TEMP_DIR, "lazyDir" + userName);
     _TestUtil.rmDir(file);
     FSDirectory tmpDir = FSDirectory.open(file);
     assertTrue(tmpDir != null);
@@ -391,10 +389,7 @@
 
   // LUCENE-1262
   public void testExceptions() throws Throwable {
-    String tempDir = System.getProperty("java.io.tmpdir");
-    if (tempDir == null)
-      throw new IOException("java.io.tmpdir undefined, cannot run test");
-    File indexDir = new File(tempDir, "testfieldswriterexceptions");
+    File indexDir = new File(TEMP_DIR, "testfieldswriterexceptions");
 
     try {
       Directory dir = new FaultyFSDirectory(indexDir);
Index: src/test/org/apache/lucene/index/TestIndexReader.java
===================================================================
--- src/test/org/apache/lucene/index/TestIndexReader.java	(revision 922799)
+++ src/test/org/apache/lucene/index/TestIndexReader.java	(working copy)
@@ -507,7 +507,7 @@
     // Make sure you can set norms & commit even if a reader
     // is open against the index:
     public void testWritingNorms() throws IOException {
-        File indexDir = new File(System.getProperty("tempDir"), "lucenetestnormwriter");
+        File indexDir = new File(TEMP_DIR, "lucenetestnormwriter");
         Directory dir = FSDirectory.open(indexDir);
         IndexWriter writer;
         IndexReader reader;
@@ -685,12 +685,12 @@
     }
 
   private Directory getDirectory() throws IOException {
-    return FSDirectory.open(new File(System.getProperty("tempDir"), "testIndex"));
+    return FSDirectory.open(new File(TEMP_DIR, "testIndex"));
   }
 
   public void testFilesOpenClose() throws IOException {
         // Create initial data set
-        File dirFile = new File(System.getProperty("tempDir"), "testIndex");
+        File dirFile = new File(TEMP_DIR, "testIndex");
         Directory dir = getDirectory();
         IndexWriter writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
         addDoc(writer, "test");
@@ -719,7 +719,7 @@
     }
 
     public void testLastModified() throws Exception {
-      final File fileDir = new File(System.getProperty("tempDir"), "testIndex");
+      final File fileDir = new File(TEMP_DIR, "testIndex");
       for(int i=0;i<2;i++) {
         try {
           final Directory dir;
@@ -1148,8 +1148,7 @@
     }
 
     public void testOpenReaderAfterDelete() throws IOException {
-      File dirFile = new File(System.getProperty("tempDir"),
-                          "deletetest");
+      File dirFile = new File(TEMP_DIR, "deletetest");
       Directory dir = FSDirectory.open(dirFile);
       try {
         IndexReader.open(dir, false);
Index: src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java
===================================================================
--- src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java	(revision 922799)
+++ src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java	(working copy)
@@ -82,14 +82,8 @@
    * optimize.
    */
   public void testNorms() throws IOException {
-    // tmp dir
-    String tempDir = System.getProperty("java.io.tmpdir");
-    if (tempDir == null) {
-      throw new IOException("java.io.tmpdir undefined, cannot run test");
-    }
-
     // test with a single index: index1
-    File indexDir1 = new File(tempDir, "lucenetestindex1");
+    File indexDir1 = new File(TEMP_DIR, "lucenetestindex1");
     Directory dir1 = FSDirectory.open(indexDir1);
     IndexWriter.unlock(dir1);
 
@@ -108,14 +102,14 @@
     modifiedNorms = new ArrayList<Float>();
     numDocNorms = 0;
 
-    File indexDir2 = new File(tempDir, "lucenetestindex2");
+    File indexDir2 = new File(TEMP_DIR, "lucenetestindex2");
     Directory dir2 = FSDirectory.open(indexDir2);
 
     createIndex(dir2);
     doTestNorms(dir2);
 
     // add index1 and index2 to a third index: index3
-    File indexDir3 = new File(tempDir, "lucenetestindex3");
+    File indexDir3 = new File(TEMP_DIR, "lucenetestindex3");
     Directory dir3 = FSDirectory.open(indexDir3);
 
     createIndex(dir3);
Index: src/test/org/apache/lucene/index/TestIndexReaderReopen.java
===================================================================
--- src/test/org/apache/lucene/index/TestIndexReaderReopen.java	(revision 922799)
+++ src/test/org/apache/lucene/index/TestIndexReaderReopen.java	(working copy)
@@ -1097,10 +1097,7 @@
   @Override
   protected void setUp() throws Exception {
     super.setUp();
-    String tempDir = System.getProperty("java.io.tmpdir");
-    if (tempDir == null)
-      throw new IOException("java.io.tmpdir undefined, cannot run test");
-    indexDir = new File(tempDir, "IndexReaderReopen");
+    indexDir = new File(TEMP_DIR, "IndexReaderReopen");
   }
   
   public void testCloseOrig() throws Throwable {
Index: src/test/org/apache/lucene/index/TestIndexWriter.java
===================================================================
--- src/test/org/apache/lucene/index/TestIndexWriter.java	(revision 922799)
+++ src/test/org/apache/lucene/index/TestIndexWriter.java	(working copy)
@@ -4322,7 +4322,7 @@
   // create=true does not remove non-index files
   
   public void testOtherFiles() throws Throwable {
-    File indexDir = new File(System.getProperty("tempDir"), "otherfiles");
+    File indexDir = new File(TEMP_DIR, "otherfiles");
     Directory dir = FSDirectory.open(indexDir);
     try {
       // Create my own random file:
Index: src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java
===================================================================
--- src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java	(revision 922799)
+++ src/test/org/apache/lucene/index/TestIndexWriterLockRelease.java	(working copy)
@@ -39,8 +39,7 @@
     protected void setUp() throws Exception {
         super.setUp();
         if (this.__test_dir == null) {
-            String tmp_dir = System.getProperty("java.io.tmpdir", "tmp");
-            this.__test_dir = new File(tmp_dir, "testIndexWriter");
+            this.__test_dir = new File(TEMP_DIR, "testIndexWriter");
 
             if (this.__test_dir.exists()) {
                 throw new IOException("test directory \"" + this.__test_dir.getPath() + "\" already exists (please remove by hand)");
Index: src/test/org/apache/lucene/index/TestThreadedOptimize.java
===================================================================
--- src/test/org/apache/lucene/index/TestThreadedOptimize.java	(revision 922799)
+++ src/test/org/apache/lucene/index/TestThreadedOptimize.java	(working copy)
@@ -141,12 +141,8 @@
     runTest(directory, new ConcurrentMergeScheduler());
     directory.close();
 
-    String tempDir = System.getProperty("tempDir");
-    if (tempDir == null)
-      throw new IOException("tempDir undefined, cannot run test");
-
-    String dirName = tempDir + "/luceneTestThreadedOptimize";
-    directory = FSDirectory.open(new File(dirName));
+    File dirName = new File(TEMP_DIR, "luceneTestThreadedOptimize");
+    directory = FSDirectory.open(dirName);
     runTest(directory, new SerialMergeScheduler());
     runTest(directory, new ConcurrentMergeScheduler());
     directory.close();
Index: src/test/org/apache/lucene/store/TestBufferedIndexInput.java
===================================================================
--- src/test/org/apache/lucene/store/TestBufferedIndexInput.java	(revision 922799)
+++ src/test/org/apache/lucene/store/TestBufferedIndexInput.java	(working copy)
@@ -242,7 +242,7 @@
     }
 
     public void testSetBufferSize() throws IOException {
-      File indexDir = new File(System.getProperty("tempDir"), "testSetBufferSize");
+      File indexDir = new File(TEMP_DIR, "testSetBufferSize");
       MockFSDirectory dir = new MockFSDirectory(indexDir, newRandom());
       try {
         IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
Index: src/test/org/apache/lucene/store/TestDirectory.java
===================================================================
--- src/test/org/apache/lucene/store/TestDirectory.java	(revision 922799)
+++ src/test/org/apache/lucene/store/TestDirectory.java	(working copy)
@@ -35,7 +35,7 @@
     } catch (AlreadyClosedException ace) {
     }
 
-    dir = FSDirectory.open(new File(System.getProperty("tempDir")));
+    dir = FSDirectory.open(TEMP_DIR);
     dir.close();
     try {
       dir.createOutput("test");
@@ -48,7 +48,7 @@
   // Test that different instances of FSDirectory can coexist on the same
   // path, can read, write, and lock files.
   public void testDirectInstantiation() throws Exception {
-    File path = new File(System.getProperty("tempDir"));
+    File path = new File(TEMP_DIR, "testDirectInstantiation");
 
     int sz = 3;
     Directory[] dirs = new Directory[sz];
@@ -116,11 +116,13 @@
       dir.close();
       assertFalse(dir.isOpen);
     }
+    
+    _TestUtil.rmDir(path);
   }
 
   // LUCENE-1464
   public void testDontCreate() throws Throwable {
-    File path = new File(System.getProperty("tempDir"), "doesnotexist");
+    File path = new File(TEMP_DIR, "doesnotexist");
     try {
       assertTrue(!path.exists());
       Directory dir = new SimpleFSDirectory(path, null);
@@ -138,7 +140,7 @@
 
   // LUCENE-1468
   public void testFSDirectoryFilter() throws IOException {
-    checkDirectoryFilter(FSDirectory.open(new File(System.getProperty("tempDir"),"test")));
+    checkDirectoryFilter(FSDirectory.open(new File(TEMP_DIR,"test")));
   }
 
   // LUCENE-1468
@@ -155,7 +157,7 @@
 
   // LUCENE-1468
   public void testCopySubdir() throws Throwable {
-    File path = new File(System.getProperty("tempDir"), "testsubdir");
+    File path = new File(TEMP_DIR, "testsubdir");
     try {
       path.mkdirs();
       new File(path, "subdir").mkdirs();
@@ -168,7 +170,7 @@
 
   // LUCENE-1468
   public void testNotDirectory() throws Throwable {
-    File path = new File(System.getProperty("tempDir"), "testnotdir");
+    File path = new File(TEMP_DIR, "testnotdir");
     Directory fsDir = new SimpleFSDirectory(path, null);
     try {
       IndexOutput out = fsDir.createOutput("afile");
Index: src/test/org/apache/lucene/store/TestLockFactory.java
===================================================================
--- src/test/org/apache/lucene/store/TestLockFactory.java	(revision 922799)
+++ src/test/org/apache/lucene/store/TestLockFactory.java	(working copy)
@@ -171,7 +171,7 @@
     // Verify: NativeFSLockFactory works correctly
     public void testNativeFSLockFactory() throws IOException {
 
-      NativeFSLockFactory f = new NativeFSLockFactory(System.getProperty("tempDir"));
+      NativeFSLockFactory f = new NativeFSLockFactory(TEMP_DIR);
 
       f.setLockPrefix("test");
       Lock l = f.makeLock("commit");
@@ -195,7 +195,7 @@
 
     public void testNativeFSLockReleaseByOtherLock() throws IOException {
 
-      NativeFSLockFactory f = new NativeFSLockFactory(System.getProperty("tempDir"));
+      NativeFSLockFactory f = new NativeFSLockFactory(TEMP_DIR);
 
       f.setLockPrefix("test");
       Lock l = f.makeLock("commit");
Index: src/test/org/apache/lucene/store/TestRAMDirectory.java
===================================================================
--- src/test/org/apache/lucene/store/TestRAMDirectory.java	(revision 922799)
+++ src/test/org/apache/lucene/store/TestRAMDirectory.java	(working copy)
@@ -49,10 +49,7 @@
   @Override
   protected void setUp () throws Exception {
     super.setUp();
-    String tempDir = System.getProperty("java.io.tmpdir");
-    if (tempDir == null)
-      throw new IOException("java.io.tmpdir undefined, cannot run test");
-    indexDir = new File(tempDir, "RAMDirIndex");
+    indexDir = new File(TEMP_DIR, "RAMDirIndex");
     
     Directory dir = FSDirectory.open(indexDir);
     IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
Index: src/test/org/apache/lucene/store/TestWindowsMMap.java
===================================================================
--- src/test/org/apache/lucene/store/TestWindowsMMap.java	(revision 922799)
+++ src/test/org/apache/lucene/store/TestWindowsMMap.java	(working copy)
@@ -63,7 +63,7 @@
   }
   
   private final static String storePathname = 
-    new File(System.getProperty("tempDir"),"testLuceneMmap").getAbsolutePath();
+    new File(TEMP_DIR,"testLuceneMmap").getAbsolutePath();
 
   public void testMmapIndex() throws Exception {
     FSDirectory storeDirectory;
Index: src/test/org/apache/lucene/util/_TestUtil.java
===================================================================
--- src/test/org/apache/lucene/util/_TestUtil.java	(revision 922799)
+++ src/test/org/apache/lucene/util/_TestUtil.java	(working copy)
@@ -33,10 +33,7 @@
   /** Returns temp dir, containing String arg in its name;
    *  does not create the directory. */
   public static File getTempDir(String desc) {
-    String tempDir = System.getProperty("java.io.tmpdir");
-    if (tempDir == null)
-      throw new RuntimeException("java.io.tmpdir undefined, cannot run test");
-    return new File(tempDir, desc + "." + new Random().nextLong());
+    return new File(LuceneTestCaseJ4.TEMP_DIR, desc + "." + new Random().nextLong());
   }
 
   public static void rmDir(File dir) throws IOException {
Index: src/test/org/apache/lucene/util/LuceneTestCase.java
===================================================================
--- src/test/org/apache/lucene/util/LuceneTestCase.java	(revision 922799)
+++ src/test/org/apache/lucene/util/LuceneTestCase.java	(working copy)
@@ -17,7 +17,9 @@
  * limitations under the License.
  */
 
+import java.io.File;
 import java.io.PrintStream;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.Random;
@@ -60,8 +62,12 @@
    */
   public static final boolean VERBOSE = LuceneTestCaseJ4.VERBOSE;
 
+  /** Use this constant when creating Analyzers. */
   public static final Version TEST_VERSION_CURRENT = LuceneTestCaseJ4.TEST_VERSION_CURRENT;
 
+  /** Create indexes in this directory, optimally use a subdir, named after the test */
+  public static final File TEMP_DIR = LuceneTestCaseJ4.TEMP_DIR;
+
   private int savedBoolMaxClauseCount;
   
   private volatile Thread.UncaughtExceptionHandler savedUncaughtExceptionHandler = null;
@@ -250,6 +256,18 @@
     return new Random(seed);
   }
   
+  /** Gets a resource from the classpath as {@link File}. This method should only be used,
+   * if a real file is needed. To get a stream, code should prefer
+   * {@link Class#getResourceAsStream} using {@code this.getClass()}.
+   */
+  protected File getDataFile(String name) throws IOException {
+    try {
+      return new File(this.getClass().getResource(name).toURI());
+    } catch (Exception e) {
+      throw new IOException("Cannot find resource: " + name);
+    }
+  }
+  
   @Override
   public void runBare() throws Throwable {
     //long t0 = System.currentTimeMillis();
Index: src/test/org/apache/lucene/util/LuceneTestCaseJ4.java
===================================================================
--- src/test/org/apache/lucene/util/LuceneTestCaseJ4.java	(revision 922799)
+++ src/test/org/apache/lucene/util/LuceneTestCaseJ4.java	(working copy)
@@ -28,7 +28,9 @@
 import org.junit.rules.TestWatchman;
 import org.junit.runners.model.FrameworkMethod;
 
+import java.io.File;
 import java.io.PrintStream;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.Random;
@@ -58,8 +60,7 @@
  * of its name
  * <p>
  * <p>
- * See Junit4 documentation for a complete list of features at
- * http://junit.org/junit/javadoc/4.7/
+ * See Junit4 <a href="http://junit.org/junit/javadoc/4.7/">documentation</a> for a complete list of features.
  * <p>
  * Import from org.junit rather than junit.framework.
  * <p>
@@ -83,8 +84,19 @@
    */
   public static final boolean VERBOSE = Boolean.getBoolean("tests.verbose");
 
-  /** Change this when development starts for new Lucene version: */
+  /** Use this constant when creating Analyzers.
+   * <b>NOTE:</b> Change this when development starts for new Lucene version:
+   */
   public static final Version TEST_VERSION_CURRENT = Version.LUCENE_31;
+  
+  /** Create indexes in this directory, optimally use a subdir, named after the test */
+  public static final File TEMP_DIR;
+  static {
+    String s = System.getProperty("tempDir", System.getProperty("java.io.tmpdir"));
+    if (s == null)
+      throw new RuntimeException("To run tests, you need to define system property 'tempDir' or 'java.io.tmpdir'.");
+    TEMP_DIR = new File(s);
+  }
 
   private int savedBoolMaxClauseCount;
 
@@ -100,7 +112,7 @@
     }
   }
   private List<UncaughtExceptionEntry> uncaughtExceptions = Collections.synchronizedList(new ArrayList<UncaughtExceptionEntry>());
-
+  
   // This is how we get control when errors occur.
   // Think of this as start/end/success/failed
   // events.
@@ -291,6 +303,18 @@
   public String getName() {
     return this.name;
   }
+  
+  /** Gets a resource from the classpath as {@link File}. This method should only be used,
+   * if a real file is needed. To get a stream, code should prefer
+   * {@link Class#getResourceAsStream} using {@code this.getClass()}.
+   */
+  protected File getDataFile(String name) throws IOException {
+    try {
+      return new File(this.getClass().getResource(name).toURI());
+    } catch (Exception e) {
+      throw new IOException("Cannot find resource: " + name);
+    }
+  }
 
   // We get here from InterceptTestCaseEvents on the 'failed' event....
   public void reportAdditionalFailureInfo() {
