BAEL-4220 | A Guide to IllegalAccessError and when it happens (#10798)
* BAEL-4220 | A Guide to IllegalAccessError and when it happens * BAEL-4220 | A Guide to IllegalAccessError and when it happens | fix tests * BAEL-4220 | A Guide to IllegalAccessError and when it happens | fix tests * BAEL-4220 | A Guide to IllegalAccessError and when it happens | BDD test names
This commit is contained in:
parent
263bfcfdd1
commit
fa55f989d6
|
@ -0,0 +1,8 @@
|
|||
package com.baeldung.exceptions.illegalaccesserror;
|
||||
|
||||
public class Class1 {
|
||||
|
||||
public void bar() {
|
||||
System.out.println("SUCCESS");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.baeldung.exceptions.illegalaccesserror;
|
||||
|
||||
public class Class2 {
|
||||
|
||||
public void foo() {
|
||||
Class1 c1 = new Class1();
|
||||
c1.bar();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.baeldung.exceptions.illegalaccesserror;
|
||||
|
||||
public class IllegalAccessErrorExample {
|
||||
|
||||
interface Baeldung {
|
||||
public default void foobar() {
|
||||
System.out.println("This is a default method.");
|
||||
}
|
||||
}
|
||||
|
||||
class Super {
|
||||
private void foobar() {
|
||||
System.out.println("SuperClass method foobar");
|
||||
}
|
||||
}
|
||||
|
||||
class MySubClass extends Super implements Baeldung {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.baeldung.exceptions.illegalaccesserror;
|
||||
|
||||
public class IllegalAccessErrorSolved {
|
||||
|
||||
interface BaeldungSolved {
|
||||
public default void foobar() {
|
||||
System.out.println("This is a default method.");
|
||||
}
|
||||
}
|
||||
|
||||
class SuperSolved {
|
||||
public void foobar() {
|
||||
System.out.println("SuperClass method foobar");
|
||||
}
|
||||
}
|
||||
|
||||
class MySubClassSolved extends SuperSolved implements BaeldungSolved {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.exceptions.illegalaccesserror;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class IllegalAccessErrorExampleUnitTest {
|
||||
|
||||
@Test()
|
||||
public void givenInterfaceDefaultMethOverriddenPrivateAccess_whenInvoked_thenIllegalAccessError() {
|
||||
Assertions.assertThrows(IllegalAccessError.class, () -> {
|
||||
new IllegalAccessErrorExample().new MySubClass().foobar();
|
||||
});
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void givenClass1Class2_whenSameClassDefintion_thenNoIllegalAccessError() {
|
||||
Assertions.assertDoesNotThrow(() -> {
|
||||
new Class2().foo();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.baeldung.exceptions.illegalaccesserror;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class IllegalAccessErrorSolvedUnitTest {
|
||||
|
||||
@Test()
|
||||
public void givenInterfaceDefaultMethOverriddenNonPrivateAccess_whenInvoked_thenNoIllegalAccessError() {
|
||||
Assertions.assertDoesNotThrow(() -> {
|
||||
new IllegalAccessErrorSolved().new MySubClassSolved().foobar();
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue