GradleDetector: `checkDslPropertyAssignment` isn't executed - android

I'm writing some custom lint and decided to add a detector for the Gradle files.
So I've extended the GradleDetector(), overridden checkDslPropertyAssignment method, and added some test to check the logic inside checkDslPropertyAssignment. So far all works well.
However, if I name the gradle file differently in the test case, checkDslPropertyAssignment doesn't get executed. For example:
lint().files(
gradle("test.gradle", gradleFile)
)
If I skip "test.gradle", everything seems to be working.
Am I misusing something here, or is there a bug in the GradleDetector?
Thanks!

Related

'this#ActivityName' is not captured error Android/Kotlin

I'm repairing my friend's code and got confused.
My friend wants to fetch entered text (in EditText). Seems easy, right? Well, it is but instead of user input, he gets this warning/error:
To be honest I'm not sure how to fix it. He is coding in Kotlin (Android 10).
Activity that contains EditText:
And XML:
This is how it looks when debugging:
The app started working just fine after running "File -> invalidate Cashes/Restart" option, I just don't understand where this warning came from and how to fix it because the error remained unchanged (even though the app works). Do you have an idea how to solve it?
All the best!
fyi lambda expression like setOnClickListener from kotlin is not debuggable, see here.
if you want to debug variables inside setOnClickListener you should use the normal one e.g. setOnClickListener(object: View.OnClickListener {..})
sometimes there will be problem in auto generated binding files, if so it will be solved after invalidate cache and restart ide. sometimes the warning/error show but the project and complied without errors. so no need to worry about that. for next time post the code as code not screen shots.
I understand that the question is regarding evaluating expression, but there is a way you can read variables from your debugger console, even if you're inside an anonymous callback. I found it helpful sometimes. Here are the steps:
First enter debugger mode inside of your anonymous callback,
In your debugger console, look at the right side for "Frames"
Within Frames under , you'll see stack of function execution first top one on the list is the latest:
Click on row(s) below the latest function, until you find an instance of your activity AddInformationActivity. You will see the activity instance on the right side window under Variables. Don't go as far as selecting functions browned out, because those are from internal libraries.
When you see you AddInformationActivity instance, you can expand it and see its variables.
Hope that helps!
It's not a beautiful way, but if you create a method like this:
private fun debug() {
println()
}
and add a breakpoint on the println() it'll capture the activity.
(Don't use TODO as it'll crash the app with a NotImplementedError once called.)
I have this method now in my code all the time to call it whenever I need it.
I know, that question is old, but I just stumbled over it and needed a way.

Is there a way to trace who invoked onNext() on a Subject, in RxJava(2)?

