hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xg...@apache.org
Subject [11/20] hadoop git commit: HADOOP-14245. Use Mockito.when instead of Mockito.stub. Contributed by Andras Bokor.
Date Tue, 01 Aug 2017 15:47:34 GMT
HADOOP-14245. Use Mockito.when instead of Mockito.stub. Contributed by Andras Bokor.


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

Branch: refs/heads/YARN-5734
Commit: b38a1eea8e2917989d83d169a7b5773163e6832e
Parents: ceacadc
Author: Akira Ajisaka <aajisaka@apache.org>
Authored: Tue Aug 1 15:15:43 2017 +0900
Committer: Akira Ajisaka <aajisaka@apache.org>
Committed: Tue Aug 1 15:15:43 2017 +0900

----------------------------------------------------------------------
 .../org/apache/hadoop/TestGenericRefresh.java   | 28 ++++++++++----------
 .../util/TestCgroupsLCEResourcesHandler.java    |  2 +-
 2 files changed, 15 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/b38a1eea/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/TestGenericRefresh.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/TestGenericRefresh.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/TestGenericRefresh.java
index 3c73c28..dcd91c7 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/TestGenericRefresh.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/TestGenericRefresh.java
@@ -72,16 +72,16 @@ public class TestGenericRefresh {
   public void setUp() throws Exception {
     // Register Handlers, first one just sends an ok response
     firstHandler = Mockito.mock(RefreshHandler.class);
-    Mockito.stub(firstHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
-      .toReturn(RefreshResponse.successResponse());
+    Mockito.when(firstHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
+      .thenReturn(RefreshResponse.successResponse());
     RefreshRegistry.defaultRegistry().register("firstHandler", firstHandler);
 
     // Second handler has conditional response for testing args
     secondHandler = Mockito.mock(RefreshHandler.class);
-    Mockito.stub(secondHandler.handleRefresh("secondHandler", new String[]{"one", "two"}))
-      .toReturn(new RefreshResponse(3, "three"));
-    Mockito.stub(secondHandler.handleRefresh("secondHandler", new String[]{"one"}))
-      .toReturn(new RefreshResponse(2, "two"));
+    Mockito.when(secondHandler.handleRefresh("secondHandler", new String[]{"one", "two"}))
+      .thenReturn(new RefreshResponse(3, "three"));
+    Mockito.when(secondHandler.handleRefresh("secondHandler", new String[]{"one"}))
+      .thenReturn(new RefreshResponse(2, "two"));
     RefreshRegistry.defaultRegistry().register("secondHandler", secondHandler);
   }
 
@@ -181,12 +181,12 @@ public class TestGenericRefresh {
   public void testMultipleReturnCodeMerging() throws Exception {
     // Two handlers which return two non-zero values
     RefreshHandler handlerOne = Mockito.mock(RefreshHandler.class);
-    Mockito.stub(handlerOne.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
-      .toReturn(new RefreshResponse(23, "Twenty Three"));
+    Mockito.when(handlerOne.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
+      .thenReturn(new RefreshResponse(23, "Twenty Three"));
 
     RefreshHandler handlerTwo = Mockito.mock(RefreshHandler.class);
-    Mockito.stub(handlerTwo.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
-      .toReturn(new RefreshResponse(10, "Ten"));
+    Mockito.when(handlerTwo.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
+      .thenReturn(new RefreshResponse(10, "Ten"));
 
     // Then registered to the same ID
     RefreshRegistry.defaultRegistry().register("shared", handlerOne);
@@ -210,12 +210,12 @@ public class TestGenericRefresh {
   public void testExceptionResultsInNormalError() throws Exception {
     // In this test, we ensure that all handlers are called even if we throw an exception
in one
     RefreshHandler exceptionalHandler = Mockito.mock(RefreshHandler.class);
-    Mockito.stub(exceptionalHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
-      .toThrow(new RuntimeException("Exceptional Handler Throws Exception"));
+    Mockito.when(exceptionalHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
+      .thenThrow(new RuntimeException("Exceptional Handler Throws Exception"));
 
     RefreshHandler otherExceptionalHandler = Mockito.mock(RefreshHandler.class);
-    Mockito.stub(otherExceptionalHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
-      .toThrow(new RuntimeException("More Exceptions"));
+    Mockito.when(otherExceptionalHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
+      .thenThrow(new RuntimeException("More Exceptions"));
 
     RefreshRegistry.defaultRegistry().register("exceptional", exceptionalHandler);
     RefreshRegistry.defaultRegistry().register("exceptional", otherExceptionalHandler);

http://git-wip-us.apache.org/repos/asf/hadoop/blob/b38a1eea/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestCgroupsLCEResourcesHandler.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestCgroupsLCEResourcesHandler.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestCgroupsLCEResourcesHandler.java
index b562133..1ed8fd8 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestCgroupsLCEResourcesHandler.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestCgroupsLCEResourcesHandler.java
@@ -76,7 +76,7 @@ public class TestCgroupsLCEResourcesHandler {
 
     // Test 1, tasks file is empty
     // tasks file has no data, should return true
-    Mockito.stub(fspy.delete()).toReturn(true);
+    Mockito.when(fspy.delete()).thenReturn(true);
     Assert.assertTrue(handler.checkAndDeleteCgroup(fspy));
 
     // Test 2, tasks file has data


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message