私はMockitoとPowerMockitoも新しくなっています。静的メソッドを純粋なMockitoでテストすることができないことがわかったので、私はPowerMockitoというユーザに必要です(右?)。私は、だから私はそれを確認する必要があり、この非常に簡単な方法で検証と呼ばれる非常に単純なクラス私はどんな理由で嘲笑すべきですか?
public class Validate {
public final static void stateNotNull(
final Object object,
final String message) {
if (message == null) {
throw new IllegalArgumentException("Exception message is a null object!");
}
if (object == null) {
throw new IllegalStateException(message);
}
}
を持って
:
1)私は、ヌルメッセージ引数の静的メソッドは、はIllegalArgumentExceptionが呼び出されることを呼び出します
2)私は、私がこれまでのところ、私はこのテストを書いてしまった何からヌルオブジェクト引数上の静的メソッドは、IllegalStateExceptionがが
と呼ばれていることを呼び出します。
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.isNull;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.testng.annotations.Test;
@RunWith(PowerMockRunner.class)
@PrepareForTest(Validate.class)
public class ValidateTestCase {
@Test(expectedExceptions = { IllegalStateException.class })
public void stateNotNullTest() throws Exception {
PowerMockito.mockStatic(Validate.class);
Validate mock = PowerMockito.mock(Validate.class);
PowerMockito.doThrow(new IllegalStateException())
.when(mock)
.stateNotNull(isNull(), anyString());
Validate.stateNotNull(null, null);
}
}
だからこれは私が検証クラスをモックと私はモックを対象とメッセージとして任意の文字列としてnullを引数とそのメソッドで呼び出されたときは、IllegalStateExceptionがスローされていることを確認していたという。
今、私は本当にそれを取得していません。なぜ私はそのメソッドを直接呼び出すことができないのですか?そのブーストーマジック全体をその静的クラスを嘲笑することで捨てるのですか?私がValidate.stateNotNullを呼び出さない限り、テストはとにかく進みます...私は何故それを嘲笑すべきですか?