Reputation: 327
I have a DateAdapter class where am marshaling date type into String type and unmarshaling string data type into Date type via 2 methods mrashall and unmarshall. So my test methods are not running.
public class DateAdapter extends XmlAdapter<String, LocalDate> {
private static final String FORMAT = "yyyy-MM-dd";
/**
* Java Type => XML
*
* @param date unmappable Java object (date)
* @return desired XML representation
* @throws Exception
*/
public String marshal(LocalDate date) throws Exception {
if (date == null) {
return null;
}
return date.toString(FORMAT);
}
/**
* String Type => Java Type
*
* @param dateString String needs to parse into java type
* @return desired Java Type representation
* @throws Exception
*/
@Override
public LocalDate unmarshal(String dateString) throws Exception {
if (StringUtils.isNotBlank(dateString)) {
DateTimeFormatter formatter = DateTimeFormat.forPattern(FORMAT);
DateTime dateTime = formatter.parseDateTime(dateString);
return dateTime.toLocalDate();
}
return null;
}
}
I am using Junit, testNG, maven 2.2 and eclipse Juno. Right click to test cases won't execute test methods.
public class DateAdapterTest {
/* Date adapter is a class to marshall date type into String and unmarshall
viseversa.
*/
DateAdapter dateAdapter;
private static final String DATE_FORMAT = "2014-01-01";
private static final LocalDate DATE = new LocalDate(2014, 01, 01);
@BeforeClass
public void setUp(){
dateAdapter = new DateAdapter();
}
/*
* @param Date Date type
* @return String String data type date
* @throw Exception
*/
@Test
public void testMarshal() throws Exception{
String dateString = dateAdapter.marshal(DATE) ;
assertEquals(DATE_FORMAT, dateString);
}
/*
* @param String String data type
* @return date LocalDate type date
* @throw Exception
*/
@Test
public void testUnmarshal() throws Exception{
LocalDate date = dateAdapter.unmarshal(DATE_FORMAT);
assertEquals(DATE , date);
}
}
java.lang.NoSuchMethodError: org.junit.runner.Request.classWithoutSuiteMethod(Ljava/lang/Class;)Lorg/junit/runner/Request;
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestMethodReference.createRequest(JUnit4TestMethodReference.java:31)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestMethodReference.<init>(JUnit4TestMethodReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:54)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Upvotes: 2
Views: 5918
Reputation: 361
Upgrade to Junit 4.4, this is an old issue who should be fixed by now. See http://www.java-tutorial.ch/software-testing/junit-error-classwithoutsuitemethod
Upvotes: 1
Reputation: 115338
First you have to decide which framework to use: JUnit or TestNG. Once you decided check which @Test
annotation are you using. I guess that you marked tests using @Test
from TestNG and try to run the tests using JUnit.
Upvotes: 5