public static ReturnObject getReferenceReturnObject(String name) { ReturnObject rObject = new ReturnObject(); rObject.name = name; rObject.isReference = true; rObject.commandPart = Protocol.REFERENCE_TYPE + name; return rObject; }
public static ReturnObject getSetReturnObject(String name, int size) { ReturnObject rObject = new ReturnObject(); rObject.name = name; rObject.size = size; rObject.isSet = true; rObject.commandPart = Protocol.SET_TYPE + name; return rObject; }
@RequestMapping(value="/postLogout.html", method=RequestMethod.GET) @ResponseBody public MyreturnObject getPostLogout(){ return new ReturnObject(true,true,false); }
public static ReturnObject getArrayReturnObject(String name, int size) { ReturnObject rObject = new ReturnObject(); rObject.name = name; rObject.size = size; rObject.isArray = true; rObject.commandPart = Protocol.ARRAY_TYPE + name; return rObject; }
public static ReturnObject getIteratorReturnObject(String name) { ReturnObject rObject = new ReturnObject(); rObject.name = name; rObject.isIterator = true; rObject.commandPart = Protocol.ITERATOR_TYPE + name; return rObject; }
public static ReturnObject getListReturnObject(String name, int size) { ReturnObject rObject = new ReturnObject(); rObject.name = name; rObject.size = size; rObject.isList = true; rObject.commandPart = Protocol.LIST_TYPE + name; return rObject; }
public static ReturnObject getMapReturnObject(String name, int size) { ReturnObject rObject = new ReturnObject(); rObject.name = name; rObject.size = size; rObject.isMap = true; rObject.commandPart = Protocol.MAP_TYPE + name; return rObject; }
Observable<ReturnObject> observable = Observable.concat( apiCall1(), apiCall2(), apiCall3() ).flatMap(response -> { if (response.value == whatWeAreLookingFor) { ReturnObject obj = new ReturnObject(); // set obj properties and return it. return Observable.just(obj); } // Return empty to continue with next call from .concat() list. return null; // or return Observable.empty(); }).first(); // Makes sure only the first non-empty result is called and returned.
public static ReturnObject getDecimalReturnObject(Object object) { BigDecimal decimal = (BigDecimal) object; ReturnObject rObject = new ReturnObject(); rObject.isDecimal = true; rObject.commandPart = Protocol.DECIMAL_TYPE + decimal.toPlainString(); return rObject; }
public static ReturnObject getErrorReturnObject() { ReturnObject rObject = new ReturnObject(); rObject.isError = true; rObject.commandPart = String.valueOf(Protocol.ERROR); return rObject; }
public static ReturnObject getNullReturnObject() { ReturnObject rObject = new ReturnObject(); rObject.isNull = true; rObject.commandPart = String.valueOf(Protocol.NULL_TYPE); return rObject; }
public static ReturnObject getVoidReturnObject() { ReturnObject rObject = new ReturnObject(); rObject.isVoid = true; rObject.commandPart = String.valueOf(Protocol.VOID); return rObject; }
public static ReturnObject getErrorReferenceReturnObject(String name) { ReturnObject rObject = new ReturnObject(); rObject.name = name; rObject.isError = true; StringBuilder builder = new StringBuilder(); builder.append(Protocol.ERROR); builder.append(Protocol.REFERENCE_TYPE); builder.append(name); rObject.commandPart = builder.toString(); return rObject; }
public static ReturnObject getErrorReturnObject(Throwable throwable) { ReturnObject rObject = new ReturnObject(); rObject.isError = true; StringBuilder builder = new StringBuilder(); builder.append(Protocol.ERROR); builder.append(Protocol.STRING_TYPE); builder.append(StringUtil.escape(Protocol.getThrowableAsString(throwable))); rObject.commandPart = builder.toString(); return rObject; }
@RunWith(PowerMockRunner.class) @PrepareForTest({ }) public class ItemTest{ @Test public void testSaveItem() throws Exception { //create a real object of MainServiceImpl MainServiceImpl mainService = new MainServiceImpl(); //create a normal way for a mocking object AService aService = Mockito.mock(AService.class); // Add mock object to MainServiceImpl instance ReflectionTestUtils.setField(mainService, "aService", aService); //Mock when aService call to addNewItem() method PowerMockito.when(aService , "addNewItem", Mockito.anyString(), Mockito.anyString()).then(new Answer<ReturnObject>() { @Override public ReturnObject answer(InvocationOnMock invocation) throws Throwable { return new ReturnObject("saveOK"); } }); ReturnObject returnObj = mainService.saveItem("Book", "Code123"); Assert.assertNotNull(returnObj); } }
@Test public void testSaveItem() throws Exception { //create a real object of MainServiceImpl MainServiceImpl mainService = new MainServiceImpl(); //create a special way for a mocking object by add //the answer at create the mock object final Answer<ReturnObject> answer = new Answer<ReturnObject>() { @Override public ReturnObjectanswer(final InvocationOnMock invocation) throws Throwable { return new ReturnObject("saveOK"); } }; AService aService = Mockito.mock(AService.class, answer); // Add mock object to MainServiceImpl instance ReflectionTestUtils.setField(mainService, "aService", aService); //Mock when aService call to addNewItem() method PowerMockito.when(aService , "addNewItem", Mockito.anyString(), Mockito.anyString()).then(new Answer<ReturnObject>() { @Override public ReturnObject answer(InvocationOnMock invocation) throws Throwable { return new ReturnObject("saveOK"); } }); ReturnObject returnObj = mainService.saveItem("Book", "Code123"); Assert.assertNotNull(returnObj); }
public static ReturnObject getPrimitiveReturnObject(Object primitive) { ReturnObject rObject = new ReturnObject(); rObject.primitiveObject = primitive; char primitiveType = Protocol.getPrimitiveType(primitive); if (primitiveType == Protocol.STRING_TYPE) { rObject.commandPart = primitiveType + StringUtil.escape(primitive.toString()); } else if (primitiveType == Protocol.BYTES_TYPE) { rObject.commandPart = primitiveType + Protocol.encodeBytes((byte[]) primitive); } else { rObject.commandPart = primitiveType + primitive.toString(); } return rObject; }
ReturnObject returnObject = new ReturnObject();
public class Foo { static { System.loadLibrary("Foo"); } public static void main(String[] args) { ReturnObject returnObject = new ReturnObject(); returnObject.list = new ArrayList<>(); Foo foo = new Foo(); foo.someFunction(returnObject); System.out.println("size is " + returnObject.list.size()); foo.someFunction(returnObject); System.out.println("size is " + returnObject.list.size()); foo.someFunction(returnObject); System.out.println("size is " + returnObject.list.size()); // we have three element added from JNI for (String string : returnObject.list.get(2)) { System.out.println(string); } } public native void someFunction(ReturnObject returnObject); }