Java源码示例:org.moe.natj.objc.ObjCRuntime

示例1
@SuppressWarnings("unchecked")
static <T> T processPrimitiveData(Object data, Class<T> wantedType) {
    T result = null;
    if (data.getClass() == wantedType) {
        return (T) data;
    }
    if (data instanceof NSNumber) {
        if (wantedType == Long.class) {
            result = (T) Long.valueOf(((NSNumber) data).longValue());
        } else if (wantedType == Integer.class) {
            result = (T) Integer.valueOf(((NSNumber) data).intValue());
        } else if (wantedType == Float.class) {
            result = (T) Float.valueOf(((NSNumber) data).floatValue());
        } else if (wantedType == Double.class) {
            result = (T) Double.valueOf(((NSNumber) data).doubleValue());
        } else if (wantedType == Boolean.class) {
            result = (T) Boolean.valueOf(((NSNumber) data).boolValue());
        }
    } else if (data instanceof NSString) {
        result = (T) ObjCRuntime.createJavaString(((NSString) data).getPeerPointer());
    } else {
        throw new ConvertingException("" + data.getClass() + " is not primitive data");
    }
    return result;
}
 
示例2
void processDownload(FIRStorageReference firStorageReference, final String path, long bytesLimit, final FuturePromise<byte[]> promise) {
    firStorageReference.child(path).dataWithMaxSizeCompletion(bytesLimit, new FIRStorageReference.Block_dataWithMaxSizeCompletion() {
        @Override
        public void call_dataWithMaxSizeCompletion(final NSData arg0, NSError arg1) {
            if (ErrorHandler.handleError(arg1, promise)) return;
            ObjCRuntime.autoreleasepool(new Runnable() { // TODO - check this autorelease pool
                @Override
                public void run() {
                    int length = (int) arg0.length();
                    byte[] data = new byte[length];
                    arg0.bytes().getBytePtr().copyTo(data);
                    promise.doComplete(data);
                }
            });
        }
    });
}
 
示例3
@Override
public void setup() {
    super.setup();
    PowerMockito.mockStatic(NSString.class);
    PowerMockito.mockStatic(NSNumber.class);
    PowerMockito.mockStatic(NSArray.class);
    PowerMockito.mockStatic(NSMutableArray.class);
    PowerMockito.mockStatic(NSDictionary.class);
    PowerMockito.mockStatic(ObjCRuntime.class);
    PowerMockito.mockStatic(NSDictionaryHelper.class);
    PowerMockito.mockStatic(NSNumberHelper.class);
    PowerMockito.mockStatic(NSArrayHelper.class);
    Mockito.when(NSDictionaryHelper.toMap(Mockito.any(NSDictionary.class))).thenReturn(Mockito.mock(Map.class));
    Mockito.when(NSDictionaryHelper.toNSDictionary(Mockito.any(Object.class))).thenReturn(Mockito.mock(NSDictionary.class));
    Mockito.when(NSNumberHelper.getNSNumberPrimitive(Mockito.any(NSNumber.class))).thenReturn(Mockito.mock(Number.class));
    Mockito.when(NSArrayHelper.toList(Mockito.any(NSArray.class))).thenReturn(Mockito.mock(List.class));
    Mockito.when(NSArrayHelper.toArray(Mockito.any(List.class))).thenReturn(Mockito.mock(NSMutableArray.class));
}
 
示例4
@Test
public void iosDataToJava1() {
    // Given
    NSString nsString = PowerMockito.mock(NSString.class);
    NSNumber nsNumber = PowerMockito.mock(NSNumber.class);
    NSArray nsArray = PowerMockito.mock(NSArray.class);
    NSDictionary nsDictionary = PowerMockito.mock(NSDictionary.class);
    PowerMockito.when(ObjCRuntime.createJavaString(Mockito.nullable(Long.class))).thenReturn("test");

    // When
    Object resultString = DataProcessor.iosDataToJava(nsString);
    Object resultNumber = DataProcessor.iosDataToJava(nsNumber);
    Object resultArray = DataProcessor.iosDataToJava(nsArray);
    Object resultDictionary = DataProcessor.iosDataToJava(nsDictionary);

    // Then
    Assert.assertTrue(resultString instanceof String);
    Assert.assertTrue(resultNumber instanceof Number);
    Assert.assertTrue(resultArray instanceof List);
    Assert.assertTrue(resultDictionary instanceof Map);
}
 