I am developing an Android app (It doesn't matter though) using RxJava2, and in some singleton there are some PublishProcessors.
And there are a lot of .onNext() calls on these PublishProcessors all over the project.
Now in order to debug, I need to know, on every .onNext() called, which line in my project invoked this .onNext().
Is there a way in RxJava(2) that I can achieve this?
I think you can use Frames tab in Debug menu.
For example, in this case, MainActivity line 18 trigger onNext
Ah, thanks to #PhanVanLinh, I found a solution that worked for me.
(Actually it has pretty much nothing to do with RxJava...)
You just need to print the stacktrace using Thread.currentThread.stackTrace and print it to your own string inside doOnNext(), but remember to do it before .observeOn() so that the thread won't switch, it must stay at the original thread that called .onNext(), otherwise you won't get meaningful information.
Then you will know which line that called .onNext().

Shadow a part of the Fragment hierarchy

I am a newbie at robolectric unit testing, i have a fragment which i want to test, ex, ScreenAFragment. This has a hierarchy as below,
ScreenAFragment -> MyAppFragment -> MyLibFragment -> SherlockFragment.
There are 2 problems,
The MyLibFragment has some code which links to a database and does other stuff which don't need to be tested as a 'unit test case'.
This MyLibFragment reference is also causing a "PackageManager#NameNotFoundException"
How do I go about testing this? My initial thought was create a ShadowMyLibFragment and config my test case #config(shadow={ShadowMyLibFragment.class}) to use this instead of the original class. Doesn't seem to be working at the moment, as it still seems to refer to the original library and throws the old error.
Any Solutions? I am using Robolectric 2.4 version.

Keep sections are being removed on generation

I am using GreenDAO v1.2.0 to generate entity classes for an Android app.
I have set enableKeepSectionsByDefault() on my schema, and am getting these comment lines in my generated classes:
// KEEP METHODS - put your custom methods here
// KEEP METHODS END
I have put some custom methods between the comments, but the custom methods are removed every time I regenerate.
Is there something else I need to do to get this to work?
There is a parsing bug in greenDAO that will cause some or all of your KEEP METHODS to get wiped out by running the DaoGenerator.generateAll() method (even with schema.enableKeepSectionsByDefault() enabled)
The bug is that your Entity class (the one you have added custom imports, fields or methods to) REQUIRES a blank line at the end of the file.
for example
...
//KEEP_METHODS_END
}
... end of file
will fail, while
...
//KEEP_METHODS_END
}
... end of file
will work. Nasty little bug. Until it's fixed (if ever), ensure that your entity classes have a blank line at the end.
Hope this saves someone the torment I have experienced.
Ensure that the last line of the generated entity class is blank.
You need to call the schema.enableKeepSectionsByDefault();.

Unittesting AsyncTaskLoader with getLoaderResultSynchronously

I am trying to create unit tests for a REST client that does some API calls. The client works fine in the live application, but I can't get it to run in the test case.
Apparantly, LoaderTestCase.getLoaderResultSynchronously() could be used here (at least according to Android reference, but it will not accept my loader. The code:
public void testGetEventInfo() {
// Init some vars
...
// Create & execute loader
RESTLoader loader = new RESTLoader(getContext(),
RESTLoader.HTTPVerb.GET, action, params, LOADER_GET_NEWS);
getLoaderResultSynchronously(loader);
}
This yields the error getLoaderResultSynchronously(Loader) in the type LoaderTestCase is not applicable for the arguments (RESTLoader).
RESTLoader extends AsyncLoader. Note that I'm using the supportlibrary, maybe the Loader in there is incompatible? The documentation gives no information on this.
I've tried to solve this in several ways, though none seem to work:
Registered a listener to loader. However, the callback never triggers
Using CountdownLatch (also with a listener). Again, no trigger/countdown timeout.
Playing around with the type template (), without success.
Similar solutions on SO, though again failing to reach the listener.
Does anybody know why getLoaderResultSynchronously will not accept the loader? Or another clean way of testing the Loader, including a way to test return data? I can test handling the return data in a separate case, but I would also like to test the actual data.
Sincerely,
Have you taken a look at the source code? You'll find the following import statements:
import android.content.Loader;
import android.content.Loader.OnLoadCompleteListener;
It doesn't look like Android offers a support version for LoaderTestCase. The easiest solution would be to temporarily change to the non-support LoaderManager (that is, have your class make use of the android.content.Loader instead), test your app, and then switch back to the support implementation. You might also consider copying the testing source code into your project, import the support LoaderManager, and execute it directly. I'm not familiar with the test libraries for Loaders but it doesn't seem outwardly obvious that this would cause any major issues.
You can get sources from LoaderTestCase here, create SupportLoaderTestCase class from that sources in your test project and modify all namespaces to support library namespaces (e.g. change android.content.Loader with android.support.v4.content.Loader). Than you can extend your test case from SupportLoaderTestCase (not from LoaderTestCase) and use it without problems
The method you are trying to call (getLoaderResultSynchronously) accepts an object of type android.content.Loader. If your RESTLoader class is not of that EXACT type then you will get this error. I suspect your class directly or indirectly extends android.support.v4.content.Loader, which would explain the error.
I am not aware of a back-port of LoaderTestCase that would support testing of this type of class.

Categories

Resources