"Assert in junit.framework has been deprecated" - what next to use? - junit

I bump version of junit to 4.11 and get:
[WARNING] [deprecation] Assert in junit.framework has been deprecated
[WARNING] [deprecation] Assert in junit.framework has been deprecated
....
How and to what migrate?

As it seems the Assert class has been moved from junit.framework to org.junit.Assert in JUnit 4.0 - you can use that instead, it's not deprecated.

Change your import statement from
import junit.framework.Assert;
to
import org.junit.Assert;
and this will rectify your JUnit deprecation warnings.

Both are depricated:
junit.framework.Assert.assertThat
org.junit.Assert.assertThat
According to docs, use Instead:
org.hamcrest.MatcherAssert.assertThat

After facing this problem I have tried lots of ways to solve this but failed again and again.
The good thing is: I have download junit-4.12.jar file from here and added the jar file in the project section under the libs folder. If previously any kind of Junit dependancy exist in the project then remove that from the build.gradle and build + clean your project.
It is worked for me. Hope it will work for you.
Note: Take a look in the image that I attached in below.
Thank you

We had a large number of tests with many assertions.
Adding something like
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
to the import statements also helped to limit the changes in test code.

You can refer to jUnit4 Assert class methods from JUnit4

Related

How to test require statement with hardhat?

I'm testing a smart contract that has a require statement in one of the functions.
In the past, I would just write.
await expect(token.transfer(user.address, ethers.utils.parseEther("10")).to.be.reverted;
But recently it stopped working, and it gives me this error:
Property 'reverted' does not exist on type 'Assertion'.ts(2339)
Any ideas why it's not working properly, or am I doing something wrong?
Thanks a lot.
It turns out I didn't import chai correctly.
So to solve this I created another file called chai-setup.ts and added this code inside:
import chaiModule from "chai";
import { chaiEthers } from "chai-ethers";
chaiModule.use(chaiEthers);
export = chaiModule;
Then in my main test file, I added this import statement:
import { expect } from "./chai-setup"
And that solved my problem.
A little late to answer, but you can use hardhat chai matchers to solve this issue.
Install hardhat chai matchers by
yarn add --dev #nomicfoundation/hardhat-chai-matchers
Now all you need to is import it in your hardhat config by:
import "#nomicfoundation/hardhat-chai-matchers";
or
require("#nomicfoundation/hardhat-chai-matchers")
Now you will be able to use reverted and other stuff.

How to fix this error duplicate class found in module class.jar

I got this error when I try to generate signed apk for my project
Duplicate class com.google.android.gms.measurement.AppMeasurement
found in modules classes.jar
(com.google.android.gms:play-services-measurement-impl:16.5.0) and
classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics found
in modules classes.jar
(com.google.android.gms:play-services-measurement-api:16.5.0) and
classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Event
found in modules classes.jar
(com.google.android.gms:play-services-measurement-api:16.5.0) and
classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Param
found in modules classes.jar
(com.google.android.gms:play-services-measurement-api:16.5.0) and
classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)
Duplicate class
com.google.firebase.analytics.FirebaseAnalytics$UserProperty found in
modules classes.jar
(com.google.android.gms:play-services-measurement-api:16.5.0) and
classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)
Go to the documentation to learn how to Fix dependency resolution errors.
how do I fix It?
Try with
implementation("com.google.android.gms:play-services-gcm:$project.playServicesVersion") {
exclude group: 'com.google.android.gms'
}
You can Try including one by one the one which brings errors you apply
implementation("**API**") {
exclude group: 'com.google.android.gms'
}
NB $project.playServicesVersion could be any of your versions you are using
For those who face this type of issue in the future
Ensure that you are using the specific dependency of play services according to your requirements. In my case, I need a map dependency but I am importing the play service dependency which causes duplicate class issues with another firebase dependency.
Use this
def playServiceVersion = "17.0.0"
implementation "com.google.android.gms:play-services-maps:$playServiceVersion"
Instead of
def playServiceVersion = "17.0.0"
implementation "com.google.android.gms:play-services:$playServiceVersion"
For further information check the link below
https://developers.google.com/android/guides/setup
Reason: This error usually occurs due to depedencies using same functionality.
Solution: To revolve such issue is to comment: play-services because play-services-maps has same functions like play-services and also display locations on our android UI system. Please see below for solution.
//implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
Also checkout notable transitive dependencies: https://github.com/firebase/FirebaseUI-Android/releases
I hope its help solve so many developers project issues.

ImportError: cannot import name 'persist'

I want to persist a trained model in CNTK and found the 'persist' functionality after some amount of searching. However, there seems to be some error in importing it.
from cntk import persist
This is throwing ImportError.
Am I doing something the wrong way? Or is this no longer supported? Is there an alternate way to persist a model?
persist is from an earlier beta. save_model is now a method of every CNTK function. So instead of doing save_model(z, filename) you do z.save_model(filename). Load_model works the same as before but you import it from cntk.ops.functions. For an example, see: https://github.com/Microsoft/CNTK/blob/v2.0.beta7.0/Tutorials/CNTK_203_Reinforcement_Learning_Basics.ipynb or https://github.com/Microsoft/CNTK/blob/v2.0.beta7.0/bindings/python/cntk/tests/persist_test.py
The functionality has moved to cntk functions. The new way is mynetwork.save_model(...) where mynetwork represents the root of your computation (typically the prediction). For loading the model you can just say mynetwork = C.load_model(...)

