差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
study:java:powermock:mocking [2020/05/12 01:15] – [Mock Protected Parent Method] bananastudy:java:powermock:mocking [2020/05/12 01:19] (現在) – [Mock Protected Parent Method] banana
行 148: 行 148:
 Parent classにあるprotected methodの振る舞いを定義する例を紹介する。 Parent classにあるprotected methodの振る舞いを定義する例を紹介する。
  
 +親クラスの例を次に示す。
 <code java> <code java>
 package parent; package parent;
行 154: 行 155:
  
     protected void foo(String arg1, String arg2) {     protected void foo(String arg1, String arg2) {
-        //Logic here+        //some logic here
     }     }
 } }
 </code> </code>
  
 +子クラスの例を次に示す。
 <code java> <code java>
 package child; package child;
行 166: 行 168:
 public class Child extends Parent { public class Child extends Parent {
  
-    public String boo() {+    public String bar() {
         //call parent method         //call parent method
         this.foo();         this.foo();
行 175: 行 177:
 </code> </code>
  
 +テストクラスの例を次に示す。
 <code java> <code java>
 package child; package child;
行 185: 行 188:
 import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
  
-@PrepareForTest({ Parent.class, Child.class })+@PrepareForTest({Parent.class, Child.class})
 public class ChildTest { public class ChildTest {
     //Class Under Test     //Class Under Test
行 192: 行 195:
     @Before     @Before
     public void setUp() throws Exception {     public void setUp() throws Exception {
-        // Partial mock to mock methods in parent class+        //Partial mock to mock methods in parent class
         cut = spy(new Child());         cut = spy(new Child());
  
行 200: 行 203:
  
     @Test     @Test
-    public void testBoo() {+    public void testBar() {
         //call test method         //call test method
         cut.bar();         cut.bar();
行 208: 行 211:
  
 </code> </code>
 +ここでは、親クラスのfooメソッドが呼ばれた際、何もしない(doNothing)を実装している。
  

QR Code
QR Code study:java:powermock:mocking (generated for current page)