Advertisement
Guest User

srikanth

a guest
Feb 5th, 2010
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1.  
  2. //Class MyFactory
  3.  
  4.  
  5. package com.pro.ws.trust;
  6.  
  7. import javax.xml.bind.JAXBContext;
  8. import javax.xml.bind.JAXBException;
  9.  
  10. public class MyFactory {
  11.     private static JAXBContext jaxbContext = null;
  12.  
  13.     public static void loadJaxbContext() {
  14.         try {
  15.             jaxbContext = JAXBContext
  16.                     .newInstance("com.pro.xml.ws.trust.impl.bindings:com.pro.xml.ws.trust.v14.impl.bindings:com.pro.xml.ws.security.secext.impl.bindings:com.pro.xml.ws.utility.impl.bindings");
  17.         } catch (JAXBException jbe) {
  18.             throw new RuntimeException(jbe.getMessage(), jbe);
  19.         }
  20.     }
  21. }
  22.  
  23.  
  24.  
  25.  
  26. // Class Mytest
  27.  
  28.  
  29. package com.pro.ws.trust;
  30.  
  31. public class MyTest {
  32.    
  33.     public static String justexeecute(){
  34.         return "Hello";
  35.     }
  36.  
  37. }
  38.  
  39.  
  40.  
  41. //Powermock test
  42.  
  43.  
  44. package com.pro.ws.trust;
  45.  
  46. import org.junit.Test;
  47. import org.junit.runner.RunWith;
  48. import org.mockito.Mockito;
  49. import org.powermock.api.mockito.PowerMockito;
  50. import org.powermock.core.classloader.annotations.PowerMockIgnore;
  51. import org.powermock.core.classloader.annotations.PrepareForTest;
  52. import org.powermock.modules.junit4.PowerMockRunner;
  53.  
  54. @PowerMockIgnore("com.pro.ws.trust.MyFactory")
  55. //@PrepareForTest(MyTest.class)
  56. @RunWith(PowerMockRunner.class)
  57.  
  58. public class PowermockTest {
  59.    
  60.     @Test
  61.     public void testSample() {
  62.      
  63.         try {
  64.             MyFactory.loadJaxbContext();
  65.             PowerMockito.mockStatic(MyTest.class);
  66.             //PowerMockito.when(MyTest.justexeecute()).thenReturn("dummy");
  67.             //System.out.println(MyTest.justexeecute());
  68.         } catch (Exception e) {
  69.             e.printStackTrace();
  70.             // TODO: handle exception
  71.         }
  72.    
  73.     }
  74.  
  75. }
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement