Created
May 22, 2012 12:03
-
-
Save mechamogera/2768618 to your computer and use it in GitHub Desktop.
jmokitによる環境変数(System.getenv())の追加
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mymock.test; | |
import junit.framework.TestCase; | |
import mockit.Mocked; | |
import mockit.NonStrictExpectations; | |
import java.util.Map; | |
public class SystemTest extends TestCase { | |
private Map<String, String> envs = null; | |
public void test() { | |
envs = System.getenv(); | |
new NonStrictExpectations() { | |
@Mocked("getenv") System system; // getenv()のみ部分モック | |
{ | |
System.getenv(); | |
returns(envs); | |
for (Map.Entry<String, String> env : envs.entrySet()) { | |
System.getenv(env.getKey()); | |
returns(env.getValue()); | |
} | |
// 環境変数追加 | |
System.getenv("hoge"); | |
returns("hoge"); | |
} | |
}; | |
assertEquals("hoge", System.getenv("hoge"); // 追加した環境変数確認 | |
for (Map.Entry<String, String> env : envs.entrySet()) { // 既存の環境変数確認 | |
System.out.println(env.getKey()); | |
System.out.println(System.getenv(env.getKey())); | |
System.out.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment