mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
agent: remove powermock from tests (#7637)
This commit is contained in:
parent
27b0a64b40
commit
e26d49de4d
@ -26,20 +26,21 @@ import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.agent.properties.AgentProperties;
|
||||
import com.cloud.agent.properties.AgentPropertiesFileHandler;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.cloud.utils.StringUtils;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.Spy;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AgentShellTest {
|
||||
|
||||
@InjectMocks
|
||||
@ -58,6 +59,18 @@ public class AgentShellTest {
|
||||
@Mock
|
||||
UUID uuidMock;
|
||||
|
||||
MockedStatic<AgentPropertiesFileHandler> agentPropertiesFileHandlerMocked;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
agentPropertiesFileHandlerMocked = Mockito.mockStatic(AgentPropertiesFileHandler.class, Mockito.CALLS_REAL_METHODS);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
agentPropertiesFileHandlerMocked.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseCommand() throws ConfigurationException {
|
||||
AgentShell shell = new AgentShell();
|
||||
@ -106,44 +119,35 @@ public class AgentShellTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest(AgentPropertiesFileHandler.class)
|
||||
public void getPortOrWorkersTestValueIsNullGetFromProperty() {
|
||||
int expected = 195;
|
||||
PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
|
||||
PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(expected);
|
||||
agentPropertiesFileHandlerMocked.when(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(expected);
|
||||
|
||||
int result = agentShellSpy.getPortOrWorkers(null, propertyIntegerMock);
|
||||
Assert.assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest(AgentPropertiesFileHandler.class)
|
||||
public void getPortOrWorkersTestValueIsNotAValidIntegerReturnDefaultFromProperty() {
|
||||
int expected = 42;
|
||||
|
||||
PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
|
||||
Mockito.doReturn(expected).when(propertyIntegerMock).getDefaultValue();
|
||||
|
||||
int result = agentShellSpy.getPortOrWorkers("test", propertyIntegerMock);
|
||||
Assert.assertEquals(expected, result);
|
||||
|
||||
PowerMockito.verifyStatic(AgentPropertiesFileHandler.class, Mockito.never());
|
||||
AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
|
||||
agentPropertiesFileHandlerMocked.verify(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any()), Mockito.never());
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest(AgentPropertiesFileHandler.class)
|
||||
public void getPortOrWorkersTestValueIsAValidIntegerReturnValue() {
|
||||
int expected = 42;
|
||||
|
||||
PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
|
||||
Mockito.doReturn(79).when(propertyIntegerMock).getDefaultValue();
|
||||
|
||||
int result = agentShellSpy.getPortOrWorkers(String.valueOf(expected), propertyIntegerMock);
|
||||
Assert.assertEquals(expected, result);
|
||||
|
||||
PowerMockito.verifyStatic(AgentPropertiesFileHandler.class, Mockito.never());
|
||||
AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
|
||||
agentPropertiesFileHandlerMocked.verify(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any()), Mockito.never());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -183,41 +187,34 @@ public class AgentShellTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest(AgentPropertiesFileHandler.class)
|
||||
public void getZoneOrPodTestValueIsNullAndPropertyStartsAndEndsWithAtSignReturnPropertyDefaultValue() {
|
||||
String expected = "default";
|
||||
|
||||
PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
|
||||
PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn("test");
|
||||
agentPropertiesFileHandlerMocked.when(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn("test");
|
||||
|
||||
Mockito.doReturn(true).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
|
||||
Mockito.doReturn(expected).when(propertyStringMock).getDefaultValue();
|
||||
|
||||
String result = agentShellSpy.getZoneOrPod(null, propertyStringMock);
|
||||
Assert.assertEquals(expected, result);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest(AgentPropertiesFileHandler.class)
|
||||
public void getZoneOrPodTestValueIsNullAndPropertyDoesNotStartAndEndWithAtSignReturnPropertyDefaultValue() {
|
||||
String expected = "test";
|
||||
|
||||
PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
|
||||
PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(expected);
|
||||
agentPropertiesFileHandlerMocked.when(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(expected);
|
||||
|
||||
Mockito.doReturn(false).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
|
||||
Mockito.doReturn("default").when(propertyStringMock).getDefaultValue();
|
||||
|
||||
String result = agentShellSpy.getZoneOrPod(null, propertyStringMock);
|
||||
Assert.assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest(AgentPropertiesFileHandler.class)
|
||||
public void getZoneOrPodTestValueIsNotNullAndStartsAndEndsWithAtSignReturnPropertyDefaultValue() {
|
||||
String expected = "default";
|
||||
|
||||
PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
|
||||
|
||||
Mockito.doReturn(true).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
|
||||
Mockito.doReturn(expected).when(propertyStringMock).getDefaultValue();
|
||||
@ -225,25 +222,20 @@ public class AgentShellTest {
|
||||
String result = agentShellSpy.getZoneOrPod("test", propertyStringMock);
|
||||
Assert.assertEquals(expected, result);
|
||||
|
||||
PowerMockito.verifyStatic(AgentPropertiesFileHandler.class, Mockito.never());
|
||||
AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
|
||||
agentPropertiesFileHandlerMocked.verify(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any()), Mockito.never());
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest(AgentPropertiesFileHandler.class)
|
||||
public void getZoneOrPodTestValueIsNotNullAndDoesNotStartAndEndWithAtSignReturnPropertyDefaultValue() {
|
||||
String expected = "test";
|
||||
|
||||
PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
|
||||
|
||||
Mockito.doReturn(false).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
|
||||
Mockito.doReturn("default").when(propertyStringMock).getDefaultValue();
|
||||
|
||||
String result = agentShellSpy.getZoneOrPod(expected, propertyStringMock);
|
||||
Assert.assertEquals(expected, result);
|
||||
|
||||
PowerMockito.verifyStatic(AgentPropertiesFileHandler.class, Mockito.never());
|
||||
AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
|
||||
agentPropertiesFileHandlerMocked.verify(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any()), Mockito.never());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -255,12 +247,10 @@ public class AgentShellTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest(AgentPropertiesFileHandler.class)
|
||||
public void getGuidTestGuidIsNullReturnProperty() throws ConfigurationException {
|
||||
String expected = "test";
|
||||
|
||||
PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
|
||||
PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(expected);
|
||||
agentPropertiesFileHandlerMocked.when(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(expected);
|
||||
|
||||
String result = agentShellSpy.getGuid(null);
|
||||
|
||||
@ -268,34 +258,34 @@ public class AgentShellTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest({AgentShell.class, AgentPropertiesFileHandler.class})
|
||||
public void getGuidTestGuidAndPropertyAreNullIsDeveloperGenerateNewUuid() throws ConfigurationException {
|
||||
String expected = "test";
|
||||
|
||||
PowerMockito.mockStatic(AgentPropertiesFileHandler.class, UUID.class);
|
||||
PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(null, true);
|
||||
PowerMockito.when(UUID.randomUUID()).thenReturn(uuidMock);
|
||||
agentPropertiesFileHandlerMocked.when(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(null, true);
|
||||
MockedStatic<UUID> uuidMocked = Mockito.mockStatic(UUID.class);
|
||||
uuidMocked.when(() -> UUID.randomUUID()).thenReturn(uuidMock);
|
||||
Mockito.doReturn(expected).when(uuidMock).toString();
|
||||
|
||||
String result = agentShellSpy.getGuid(null);
|
||||
|
||||
Assert.assertEquals(expected, result);
|
||||
uuidMocked.close();
|
||||
}
|
||||
|
||||
@Test(expected = ConfigurationException.class)
|
||||
@PrepareForTest(AgentPropertiesFileHandler.class)
|
||||
public void getGuidTestGuidAndPropertyAreNullIsNotDeveloperThrowConfigurationException() throws ConfigurationException {
|
||||
PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
|
||||
PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(null, false);
|
||||
|
||||
agentPropertiesFileHandlerMocked.when(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(null, false);
|
||||
|
||||
agentShellSpy.getGuid(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest(AgentPropertiesFileHandler.class)
|
||||
public void setHostTestValueIsNotNullAndStartsAndEndsWithAtSignThrowConfigurationException(){
|
||||
Mockito.doReturn(true).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
|
||||
PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
|
||||
|
||||
|
||||
|
||||
|
||||
boolean error = false;
|
||||
|
||||
@ -309,16 +299,14 @@ public class AgentShellTest {
|
||||
throw new AssertionError("This test expects a ConfigurationException.");
|
||||
}
|
||||
|
||||
PowerMockito.verifyStatic(AgentPropertiesFileHandler.class, Mockito.never());
|
||||
AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
|
||||
agentPropertiesFileHandlerMocked.verify(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any()), Mockito.never());
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest(AgentPropertiesFileHandler.class)
|
||||
public void setHostTestValueIsNullPropertyStartsAndEndsWithAtSignThrowConfigurationException(){
|
||||
Mockito.doReturn(true).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
|
||||
PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
|
||||
PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn("test");
|
||||
|
||||
agentPropertiesFileHandlerMocked.when(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn("test");
|
||||
|
||||
boolean error = false;
|
||||
|
||||
@ -332,37 +320,32 @@ public class AgentShellTest {
|
||||
throw new AssertionError("This test expects a ConfigurationException.");
|
||||
}
|
||||
|
||||
PowerMockito.verifyStatic(AgentPropertiesFileHandler.class);
|
||||
AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
|
||||
agentPropertiesFileHandlerMocked.verify(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest(AgentPropertiesFileHandler.class)
|
||||
public void setHostTestValueIsNotNullAndDoesNotStartAndEndWithAtSignSetHosts() throws ConfigurationException {
|
||||
String expected = "test";
|
||||
Mockito.doReturn(false).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
|
||||
PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
|
||||
|
||||
agentShellSpy.setHost(expected);
|
||||
|
||||
PowerMockito.verifyStatic(AgentPropertiesFileHandler.class, Mockito.never());
|
||||
AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
|
||||
agentPropertiesFileHandlerMocked.verify(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any()), Mockito.never());
|
||||
|
||||
Mockito.verify(agentShellSpy).setHosts(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest(AgentPropertiesFileHandler.class)
|
||||
public void setHostTestValueIsNullPropertyDoesNotStartAndEndWithAtSignSetHosts() throws ConfigurationException {
|
||||
String expected = "test";
|
||||
|
||||
Mockito.doReturn(false).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
|
||||
PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
|
||||
PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(expected);
|
||||
|
||||
agentPropertiesFileHandlerMocked.when(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(expected);
|
||||
|
||||
agentShellSpy.setHost(null);
|
||||
|
||||
PowerMockito.verifyStatic(AgentPropertiesFileHandler.class);
|
||||
agentPropertiesFileHandlerMocked.verify(() -> AgentPropertiesFileHandler.getPropertyValue(Mockito.any()));
|
||||
AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
|
||||
|
||||
Mockito.verify(agentShellSpy).setHosts(expected);
|
||||
|
||||
@ -24,18 +24,17 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.commons.beanutils.ConvertUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({PropertiesUtil.class, ConvertUtils.class})
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AgentPropertiesFileHandlerTest extends TestCase {
|
||||
|
||||
@Mock
|
||||
@ -53,14 +52,27 @@ public class AgentPropertiesFileHandlerTest extends TestCase {
|
||||
@Mock
|
||||
Properties propertiesMock;
|
||||
|
||||
MockedStatic<PropertiesUtil> propertiesUtilMocked;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
propertiesUtilMocked = Mockito.mockStatic(PropertiesUtil.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
propertiesUtilMocked.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPropertyValueTestFileNotFoundReturnDefaultValueNull() throws Exception{
|
||||
String expectedResult = null;
|
||||
|
||||
AgentProperties.Property<String> agentPropertiesStringMock = new AgentProperties.Property<String>("Test-null", null, String.class);
|
||||
|
||||
PowerMockito.mockStatic(PropertiesUtil.class);
|
||||
PowerMockito.doReturn(null).when(PropertiesUtil.class, "findConfigFile", Mockito.anyString());
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.findConfigFile(Mockito.anyString())).thenReturn(null);
|
||||
|
||||
String result = AgentPropertiesFileHandler.getPropertyValue(agentPropertiesStringMock);
|
||||
|
||||
@ -72,8 +84,7 @@ public class AgentPropertiesFileHandlerTest extends TestCase {
|
||||
String expectedResult = "default value";
|
||||
Mockito.doReturn(expectedResult).when(agentPropertiesStringMock).getDefaultValue();
|
||||
|
||||
PowerMockito.mockStatic(PropertiesUtil.class);
|
||||
PowerMockito.doReturn(null).when(PropertiesUtil.class, "findConfigFile", Mockito.anyString());
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.findConfigFile(Mockito.anyString())).thenReturn(null);
|
||||
|
||||
String result = AgentPropertiesFileHandler.getPropertyValue(agentPropertiesStringMock);
|
||||
|
||||
@ -85,9 +96,8 @@ public class AgentPropertiesFileHandlerTest extends TestCase {
|
||||
String expectedResult = "default value";
|
||||
Mockito.doReturn(expectedResult).when(agentPropertiesStringMock).getDefaultValue();
|
||||
|
||||
PowerMockito.mockStatic(PropertiesUtil.class);
|
||||
PowerMockito.doReturn(fileMock).when(PropertiesUtil.class, "findConfigFile", Mockito.anyString());
|
||||
PowerMockito.doThrow(new IOException()).when(PropertiesUtil.class, "loadFromFile", Mockito.any());
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.findConfigFile(Mockito.anyString())).thenReturn(fileMock);
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.loadFromFile(Mockito.any())).thenThrow(new IOException());
|
||||
|
||||
String result = AgentPropertiesFileHandler.getPropertyValue(agentPropertiesStringMock);
|
||||
|
||||
@ -100,10 +110,9 @@ public class AgentPropertiesFileHandlerTest extends TestCase {
|
||||
Mockito.doReturn(expectedResult).when(agentPropertiesStringMock).getDefaultValue();
|
||||
Mockito.doReturn("name").when(agentPropertiesStringMock).getName();
|
||||
|
||||
PowerMockito.mockStatic(PropertiesUtil.class);
|
||||
PowerMockito.doReturn(fileMock).when(PropertiesUtil.class, "findConfigFile", Mockito.anyString());
|
||||
PowerMockito.doReturn(propertiesMock).when(PropertiesUtil.class, "loadFromFile", Mockito.any());
|
||||
PowerMockito.doReturn("").when(propertiesMock).getProperty(Mockito.anyString());
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.findConfigFile(Mockito.anyString())).thenReturn(fileMock);
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.loadFromFile(Mockito.any())).thenReturn(propertiesMock);
|
||||
propertiesUtilMocked.when(() -> propertiesMock.getProperty(Mockito.anyString())).thenReturn("");
|
||||
|
||||
String result = AgentPropertiesFileHandler.getPropertyValue(agentPropertiesStringMock);
|
||||
|
||||
@ -116,10 +125,9 @@ public class AgentPropertiesFileHandlerTest extends TestCase {
|
||||
Mockito.doReturn(expectedResult).when(agentPropertiesStringMock).getDefaultValue();
|
||||
Mockito.doReturn("name").when(agentPropertiesStringMock).getName();
|
||||
|
||||
PowerMockito.mockStatic(PropertiesUtil.class);
|
||||
PowerMockito.doReturn(fileMock).when(PropertiesUtil.class, "findConfigFile", Mockito.anyString());
|
||||
PowerMockito.doReturn(propertiesMock).when(PropertiesUtil.class, "loadFromFile", Mockito.any());
|
||||
PowerMockito.doReturn(null).when(propertiesMock).getProperty(Mockito.anyString());
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.findConfigFile(Mockito.anyString())).thenReturn(fileMock);
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.loadFromFile(Mockito.any())).thenReturn(propertiesMock);
|
||||
propertiesUtilMocked.when(() -> propertiesMock.getProperty(Mockito.anyString())).thenReturn(null);
|
||||
|
||||
String result = AgentPropertiesFileHandler.getPropertyValue(agentPropertiesStringMock);
|
||||
|
||||
@ -132,9 +140,8 @@ public class AgentPropertiesFileHandlerTest extends TestCase {
|
||||
Mockito.doReturn("default value").when(agentPropertiesStringMock).getDefaultValue();
|
||||
Mockito.doReturn("name").when(agentPropertiesStringMock).getName();
|
||||
|
||||
PowerMockito.mockStatic(PropertiesUtil.class);
|
||||
PowerMockito.doReturn(fileMock).when(PropertiesUtil.class, "findConfigFile", Mockito.anyString());
|
||||
PowerMockito.doReturn(propertiesMock).when(PropertiesUtil.class, "loadFromFile", Mockito.any());
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.findConfigFile(Mockito.anyString())).thenReturn(fileMock);
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.loadFromFile(Mockito.any())).thenReturn(propertiesMock);
|
||||
Mockito.doReturn(expectedResult).when(propertiesMock).getProperty(Mockito.anyString());
|
||||
|
||||
String result = AgentPropertiesFileHandler.getPropertyValue(agentPropertiesStringMock);
|
||||
@ -148,9 +155,8 @@ public class AgentPropertiesFileHandlerTest extends TestCase {
|
||||
|
||||
AgentProperties.Property<String> agentPropertiesStringMock = new AgentProperties.Property<String>("Test-null", null, String.class);
|
||||
|
||||
PowerMockito.mockStatic(PropertiesUtil.class);
|
||||
PowerMockito.doReturn(fileMock).when(PropertiesUtil.class, "findConfigFile", Mockito.anyString());
|
||||
PowerMockito.doReturn(propertiesMock).when(PropertiesUtil.class, "loadFromFile", Mockito.any());
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.findConfigFile(Mockito.anyString())).thenReturn(fileMock);
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.loadFromFile(Mockito.any())).thenReturn(propertiesMock);
|
||||
Mockito.doReturn(expectedResult).when(propertiesMock).getProperty(Mockito.anyString());
|
||||
|
||||
String result = AgentPropertiesFileHandler.getPropertyValue(agentPropertiesStringMock);
|
||||
@ -165,9 +171,8 @@ public class AgentPropertiesFileHandlerTest extends TestCase {
|
||||
Mockito.doReturn("name").when(agentPropertiesIntegerMock).getName();
|
||||
Mockito.doReturn(Integer.class).when(agentPropertiesIntegerMock).getTypeClass();
|
||||
|
||||
PowerMockito.mockStatic(PropertiesUtil.class);
|
||||
PowerMockito.doReturn(fileMock).when(PropertiesUtil.class, "findConfigFile", Mockito.anyString());
|
||||
PowerMockito.doReturn(propertiesMock).when(PropertiesUtil.class, "loadFromFile", Mockito.any());
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.findConfigFile(Mockito.anyString())).thenReturn(fileMock);
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.loadFromFile(Mockito.any())).thenReturn(propertiesMock);
|
||||
Mockito.doReturn(String.valueOf(expectedResult)).when(propertiesMock).getProperty(Mockito.anyString());
|
||||
|
||||
Integer result = AgentPropertiesFileHandler.getPropertyValue(agentPropertiesIntegerMock);
|
||||
@ -182,9 +187,8 @@ public class AgentPropertiesFileHandlerTest extends TestCase {
|
||||
Mockito.doReturn("name").when(agentPropertiesLongMock).getName();
|
||||
Mockito.doReturn(Long.class).when(agentPropertiesLongMock).getTypeClass();
|
||||
|
||||
PowerMockito.mockStatic(PropertiesUtil.class);
|
||||
PowerMockito.doReturn(fileMock).when(PropertiesUtil.class, "findConfigFile", Mockito.anyString());
|
||||
PowerMockito.doReturn(propertiesMock).when(PropertiesUtil.class, "loadFromFile", Mockito.any());
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.findConfigFile(Mockito.anyString())).thenReturn(fileMock);
|
||||
propertiesUtilMocked.when(() -> PropertiesUtil.loadFromFile(Mockito.any())).thenReturn(propertiesMock);
|
||||
Mockito.doReturn(String.valueOf(expectedResult)).when(propertiesMock).getProperty(Mockito.anyString());
|
||||
|
||||
Long result = AgentPropertiesFileHandler.getPropertyValue(agentPropertiesLongMock);
|
||||
|
||||
@ -0,0 +1 @@
|
||||
mock-maker-inline
|
||||
Loading…
x
Reference in New Issue
Block a user