HADOOP-14245. Use Mockito.when instead of Mockito.stub. Contributed by Andras Bokor.
This commit is contained in:
parent
ceacadc51e
commit
b38a1eea8e
|
@ -72,16 +72,16 @@ public class TestGenericRefresh {
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
// Register Handlers, first one just sends an ok response
|
// Register Handlers, first one just sends an ok response
|
||||||
firstHandler = Mockito.mock(RefreshHandler.class);
|
firstHandler = Mockito.mock(RefreshHandler.class);
|
||||||
Mockito.stub(firstHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
|
Mockito.when(firstHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
|
||||||
.toReturn(RefreshResponse.successResponse());
|
.thenReturn(RefreshResponse.successResponse());
|
||||||
RefreshRegistry.defaultRegistry().register("firstHandler", firstHandler);
|
RefreshRegistry.defaultRegistry().register("firstHandler", firstHandler);
|
||||||
|
|
||||||
// Second handler has conditional response for testing args
|
// Second handler has conditional response for testing args
|
||||||
secondHandler = Mockito.mock(RefreshHandler.class);
|
secondHandler = Mockito.mock(RefreshHandler.class);
|
||||||
Mockito.stub(secondHandler.handleRefresh("secondHandler", new String[]{"one", "two"}))
|
Mockito.when(secondHandler.handleRefresh("secondHandler", new String[]{"one", "two"}))
|
||||||
.toReturn(new RefreshResponse(3, "three"));
|
.thenReturn(new RefreshResponse(3, "three"));
|
||||||
Mockito.stub(secondHandler.handleRefresh("secondHandler", new String[]{"one"}))
|
Mockito.when(secondHandler.handleRefresh("secondHandler", new String[]{"one"}))
|
||||||
.toReturn(new RefreshResponse(2, "two"));
|
.thenReturn(new RefreshResponse(2, "two"));
|
||||||
RefreshRegistry.defaultRegistry().register("secondHandler", secondHandler);
|
RefreshRegistry.defaultRegistry().register("secondHandler", secondHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,12 +181,12 @@ public class TestGenericRefresh {
|
||||||
public void testMultipleReturnCodeMerging() throws Exception {
|
public void testMultipleReturnCodeMerging() throws Exception {
|
||||||
// Two handlers which return two non-zero values
|
// Two handlers which return two non-zero values
|
||||||
RefreshHandler handlerOne = Mockito.mock(RefreshHandler.class);
|
RefreshHandler handlerOne = Mockito.mock(RefreshHandler.class);
|
||||||
Mockito.stub(handlerOne.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
|
Mockito.when(handlerOne.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
|
||||||
.toReturn(new RefreshResponse(23, "Twenty Three"));
|
.thenReturn(new RefreshResponse(23, "Twenty Three"));
|
||||||
|
|
||||||
RefreshHandler handlerTwo = Mockito.mock(RefreshHandler.class);
|
RefreshHandler handlerTwo = Mockito.mock(RefreshHandler.class);
|
||||||
Mockito.stub(handlerTwo.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
|
Mockito.when(handlerTwo.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
|
||||||
.toReturn(new RefreshResponse(10, "Ten"));
|
.thenReturn(new RefreshResponse(10, "Ten"));
|
||||||
|
|
||||||
// Then registered to the same ID
|
// Then registered to the same ID
|
||||||
RefreshRegistry.defaultRegistry().register("shared", handlerOne);
|
RefreshRegistry.defaultRegistry().register("shared", handlerOne);
|
||||||
|
@ -210,12 +210,12 @@ public class TestGenericRefresh {
|
||||||
public void testExceptionResultsInNormalError() throws Exception {
|
public void testExceptionResultsInNormalError() throws Exception {
|
||||||
// In this test, we ensure that all handlers are called even if we throw an exception in one
|
// In this test, we ensure that all handlers are called even if we throw an exception in one
|
||||||
RefreshHandler exceptionalHandler = Mockito.mock(RefreshHandler.class);
|
RefreshHandler exceptionalHandler = Mockito.mock(RefreshHandler.class);
|
||||||
Mockito.stub(exceptionalHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
|
Mockito.when(exceptionalHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
|
||||||
.toThrow(new RuntimeException("Exceptional Handler Throws Exception"));
|
.thenThrow(new RuntimeException("Exceptional Handler Throws Exception"));
|
||||||
|
|
||||||
RefreshHandler otherExceptionalHandler = Mockito.mock(RefreshHandler.class);
|
RefreshHandler otherExceptionalHandler = Mockito.mock(RefreshHandler.class);
|
||||||
Mockito.stub(otherExceptionalHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
|
Mockito.when(otherExceptionalHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
|
||||||
.toThrow(new RuntimeException("More Exceptions"));
|
.thenThrow(new RuntimeException("More Exceptions"));
|
||||||
|
|
||||||
RefreshRegistry.defaultRegistry().register("exceptional", exceptionalHandler);
|
RefreshRegistry.defaultRegistry().register("exceptional", exceptionalHandler);
|
||||||
RefreshRegistry.defaultRegistry().register("exceptional", otherExceptionalHandler);
|
RefreshRegistry.defaultRegistry().register("exceptional", otherExceptionalHandler);
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class TestCgroupsLCEResourcesHandler {
|
||||||
|
|
||||||
// Test 1, tasks file is empty
|
// Test 1, tasks file is empty
|
||||||
// tasks file has no data, should return true
|
// 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));
|
Assert.assertTrue(handler.checkAndDeleteCgroup(fspy));
|
||||||
|
|
||||||
// Test 2, tasks file has data
|
// Test 2, tasks file has data
|
||||||
|
|
Loading…
Reference in New Issue