pojo testing with java 11 - unit-testing

I am trying to migrate our application from java-8 to java-11. I am facing issue with pojo junit testing. This is working with java-8 , but with java-11, pojo test class is not running. It looks below dependency is not supporting for java 11.
I have below dependency in dependencies.gradle
testImplementation("pl.pojo:pojo-tester:0.7.6")
Below is my PojoTest class
package com.product.model;
import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor;
import org.junit.Test;
import pl.pojo.tester.api.assertion.Method;
import com.product.CassOne;
import com.product.CassTwo;
import com.product.CassThree;
public class PojoTests {
#Test
public void testPojos() {
final Class<?>[] classesUnderTest = {
CassOne.class,
ClassTwo.class,
ClassThree.class};
for (Class<?> classUnderTest : classesUnderTest) {
assertPojoMethodsFor(classUnderTest).testing(Method.GETTER, Method.SETTER, Method.TO_STRING).areWellImplemented();
}
}
}
I am facing below Error
java.lang.NullPointerException at the line
assertPojoMethodsFor(classUnderTest).testing(Method.GETTER, Method.SETTER, Method.TO_STRING).areWellImplemented();
Any suggestion how I can resolve this or any other suggestion is most welcome.

have found alternate depedency which supports for java 11
testImplementation("com.obsidiandynamics.pojotester:pojotester:0.9.0")

You should check which version of apache-commons-lang3 you are using. Changing to versions 3.10 and up fixed the pojo issue for me.

Related

DataProvider is not an annotation type

I am Using TestNG with Selenium WebDriver. I am trying to get the 'data provider' annotation working in my Eclipse IDE. However, after adding overring on the annotation showing error 0
DataProvider is not an annotation type
package remoteTesting.dockervalidation;
import org.testng.annotations.Test;
public class DataProvider {
#Test
public void testcaseData() {}
#DataProvider (name = "DPS1")
public Object[][] createData1() throws Exception{
Object[][] retObjArr= {{"hello","text",1},{"bye","message",1},{"solo","call",453}};
return(retObjArr);
}
}
Its because your class name is 'DataProvider'. Please change the class name to something else (which will be of more meaning) and try to import DataProvider from testng.
I just uninstalled the TestNG plugin and installed it again and it worked for me.

JMockit can't find EJB, get NoSuchMethodException instead

Trying to mock a MessageDriven bean but have trouble getting the #EJB to be injected. The #Resource works "fine" (doesn't break it at least).
If I comment out the #EJB line in MyMDB it works fine. Probably an easy thing I missed, but I can't find it...
Also I found that replacing #EJB with #Inject will make it work, but I want to know why it doesn't work with #EJB since we have a lot of code like that.
Using JDK7 and JMockit v1.39
The error I get is:
java.lang.RuntimeException: java.lang.NoSuchMethodException: com.sun.proxy.$Proxy7.lookup()
Caused by: java.lang.NoSuchMethodException: com.sun.proxy.$Proxy7.lookup()
at java.lang.Class.getMethod(Class.java:1678)
MyMDB.java:
import javax.annotation.Resource;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageListener;
#MessageDriven(activationConfig = {
#ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
#ActivationConfigProperty(propertyName = "destination", propertyValue = "/queue/myqueue") })
public class MyMDB implements MessageListener {
#Resource(mappedName = "java:/JmsBT")
ConnectionFactory connectionFactory;
#EJB
ParConfigI parConfig;
#Override
public void onMessage(Message message) {
System.out.println("onMessage called");
}
}
MyMDBTest.java
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import org.junit.Test;
import mockit.Injectable;
import mockit.Mocked;
import mockit.Tested;
public class MyMDBTest {
#Tested
MyMDB sut;
#Injectable
ConnectionFactory jmsbt;
#Injectable
ParConfigI parConfigI;
#Mocked
Message mockedMessage;
#Test
public void testSmall() {
sut.onMessage(mockedMessage);
}
}
ParConfigI.java
import javax.ejb.Local;
#Local
public interface ParConfigI {
public void testmethod();
}
The problem is that JMockit attempts to read the lookup attribute on the #EJB annotation, but this attribute only exists in EJB 3.1+ (added in Java EE 6), not in EJB 3.0 (Java EE 5). Hence the NoSuchMethodException.
JMockit 1.40 is fixing this, but Java EE 6 has been available since early 2010. So, upgrading from the ancient Java EE 5 would also solve the problem.

