I want to test an activity, to which some information is passed in extras.
Intent intent = new Intent().putExtra("someData", "asdfgh");
activity = Robolectric.buildActivity(XYZ.class).withIntent(intent).create().get();
It throws following error:
java.lang.NullPointerException
at android.app.Activity.attach(Activity.java:4993)
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112)
at org.robolectric.util.ActivityController.attach(ActivityController.java:92)
at org.robolectric.util.ActivityController$1.run(ActivityController.java:117)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256)
at org.robolectric.util.ActivityController.create(ActivityController.java:114)
at org.robolectric.util.ActivityController.create(ActivityController.java:126)
at com.XXX.XXX.XYZTest.shouldDoBlah(XYZTest.java:XX)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:241)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
My question is similar to this in some manner. However, the answer seems to be outdated. It would have worked well in older versions of Robolectric.
This answer seems to work for me. However, can somebody confirm this as the correct way of doing. Because in the previous versions new Intent().putExtra(String, String) used to work fine.
This is what I did:
Intent intent = new Intent(Robolectric.getShadowApplication().getApplicationContext(), XYZ.class);
intent.putExtra("foo", "bar");
XYZ xyz = Robolectric.buildActivity(XYZ.class).withIntent(intent).create().get();
You need to pass a context and the class (you want to test) as parameters of the Intent constructor.
Hope it helps.
For Roboelectric Version 3.1+
withIntent(intent) method is deprecated, as per the document intent should be passed through the constructor instead.
Robolectric.buildActivity(XYZ.class, intent).create().get();
In robolectric 3.x the way to get the application context is a little different:
Intent intent = new Intent(ShadowApplication.getInstance().getApplicationContext(),
ViewTransactionActivity.class);
intent.putExtra(foo, bar);
activity = Robolectric.buildActivity(XYZ.class).withIntent(intent).create().get();
In 3.0 snapshot of robolectric the api is changed to :
Bundle bundle = new Bundle();
bundle.putString(Constants.PASSWORD_RESET_MESSAGE, "");
intent.putExtras(bundle);
mTargetActivity = Robolectric.buildActivity(Target.class).withIntent(intent).create().get();
It seems withIntent method is deprecated. Alternative is:
Intent intent = new Intent();
Intent.putExtra("extra", "test");
Activity activity = Robolectric.buildActivity(YourActivity.class, intent).create().visible().get();
Related
I have a xamarin forms app. When I compile and test on my Pixel3, everything seems to be working properly. When I load it up in my iOS device running iOS13.something, I get the following error when I try to make my second call to a web service in my app. The error is shown below.
Assertion at /Users/builder/jenkins/workspace/archive-mono/2019-08/ios/release/mono/mini/interp/interp.c:2160, condition `is_ok (error)' not met, function:do_jit_call, Attempting to JIT compile method '(wrapper other) void object:gsharedvt_out_sig (object&,single&,int&,intptr)' while running in aot-only mode. See https://learn.microsoft.com/xamarin/ios/internals/limitations for more information. assembly: type: member:(null)
The code is a bit of a mess, but has been working in the past.
var uri = String.Format("{0}//{1}/{2}?PlayerToken={3}", protocol, servername, tournamentsInClubUrl, userToken);
var httpC = new HttpClient();
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);
requestMessage.Headers.Add("AppKey", AppKey);
var body = await httpC.SendAsync(requestMessage); <-- Error happens here.
var str = await body.Content.ReadAsStringAsync();
var res = JsonConvert.DeserializeObject<List<PicVideoApp.Models.TournamentInfo>>(str);
httpC.Dispose();
httpC = null;
return res;
I assume that I am doing something wrong, but danged if I can see it. Any ideas are appreciated.
It runs properly in the iOS Simulator.
TIA.
From shared error info , you need to use C# delegate to call native functions .
To call a native function through a C# delegate, the delegate's declaration must be decorated with one of the following attributes:
UnmanagedFunctionPointerAttribute (preferred, since it is cross-platform and compatible with .NET Standard 1.1+)
MonoNativeFunctionWrapperAttribute
For example :
[MonoNativeFunctionWrapper]
delegate void SomeDelegate (int a, int b);
//
// the ptrToFunc points to an unmanaged C function with the signature (int a, int b)
void Callback (IntPtr ptrToFunc)
{
var del = (SomeDelegate) Marshal.GetDelegateForFunctionPointer (ptrToFunc, typeof (SomeDelegate));
// invoke it
del (1, 2);
A similar error was thrown at me in iOS when I used dynamic types in my code. I was able to solve it by enabling the 'Mono Interpreter' in iOS build settings. Hope that helps in your case.
I am a newbie to Apache Chemistry openCMIS.
I am trying to pull a PDF document from the Alfresco repository using its Id.
The id is something similar to workspace://SpacesStore/b91dc42c-1644-4246-b3x9-bxx6f0be4wf3
CmisObject object = getSession().getObject(Id);
I am getting the below exception while execute the above line.
org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException: Parsing exception!
The Exception object does not contain the stackTrace and it contains the cause as below.
org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException: Extensions tree too wide!
But, I dont understand what I am missing. I have another drupal application, that pulls the same PDF without any issue. But this issue happens when I do it thru my java program.
Can anyone please help me out find what I am doing wrong?
UPDATE (ATTACHING THE CODE)
SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Map<String, String> parameter = new HashMap<String, String>();
parameter.put(SessionParameter.USER, "admin");
parameter.put(SessionParameter.PASSWORD, "admin");
parameter.put(SessionParameter.ATOMPUB_URL, "http://192.168.64.130:8080/alfresco/service/cmis");
parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
parameter.put(SessionParameter.LOCALE_ISO3166_COUNTRY, "us");
parameter.put(SessionParameter.LOCALE_ISO639_LANGUAGE, "en");
parameter.put(SessionParameter.LOCALE_VARIANT, "");
Repository soleRepository = (Repository)sessionFactory.getRepositories(parameter).get(0);
Session session = soleRepository.createSession();
String Id = "workspace://SpacesStore/c271a8b1-9fe6-4c43-8b9d-c09935248d18";
CmisObject object = session.getObject(Id);
System.out.println(object);
Look at the following discussion: jeff potts on alfresco forum
It is not the best thing to do, but I would like to verify that a private method of an object is called, so I create a partial mock and add an expectation on the private method.
Synchronizer * sync = [[Synchronizer alloc] initWithCleanup:YES];
sync = [OCMockObject partialMockForObject:sync];
[[(id)sync expect] cleanupPreviousContents];
When I run the test, cleanupPreviousContents is not called but the test is still successful. Where is the bug ?
Regards,
Quentin
Yes, this is a perfectly valid thing to do. But you need to create a new reference for your partial mock:
Synchronizer * sync = [[Synchronizer alloc] initWithCleanup:YES];
id mockSync = [OCMockObject partialMockForObject:sync];
[[mockSync expect] cleanupPreviousContents];
... do something
[mockSync verify];
Is cleanupPreviousContents called within your initWithCleanup method? If so, you'll have to structure it a bit differently:
Synchronizer *sync = [Synchronizer alloc];
id mockSync = [OCMockObject partialMockForObject:sync];
[[mockSync expect] cleanupPreviousContents];
[sync initWithCleanup:YES];
[mockSync verify];
I'm using Adobe Stratus (now renamed to Cirrus) to build a p2p application. Inside the application, I used NetStream.onPeerConnect callback function and expected it to be triggered every time when a peer is connected. However, it always failed with my friend A while strangely friend B managed to have the function called without any problem.
I was wondering what could be the cause to this issue?
Here are how the code pieces look like.
First of all, create a NetConnection.
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
netConnection.connect(SERVER_ADDRESS+DEVELOPER_KEY);
Secondly, create NetStream upon NetConnection successfully connected.
private function netConnectionHandler(event:NetStatusEvent):void{
switch (event.info.code){
case "NetConnection.Connect.Success":
sendStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
sendStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
var sendObj:Object = new Object();
sendObj.onPeerConnect = function(subscriber:NetStream) : Boolean {
trace("[onPeerConnect] far id: " + subscriber.farID);
return true;
}
sendStream.client = sendObj;
sendStream.publish("file");
......
Thirdly, here's how I build the connection between two peers
receivedStream = new NetStream(netConnection, farId);
receivedStream.client = this;
receivedStream.addEventListener(NetStatusEvent.NET_STATUS, incomingStreamHandler);
receivedStream.play("file");
Please help enlighten me. Thanks!
It turns out my friend A is behind a symmetric NAT. I'm thinking to setup a TURN server for us to build a successful connection.
What I'm doing NOW:
Often multiple instances of the view component would be used in multiple places in an application. Each time I do this, I register the same mediator with a different name.
When a notification is dispatched, I attach the name of the mediator to the body of the notification, like so:
var obj:Object = new Object();
obj.mediatorName = this.getMediatorName();
obj.someParameter = someParameter;
sendNotification ("someNotification", obj);
Then in the Command class, I parse the notification body and store the mediatorName in the proxy.
var mediatorName:String = notification.getBody().mediatorName;
var params:String = notification.getBody().someParameter;
getProxy().someMethod(params, mediatorName);
On the return notification, the mediatorName is returned with it.
var obj:Object = new Object();
obj.mediatorName = mediatorName;
obj.someReturnedValue= someReturnedValue;
sendNotification ("someReturnedNotification", obj);
In the multiple mediators that might be watching for "someReturnedNotification," in the handleNotification(), it does an if statement, to see
if obj.mediatorName == this.getMediatorName
returns true. If so, process the info, if not, don't.
My Question is:
Is this the right way of using Multiton PureMVC? My gut feeling is not. I am sure there's a better way of architecting the application so that I don't have to test for the mediator's name to see if the component should be updated with the returned info.
Would someone please help and give me some direction as to what is a better way?
Thanks.
I checked with Cliff (the puremvc.org guy) and he said it's fine.