accumulo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlmar...@comcast.net
Subject Re: Using powermock-api-mockito in tests?
Date Thu, 21 Mar 2013 21:11:56 GMT


We can do it with PowerMock, no need to add  Mockito. This should work, going from memory
here. I should be able to help when I get back to a computer if you have problems. 



  //Mock the method 

  PowerMock.mockStatic(System.class, System.class.getMethod("getenv")); 



  //Invoke it 

  Map<String, String> mockSystemProperties = new HashMap<String, String>();

  mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME")); 
  EasyMock.expect(System.getenv()).andReturn(mockSystemProperties); 



----- Original Message -----


From: "David Medinets" <david.medinets@gmail.com> 
To: "accumulo-dev" <dev@accumulo.apache.org> 
Sent: Thursday, March 21, 2013 4:59:40 PM 
Subject: Using powermock-api-mockito in tests? 

Is there any reason why I should not add a dependency in start/pom.xml 
to powermock-api-mockito? With this library, we can mock the call to 
System.getenv() which breaks the tests in AccumuloVFSClassLoaderTest. 
The two tests need these four lines of setup in order to pass: 

      Map<String, String> mockSystemProperties = new HashMap<String, String>();

      mockSystemProperties.put("ACCUMULO_HOME", System.getenv("HOME")); 

      PowerMockito.mockStatic(System.class); 
      Mockito.when(System.getenv()).thenReturn(mockSystemProperties); 

You'll notice that set ACCUMULO_HOME is set to the value of HOME to 
make the test cross-platform. 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message