BAEL-831 ClassNotFoundExceptions vs NoClassDefFoundError (#1899)

* Dependency Injection examples

Dependency Injection examples for evaluation article

* Junit test cases added for dependency injection

Junit test cases added for dependency injection

* ClassNotFoundException vs NoClassDefFoundError

Example to reproduce ClassNotFoundException & NoClassDefFoundError

* JUnit test cases for ClassNotFoundException & NoClassDefFoundError

test cases to reproduce ClassNotFoundException & NoClassDefFoundError

* Deleting exampls for evaluation article

* BAEL-831 Examples for ClassNotFoundException & NoClassDefFoundError

* deleting config file for evaluation article

deleting config file for evaluation article
This commit is contained in:
parthkaria 2017-05-22 23:02:48 +05:30 committed by maibin
parent 45e16d409b
commit 28adbeb53d
5 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,7 @@
package com.baeldung.classnotfoundexception;
public class ClassNotFoundExceptionExample {
public void loadDrivers() throws ClassNotFoundException {
Class.forName("oracle.jdbc.driver.OracleDriver");
}
}

View File

@ -0,0 +1,5 @@
package com.baeldung.noclassdeffounderror;
public class ClassWithInitErrors {
static int data = 1 / 0;
}

View File

@ -0,0 +1,14 @@
package com.baeldung.noclassdeffounderror;
public class NoClassDefFoundErrorExample {
public ClassWithInitErrors getClassWithInitErrors() {
ClassWithInitErrors test;
try {
test = new ClassWithInitErrors();
} catch (Throwable t) {
System.out.println(t);
}
test = new ClassWithInitErrors();
return test;
}
}

View File

@ -0,0 +1,12 @@
package com.baeldung.classnotfoundexception;
import org.junit.Test;
public class ClassNotFoundExceptionTest {
@Test(expected = ClassNotFoundException.class)
public void givenNoDriversInClassPath_whenLoadDrivers_thenClassNotFoundException() throws ClassNotFoundException {
ClassNotFoundExceptionExample test = new ClassNotFoundExceptionExample();
test.loadDrivers();
}
}

View File

@ -0,0 +1,12 @@
package com.baeldung.noclassdeffounderror;
import org.junit.Test;
public class NoClassDefFoundErrorTest {
@Test(expected = NoClassDefFoundError.class)
public void givenInitErrorInClass_whenloadClass_thenNoClassDefFoundError() {
NoClassDefFoundErrorExample sample = new NoClassDefFoundErrorExample();
sample.getClassWithInitErrors();
}
}