示例5
@Generated
public void setDelegate(
		@Mapped(ObjCObjectMapper.class) GIDSignInDelegate value) {
	Object __old = delegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例6
@Generated
public void setUiDelegate(
		@Mapped(ObjCObjectMapper.class) GIDSignInUIDelegate value) {
	Object __old = uiDelegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setUiDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例7
@Generated
public void setDelegate(
		@Mapped(ObjCObjectMapper.class) CrashlyticsDelegate value) {
	Object __old = delegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例8
@Generated
public void setDelegate(
		@Mapped(ObjCObjectMapper.class) FIRMessagingDelegate value) {
	Object __old = delegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例9
@Test
public void iosDataToJava_string() {
    // Given
    Object iosObject = Mockito.mock(NSString.class);
    Class wantedType = String.class;
    PowerMockito.when(ObjCRuntime.createJavaString(Mockito.nullable(Long.class))).thenReturn("test");

    // When
    Object result = DataProcessor.iosDataToJava(iosObject, wantedType);

    // Then
    Assert.assertEquals("test", result);
}
 
示例10
@Test
public void processPrimitiveData_string() {
    // Given
    NSString iosObject = PowerMockito.mock(NSString.class);
    PowerMockito.when(ObjCRuntime.createJavaString(Mockito.nullable(Long.class))).thenReturn("test");

    // When
    Object result = DataProcessor.processPrimitiveData(iosObject, String.class);

    // Then
    Assert.assertTrue(result instanceof String);
}
 
示例11
@Override
public void setup() {
    super.setup();
    PowerMockito.mockStatic(FIRStorageReference.class);
    PowerMockito.mockStatic(FIRStorageMetadata.class);
    PowerMockito.mockStatic(NSError.class);
    PowerMockito.mockStatic(NSData.class);
    PowerMockito.mockStatic(FIRStorageUploadTask.class);
    PowerMockito.mockStatic(ObjCRuntime.class);
    PowerMockito.mockStatic(FIRStorageDownloadTask.class);
    PowerMockito.mockStatic(NSURL.class);
    PowerMockito.mockStatic(PtrFactory.class);
    PowerMockito.mockStatic(Foundation.class);
    PowerMockito.mockStatic(FIRStorage.class);
    PowerMockito.mockStatic(NSDate.class);
    try {
        PowerMockito.doAnswer(new Answer() {
            @Override
            public Object answer(InvocationOnMock invocation) {
                ((Runnable) invocation.getArgument(0)).run();
                return null;
            }
        }).when(ObjCRuntime.class, "autoreleasepool", Mockito.any(Runnable.class));
    } catch (Exception e) {
        e.printStackTrace();
    }
    firStorage = Mockito.mock(FIRStorage.class);
    firStorageReference = Mockito.mock(FIRStorageReference.class);
    when(FIRStorage.storage()).thenReturn(firStorage);
    when(firStorage.referenceForURL(Mockito.anyString())).thenReturn(firStorageReference);
    when(firStorage.reference()).thenReturn(firStorageReference);
    when(firStorageReference.child(Mockito.anyString())).thenReturn(firStorageReference);
    when(PtrFactory.newByteArray(Mockito.any(byte[].class))).thenReturn(Mockito.mock(BytePtr.class));
}
 
示例12
@Generated
public void setDelegate(
		@Mapped(ObjCObjectMapper.class) BFAppLinkReturnToRefererControllerDelegate value) {
	Object __old = delegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例13
@Generated
public void setDelegate(
		@Mapped(ObjCObjectMapper.class) BFAppLinkReturnToRefererViewDelegate value) {
	Object __old = delegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例14
@Generated
@Deprecated
public void setDelegate(
		@Mapped(ObjCObjectMapper.class) FBSDKAppGroupAddDialogDelegate value) {
	Object __old = delegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例15
@Generated
public void setDelegate(@Mapped(ObjCObjectMapper.class) Object value) {
	Object __old = delegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例16
@Generated
public void setFromViewController(UIViewController value) {
	Object __old = fromViewController();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setFromViewController_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例17
@Generated
public void setDelegate(@Mapped(ObjCObjectMapper.class) Object value) {
	Object __old = delegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例18
@Generated
@Deprecated
public void setDelegate(
		@Mapped(ObjCObjectMapper.class) FBSDKAppGroupJoinDialogDelegate value) {
	Object __old = delegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例19
@Generated
public void setDelegate(
		@Mapped(ObjCObjectMapper.class) FBSDKGameRequestDialogDelegate value) {
	Object __old = delegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例20
@Generated
public void setDelegate(
		@Mapped(ObjCObjectMapper.class) FBSDKAppInviteDialogDelegate value) {
	Object __old = delegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例21
@Generated
public void setFromViewController(UIViewController value) {
	Object __old = fromViewController();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setFromViewController_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例22
@Generated
public void setDelegate(@Mapped(ObjCObjectMapper.class) Object value) {
	Object __old = delegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例23
@Generated
public void setDelegate(
		@Mapped(ObjCObjectMapper.class) FBSDKLoginButtonDelegate value) {
	Object __old = delegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例24
@Generated
public void setDelegate(
		@Mapped(ObjCObjectMapper.class) FBSDKLoginTooltipViewDelegate value) {
	Object __old = delegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}
 
示例25
@Generated
public void setDelegate(
		@Mapped(ObjCObjectMapper.class) FBSDKGraphRequestConnectionDelegate value) {
	Object __old = delegate();
	if (value != null) {
		org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
	}
	setDelegate_unsafe(value);
	if (__old != null) {
		org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);
	}
}