Could not initialize class com.github.tomakehurst.wiremock.core.WireMockApp - java-11

I recently upgraded my Java version to Java11 for 8 and since then i am seeing this error:
java.lang.NoClassDefFoundError: Could not initialize class com.github.tomakehurst.wiremock.core.WireMockApp
at com.github.tomakehurst.wiremock.WireMockServer.(WireMockServer.java:73)
at com.github.tomakehurst.wiremock.WireMockServer.(WireMockServer.java:112)
Below you can find my usage of wiremock:
#RunWith(PowerMockRunner.class)
#PrepareForTest(ConfigManagement.class)
#PowerMockIgnore({"javax.management.*","com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*","com.github.tomakehurst.*"})
public class MandateEventsJobTest {
private static HikariDataSource dataSource;
private WireMockServer wireMockServer;
#Before
public void setUp() throws Exception {
wireMockServer = new WireMockServer(8080);
wireMockServer.start();
stubFor(get(urlPathMatching("/ping")).willReturn(aResponse().withBody("pong")));
...
I'm not able to resolve this issue. Please help.

Seems like there's an issue with PowerMockRunner in java version 9 or above. I added even more packages to #PowerMockIgnore({}) and it worked:
#PowerMockIgnore({"javax.management.","com.sun.org.apache.xerces.", "javax.xml.", "org.xml.", "com.sun.org.apache.xalan.", "javax.net."})

Related

Why is static variable unavailable in controller and how does DI help here

I am porting from traditional mvc to .net core
There is a static class where values are assigned on application start.
public static class WPSGlobalSettings
{
private static readonly string ToolboxDatabaseName = GetValue<string>("tbdatabasename", "db");
public static NpgsqlConnectionStringBuilder ToolboxConnString = build_conn_str(ToolboxDatabaseName);
...
}
However when I try to access it from Controller, it throws exception and is null
public class StatusController : Microsoft.AspNetCore.Mvc.ControllerBase
{
protected StatusDAL status_dal= new StatusDAL(WPSGlobalSettings.ToolboxConnString);
...
}
I want to understand why it stopped working after porting and how does Dependency Injection help here?
Note: I have resolved the issue here but want to clear my concepts.

bytebuddy official demo throw Exception "Class already loaded: class foo.Bar"

Section "Working with unloaded classes" in Official document give a demo, I run it on my machine then throw an exception Class already loaded: class foo.Bar。
class MyApplication {
public static void main(String[] args) {
TypePool typePool = TypePool.Default.ofSystemLoader();
new ByteBuddy()
.redefine(typePool.describe("foo.Bar").resolve(), // do not use 'Bar.class'
ClassFileLocator.ForClassLoader.ofSystemLoader())
.defineField("qux", String.class) // we learn more about defining fields later
.make()
.load(ClassLoader.getSystemClassLoader());
assertThat(Bar.class.getDeclaredField("qux"), notNullValue());
}
}
bytebuddy version is 1.10.22
The problem is in the last line Bar.class.getDeclaredField("qux") which loads the Bar class upon validation of the code. I fixed this in the example. Rather use the return value of load which returns Bar.

Can't use Processing 3 in IntelliJ

Well the thing is simple i guess.
I'm kinda of new in Java and IntelliJ but i wanted to use Processing in IntelliJ because of the auto - complete.
Well i've added the core.jar library from processing.
I've wrote the code (i tried with only what it is inside main and still won't work so i guess there is no problem with the overridden functions).
package com.company;
import processing.core.PApplet;
class MainClass extends PApplet {
#Override
public void setup() {
super.setup();
}
#Override
public void draw() {
super.draw();
}
#Override
public void settings() {
super.settings();
}
public static void main(String args[]) {
PApplet.main("Test");
}
}
(edit: i tried with MainClass and com.company.MainClass and didn't work either)
And when i tried to run it this pops out.
java.lang.RuntimeException: java.lang.ClassNotFoundException: Test
at processing.core.PApplet.runSketch(PApplet.java:10697)
at processing.core.PApplet.main(PApplet.java:10504)
at processing.core.PApplet.main(PApplet.java:10486)
at com.company.MainClass.main(MainClass.java:23)
Caused by: java.lang.ClassNotFoundException: Test
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at processing.core.PApplet.runSketch(PApplet.java:10690)
... 3 more
Your error is telling you that it can't find a class named Test. You're using a String value of "Test". Do you have a class named Test?
Your main class is called MainTest. But you're passing in a String value of "Test" to the PApplet.main() function. Where are you getting the "Test" value?
It should be:
PApplet.main("MainClass");
Or possibly:
PApplet.main("com.company.MainClass");
By the way, if autocomplete is the main reason you're switching to an IDE, I'd actually recommend sticking with the Processing editor. Using an IDE too soon will hide a lot of the stuff you need to learn from you.
And in the future, please don't post screenshots of code or error messages. Copy and paste them as text instead.

method does not override or implement a method from a supertype #Override

I am using bugsnag-react-native version 2.2.3, I am getting below error while building in android
"method does not override or implement a method from a supertype #override"
and in ios, it's working fine.
and when i comment #override in node_modules/bugsnag-react-native/android/src/main/java/com/bugsnag/BugsnagReactNative.java file then it' successfully build.
I replaced this
#override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
to
//#override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
and it's working
when i use latest version so i am getting so many errors.
So please suggest, Dont want to change in node module.
This issue was fixed in a later version. Could you try updating to the newest bugsnag-react-native version (2.7.0)?

junit.framework.AssertionFailedError: No tests found in register

I'm having a problem getting this test case to work. Can anyone point me in the right direction? I know I'm doing something wrong, I just don't know what.
import org.junit.*;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
#SuppressWarnings("deprecation")
public class register extends SeleneseTestCase {
Selenium selenium;
private SeleniumServer seleniumServer;
public static final String MAX_WAIT = "60000";
public final String CRN = "12761";
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
rc.setAvoidProxy(true);
rc.setSingleWindow(true);
rc.setReuseBrowserSessions(true);
seleniumServer = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://google.com/");
seleniumServer.start();
selenium.start();
}
#Test
public void register_test() throws Exception {
//TESTS IN HERE
}
#After
public void tearDown() throws Exception {
selenium.stop();
// Thread.sleep(500000);
}
}
And I'm getting the following errors:
junit.framework.AssertionFailedError: No tests found in register
at jumnit.framework.TestSuite$1.runTest(TestSuite.java:97)
I'm stumped.
You can't both extend TestCase (or SeleniumTestCase) and also use JUnit annotations (#Test). The test runners for JUnit3 and 4 are different, and my assumption is when JUnit sees that you've extended TestCase, it uses the old runner.
Remove the #Test annotation, and instead follow the old convention of naming your test with the word "test" prefixed, and that will fix it.
public void testRegister() throws Exception {
//TESTS IN HERE
}
PS. I'd recommend following more standard Java naming conventions, such as camel casing.
PPS. Here's a link that explains this in more detail.
This means you did not created method names starting with test in following test cases class what you running currently
I was able to solve this error in my case--that is, running tests with a <junit> Ant task--by pointing to a 1.7 or later version of Ant. Ant 1.7+ honors nested <classpath> elements, in which I was pointing to a JUnit 4.x jar, which as CodeSpelunker indicated understands #Test annotations. http://ant.apache.org/faq.html#delegating-classloader provided the aha moment for me.
I'm using mockk in Kotlin for Android and I had this error.
My class was declared like this (autogenerated by Android Studio):
class MyClassTest : TestCase() {
but removing TestCase fixed the error
class MyClassTest {