Skip to content

Commit

Permalink
Restored the support for mocking-up java.lang.System when running on …
Browse files Browse the repository at this point in the history
…IBM JRE 7+; closes #155.
  • Loading branch information
rliesenfeld committed Mar 19, 2015
1 parent 46062b4 commit d15101c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
7 changes: 1 addition & 6 deletions main/src/mockit/internal/mockups/MockClassSetup.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2014 Rogério Liesenfeld
* Copyright (c) 2006-2015 Rogério Liesenfeld
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit.internal.mockups;
Expand All @@ -15,7 +15,6 @@
import mockit.internal.state.*;
import mockit.internal.util.*;
import static mockit.external.asm.ClassReader.*;
import static mockit.internal.util.Utilities.*;

import org.jetbrains.annotations.*;

Expand Down Expand Up @@ -106,10 +105,6 @@ private Set<Class<?>> redefineMethodsInClassHierarchy()
private byte[] modifyRealClass(@NotNull Class<?> classToModify)
{
if (rcReader == null) {
if (!HOTSPOT_VM && classToModify == System.class) {
return null;
}

rcReader = createClassReaderForRealClass(classToModify);
}

Expand Down
40 changes: 23 additions & 17 deletions main/test/mockit/ReentrantMockTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2014 Rogério Liesenfeld
* Copyright (c) 2006-2015 Rogério Liesenfeld
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit;
Expand All @@ -9,6 +9,8 @@
import org.junit.*;
import static org.junit.Assert.*;

import static mockit.internal.util.Utilities.*;

public final class ReentrantMockTest
{
public static class RealClass
Expand Down Expand Up @@ -228,24 +230,28 @@ public void reentrantMockForJREClassWhichCallsAnotherFromADifferentThread()
System.setProperty("a", "1");
System.setProperty("b", "2");

new MockUp<System>() {
String property;
if (HOTSPOT_VM) { // causes main thread to hang up on IBM JRE
new MockUp<System>()
{
String property;

@Mock
String getProperty(Invocation inv, String key) { return inv.proceed(); }
@Mock
String getProperty(Invocation inv, String key) { return inv.proceed(); }

@Mock
String clearProperty(final String key) throws InterruptedException
{
Thread t = new Thread() {
@Override
public void run() { property = System.getProperty(key); }
};
t.start();
t.join();
return property;
}
};
@Mock
String clearProperty(final String key) throws InterruptedException
{
Thread t = new Thread()
{
@Override
public void run() { property = System.getProperty(key); }
};
t.start();
t.join();
return property;
}
};
}

assertEquals("1", System.getProperty("a"));
assertEquals("2", System.clearProperty("b"));
Expand Down

0 comments on commit d15101c

Please sign in to comment.