[06/50] [abbrv] incubator-geode git commit: GEODE-1466 : Added TemporaryFileRule JUnit rule for tests that need to create files in a particular directory.

2016-10-31 Thread klund
GEODE-1466 : Added TemporaryFileRule JUnit rule for tests that need to create 
files in a particular directory.

* This closes #260


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/b0659935
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/b0659935
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/b0659935

Branch: refs/heads/feature/GEODE-1930
Commit: b06599353d40ae4b54282c71aba9df57411e2704
Parents: 8a08032
Author: Jared Stewart 
Authored: Thu Oct 13 16:50:35 2016 -0700
Committer: Jinmei Liao 
Committed: Fri Oct 14 12:00:03 2016 -0700

--
 geode-junit/build.gradle|   5 +-
 .../test/junit/rules/TemporaryFileRule.java | 111 
 .../test/junit/rules/TemporaryFileRuleTest.java | 130 +++
 3 files changed, 245 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b0659935/geode-junit/build.gradle
--
diff --git a/geode-junit/build.gradle b/geode-junit/build.gradle
index 3e4eb22..f7e5e46 100755
--- a/geode-junit/build.gradle
+++ b/geode-junit/build.gradle
@@ -17,7 +17,10 @@
 
 dependencies {
   testCompile 'commons-lang:commons-lang:' + project.'commons-lang.version'
-  compile ('junit:junit:' + project.'junit.version') {
+  testCompile 'com.google.guava:guava:' + project.'guava.version'
+  testCompile 'org.assertj:assertj-core:' + project.'assertj-core.version'
+
+  compile('junit:junit:' + project.'junit.version') {
 exclude module: 'hamcrest-core'
   }
   compile 'org.hamcrest:hamcrest-all:' + project.'hamcrest-all.version'

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b0659935/geode-junit/src/main/java/org/apache/geode/test/junit/rules/TemporaryFileRule.java
--
diff --git 
a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/TemporaryFileRule.java
 
b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/TemporaryFileRule.java
new file mode 100644
index 000..bd2cac2
--- /dev/null
+++ 
b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/TemporaryFileRule.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.geode.test.junit.rules;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+
+import org.junit.rules.ExternalResource;
+
+
+/**
+ * A {@link org.junit.rules.TestRule} to create temporary files in a given 
directory that should be
+ * deleted when the test method finishes.  This is useful in place of {@link 
org.junit.rules.TemporaryFolder} when a test needs
+ * to create files in a particular directory, for example user.home or 
user.dir.
+ *
+ * Example of usage:
+ * 
+ * public static class HasTemporaryFile {
+ *  Rule
+ *  public TemporaryFileRule temporaryFileRule = 
TemporaryFileRule.inUserHome();
+ *
+ *  Test
+ *  public void testUsingTempFolder() throws IOException {
+ *  File createdFile= temporaryFileRule.newFile(myfile.txt);
+ *  File createdFile= temporaryFileRule.newFile(myfile2.txt);
+ *  // ...
+ * }
+ * }
+ * 
+ */
+public class TemporaryFileRule extends ExternalResource {
+
+  private final String directory;
+
+  private Set files;
+
+  private TemporaryFileRule(String parentDirectory) {
+this.directory = parentDirectory;
+  }
+
+  public static TemporaryFileRule inUserHome() {
+return new TemporaryFileRule(System.getProperty("user.home"));
+  }
+
+  public static TemporaryFileRule inCurrentDir() {
+return new TemporaryFileRule(System.getProperty("user.dir"));
+  }
+
+  public static TemporaryFileRule inDirectory(String directory) {
+return new TemporaryFileRule(directory);
+  }
+
+  @Override
+  public void before() {
+files = new HashSet<>();
+  }
+
+  @Override
+  public void after() {
+

incubator-geode git commit: GEODE-1466 : Added TemporaryFileRule JUnit rule for tests that need to create files in a particular directory.

2016-10-14 Thread jinmeiliao
Repository: incubator-geode
Updated Branches:
  refs/heads/develop 8a0803230 -> b06599353


GEODE-1466 : Added TemporaryFileRule JUnit rule for tests that need to create 
files in a particular directory.

* This closes #260


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/b0659935
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/b0659935
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/b0659935

Branch: refs/heads/develop
Commit: b06599353d40ae4b54282c71aba9df57411e2704
Parents: 8a08032
Author: Jared Stewart 
Authored: Thu Oct 13 16:50:35 2016 -0700
Committer: Jinmei Liao 
Committed: Fri Oct 14 12:00:03 2016 -0700

--
 geode-junit/build.gradle|   5 +-
 .../test/junit/rules/TemporaryFileRule.java | 111 
 .../test/junit/rules/TemporaryFileRuleTest.java | 130 +++
 3 files changed, 245 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b0659935/geode-junit/build.gradle
--
diff --git a/geode-junit/build.gradle b/geode-junit/build.gradle
index 3e4eb22..f7e5e46 100755
--- a/geode-junit/build.gradle
+++ b/geode-junit/build.gradle
@@ -17,7 +17,10 @@
 
 dependencies {
   testCompile 'commons-lang:commons-lang:' + project.'commons-lang.version'
-  compile ('junit:junit:' + project.'junit.version') {
+  testCompile 'com.google.guava:guava:' + project.'guava.version'
+  testCompile 'org.assertj:assertj-core:' + project.'assertj-core.version'
+
+  compile('junit:junit:' + project.'junit.version') {
 exclude module: 'hamcrest-core'
   }
   compile 'org.hamcrest:hamcrest-all:' + project.'hamcrest-all.version'

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b0659935/geode-junit/src/main/java/org/apache/geode/test/junit/rules/TemporaryFileRule.java
--
diff --git 
a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/TemporaryFileRule.java
 
b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/TemporaryFileRule.java
new file mode 100644
index 000..bd2cac2
--- /dev/null
+++ 
b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/TemporaryFileRule.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.geode.test.junit.rules;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+
+import org.junit.rules.ExternalResource;
+
+
+/**
+ * A {@link org.junit.rules.TestRule} to create temporary files in a given 
directory that should be
+ * deleted when the test method finishes.  This is useful in place of {@link 
org.junit.rules.TemporaryFolder} when a test needs
+ * to create files in a particular directory, for example user.home or 
user.dir.
+ *
+ * Example of usage:
+ * 
+ * public static class HasTemporaryFile {
+ *  Rule
+ *  public TemporaryFileRule temporaryFileRule = 
TemporaryFileRule.inUserHome();
+ *
+ *  Test
+ *  public void testUsingTempFolder() throws IOException {
+ *  File createdFile= temporaryFileRule.newFile(myfile.txt);
+ *  File createdFile= temporaryFileRule.newFile(myfile2.txt);
+ *  // ...
+ * }
+ * }
+ * 
+ */
+public class TemporaryFileRule extends ExternalResource {
+
+  private final String directory;
+
+  private Set files;
+
+  private TemporaryFileRule(String parentDirectory) {
+this.directory = parentDirectory;
+  }
+
+  public static TemporaryFileRule inUserHome() {
+return new TemporaryFileRule(System.getProperty("user.home"));
+  }
+
+  public static TemporaryFileRule inCurrentDir() {
+return new TemporaryFileRule(System.getProperty("user.dir"));
+  }
+
+  public static TemporaryFileRule inDirectory(String directory) {
+return new TemporaryFileRule(directory);
+  }
+
+  @Override
+  public void before() {
+files =