Java8 cannot use wsgen with a webservice endpoint that extends another class (Works with Java7)

I'm trying to use wsgen to generate wsdl files. If my webservice class extends another class I get an error but if I remove the extends it works. This is the error message:
error: compilation failed, errors should have been reported
Also wsgen -fullversion:
wsgen full version "JAX-WS RI 2.2.9-b130926.1035 svn-revision#8c29a9a53251ff741fca1664a8221dc876b2eac8"
Please note that I only have this problem when I use Java8. But the same code works when I use Java 7, and wsgen -version:
JAX-WS RI 2.2.4-b01
Here is more details and how to reproduce it:
I'm using Java8 and I have three files:
webservice
basewebservice.java
webservice.java
webserviceImpl.java
basewebservice.java:
package webservice;
public class basewebservice { }
webservice.java
package webservice;
import javax.jws.WebMethod; import javax.jws.WebService;
#WebService
public interface webservice {
#WebMethod
public String hello();
}
webserviceImpl.java
package webservice;
import javax.jws.WebService;
#WebService(endpointInterface="webservice.webservice",
serviceName="webservice")
public class webserviceImpl extends basewebservice
implements webservice {
#Override
public String hello() {
return "heLLoo";
}
}
I use this command to generate wsdl file:
wsgen -cp "." webservice.webserviceImpl -r . -wsdl
It only works when I remove the extends basewebservice.
You need to use an #XMLSeeAlso annotation on the BaseWebService. Check out this question - Java Web Services/JAXB - Abstract superclass

Asynchronous Swift Testing of Protocols with XCTestCase

I'm trying to write a REST Api class in swift and test it. I was attempting to follow the methodology in: how to test asynchronous methods Swift but I seem to have run into an issue.
Client/RestInterface.swift
import Foundation
protocol RestSearchProtocol {
func didRecieveResponse(results: NSDictionary)
}
public class RestInterface : NSObject {
// lots of code we don't care about ...
}
ClientTests/RestInterfaceTests.swift
import UIKit
import XCTest
import Client
class RestInterfaceTests: XCTestCase, RestSearchProtocol {
// ... rest of the test file
I'm getting an undeclared type error.
Any suggestions as how to make this work?
As a side note - if i take the RestInterfaceTests class and put it at the end of RestInterface.swift it seems to find the protocol, but XCTestCase is now undeclared
It appears i was missing the public identifier:
import Foundation
public protocol RestSearchProtocol {
func didRecieveResponse(results: NSDictionary)
}
public class RestInterface : NSObject {
// lots of code we don't care about ...
}
has solved the problem
use
#testable import Client
You don't need to set your types as public anymore!

Grails Unit Test

I have unit test wich extends GrailsUnitTestCase :
import grails.test.GrailsUnitTestCase
class HttpdParserSpec extends GrailsUnitTestCase {
}
However I saw in Grails documentation that is deprecated.
I tried to use the following :
import grails.test.mixin.TestFor
#TestFor(HttpdParser)
class HttpdParserSpec {
}
I obtain the following error :
Cannot add Domain class [class fr.edu.toolprod.parser.HttpdParser]. It
is not a Domain!
It's true.It's not a Domain class.I only want test a simple class HttpdParser.
What am I doing wrong ?
So how to make a simple unit test ? Have you an example ?
Don't use the TestFor annotation. Just write a unit test as you normally would. TestFor is useful for rigging up Grails artifacts and relevant elements of the environment for unit testing them.
class HttpdParserSpec extends spock.lang.Specification {
void 'test something'() {
when:
def p = new HttpdParser()
p.doSomething()
then:
p.someValue == 42
}
}
You can also just use the #TestMixin annotation with the GrailsUnitTestCaseMixin like this:
import grails.test.mixin.support.GrailsUnitTestMixin
import grails.test.mixin.TestMixin
#TestMixin(GrailsUnitTestMixin)
class MyTestClass {}