JSON Parser -java.lang.NoSuchFieldError: defaultReader

I am using a JSON parser to extract the value and I am using the following jar
json-path-2.1.0, and I am getting the following error when I invoke the use case deployed as webservice on weblogic server
I wrote a small main program to extract the value from the json string and it works fine, but the server version of the use case is giving the issue. I am not sure if there are any other jars part of my ear can negatively impact this
SEVERE: defaultReader
java.lang.NoSuchFieldError: defaultReader
at com.jayway.jsonpath.spi.json.JsonSmartJsonProvider.<init>(JsonSmartJsonProvider.java:39)
at com.jayway.jsonpath.internal.DefaultsImpl.jsonProvider(DefaultsImpl.java:21)
at com.jayway.jsonpath.Configuration.defaultConfiguration(Configuration.java:174)
at com.jayway.jsonpath.internal.JsonContext.<init>(JsonContext.java:52)
at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:596)
Stumbled about the same problem.
The reason why it does not work is not the JDK 8.
The reason why you encounter this issue, is the fact that weblogic 12.2.1.X is bundling some old version of json-smart.
On my machine this would be found here:
jar:file:/C:/dev/WLS_12_2_1_2_0/oracle_common/modules/net.minidev.json-smart.jar!/net/minidev/json/JSONValue.class
Now if you are using a library like json-path that depends on json-smart, then by default the container will load the required class using one of its built-in modules.
The blowup you have, seems to be that the JSONValue class that your json-path depends on seemed to have this defaultReder field.
Here is a snipet of the clode that is blowing up.
public JsonSmartJsonProvider() {
this(JSONParser.MODE_PERMISSIVE, JSONValue.defaultReader.DEFAULT_ORDERED);
}
That
JSONValue.defaultReader
Seems not to be valid on weblogs older system class loader class.
You can tell the container to use what you are packing by putting into your weblogic.xml deployment descriptor something like this:
<wls:prefer-application-packages>
<wls:package-name>net.minidev.json.*</wls:package-name>
</wls:prefer-application-packages>
I am having quite a bit of trouble getting weblogic to swallow the fine-grained instruction above.
I found myself to force weblogic to swallog all that goes into the web-inf folder instead doing:
<wls:container-descriptor>
<wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
</wls:container-descriptor>
I would have rather not be using a hammer like the web-inf-classes, but I am dancing with the weblogic system classloader when I do not go coarse grained...
Regards.
I too was facing this issue, It turned out some other library was using json-smart's older version, and it was getting precedence over json-path's json-smart dependency. Removing the other jar solved the issue. Or you can also downgrade your json-path's version to appropriate version such that it support json-smart's older version.
Looks like JsonParser jar is present in JVM 1.8 version and it seems to have more precedence over the JsonParser class available in Json-path.jar. Apparently the us case doesn't work in 12.2.1 version of the weblogic server but it works fine in 12.1.3
I had the same problem but I use Gradle so I had to add:
compile group: 'net.minidev', name: 'json-smart', version: '2.3' to my dependencies.

Using JUnit in Jython - NameError for assertTrue

Environment Details
Mac OS X 10.9
Oracle JDK 1.7.0_55 64-bit
jython-standalone-2.5.3.jar
junit-4.11
What I have done so far
I have added the junit jar to /Library/Java/Extensions.
I invoked Jython as follows java -jar jython-standalone-2.5.3.jar
In the Jython interpreter, I imported the following import org.junit.Assert, and this import was successful.
Problem
When I tried to use assertTrue, I got a NameError in the interpreter. Why is this so?
I understand that assertTrue is a static method. Not sure what implication this has when I try to use it in Jython.
Additional Context
I am using XMLUnit in Jython. Was able to successfully import the Diff class from org.custommonkey.xmlunit in Jython. Also able to use the methods in this class, and call them on a Diff object. The result of this method call is what I am trying to pass to assertTrue, when it throws the error.
from org.custommonkey.xmlunit import Diff
import org.junit.Assert
xml1 = ...some XML string...
xml2 = ...some XML string...
myDiff = Diff(xml1, xml2)
assertTrue(myDiff.similar())
Hope this additional information is useful in identifying a solution to this problem.
Latest Status
I narrowed it down to setting this property python.security.respectJavaAccessibility = false, since the Assert() constructor is protected.
Still trying to get it to work. Any help is greatly appreciated.
Figured it out.
In addition to junit.jar file, the hamcrest-core.jar file also needed to be copied to /Library/Java/Extensions.
Then I got rid of the jython.jar file, and instead installed it using the jython installer.
After the installation was completed, I updated the registry file in the installation folder, specifically setting this property python.security.respectJavaAccessibility = false.
Now I am able to see the assertTrue method, and no longer getting a NameError.