Skip to content

Commit

Permalink
Check for .java for JDK class (close #256)
Browse files Browse the repository at this point in the history
  • Loading branch information
henri-tremblay committed Jan 8, 2023
1 parent 6a9ab53 commit 9648793
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ private <T> ClassLoader classLoader(Class<T> toMock) {
private static <T> boolean isJdkClassOrWithoutPackage(Class<T> toMock) {
// null class loader means we are from the bootstrap class loader, the mocks will go in another package in class loader
// we need to verify for null since some dynamic classes have no package
return toMock.getPackage() == null || toMock.getClassLoader() == null;
// and I still verify for .java, which isn't perfect but a start, for classes hacked to another class loader like PowerMock does
return toMock.getPackage() == null || toMock.getClassLoader() == null || toMock.getName().startsWith("java.");
}

private ClassLoadingStrategy<ClassLoader> classLoadingStrategy() {
Expand Down
8 changes: 8 additions & 0 deletions test-integration/src/test/java/org/itests/PowermockTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
import org.powermock.modules.junit4.PowerMockRunner;

import java.net.URL;
import java.sql.Timestamp;

import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.mock;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.powermock.api.easymock.PowerMock.*;
Expand Down Expand Up @@ -75,5 +78,10 @@ public void mockType() {
assertEquals(getClass(), EasyMockSupport.getMockedClass(mock));
}

@Test
public void javaSqlPackage() {
Timestamp t = mock(Timestamp.class);
assertNotNull(t);
}
}

0 comments on commit 9648793

Please sign in to comment.