use of org.powermock.core.classloader.annotations.PrepareForTest in project cloudstack by apache.
the class NetworkACLServiceImplTest method updateNetworkACLTestParametersWithNullValues.
@Test
@PrepareForTest(CallContext.class)
public void updateNetworkACLTestParametersWithNullValues() {
Mockito.when(updateNetworkACLListCmdMock.getName()).thenReturn(null);
Mockito.when(updateNetworkACLListCmdMock.getDescription()).thenReturn(null);
Mockito.when(updateNetworkACLListCmdMock.getCustomId()).thenReturn(null);
Mockito.when(updateNetworkACLListCmdMock.getId()).thenReturn(networkAclListId);
Mockito.when(updateNetworkACLListCmdMock.getDisplay()).thenReturn(null);
networkAclServiceImpl.updateNetworkACL(updateNetworkACLListCmdMock);
InOrder inOrder = Mockito.inOrder(networkAclDaoMock, entityManagerMock, accountManagerMock, networkACLVOMock);
inOrder.verify(networkAclDaoMock).findById(networkAclListId);
inOrder.verify(entityManagerMock).findById(eq(Vpc.class), Mockito.anyLong());
inOrder.verify(accountManagerMock).checkAccess(any(Account.class), isNull(), eq(true), nullable(Vpc.class));
Mockito.verify(networkACLVOMock, Mockito.times(0)).setName(null);
inOrder.verify(networkACLVOMock, Mockito.times(0)).setDescription(null);
inOrder.verify(networkACLVOMock, Mockito.times(0)).setUuid(null);
inOrder.verify(networkACLVOMock, Mockito.times(0)).setDisplay(false);
inOrder.verify(networkAclDaoMock).update(networkAclListId, networkACLVOMock);
inOrder.verify(networkAclDaoMock).findById(networkAclListId);
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project cloudstack by apache.
the class NfsSecondaryStorageResourceTest method testSwiftWriteMetadataFile.
@Test
@PrepareForTest(NfsSecondaryStorageResource.class)
public void testSwiftWriteMetadataFile() throws Exception {
String filename = "testfile";
try {
String expected = "uniquename=test\nfilename=" + filename + "\nsize=100\nvirtualsize=1000";
StringWriter stringWriter = new StringWriter();
BufferedWriter bufferWriter = new BufferedWriter(stringWriter);
PowerMockito.whenNew(BufferedWriter.class).withArguments(any(FileWriter.class)).thenReturn(bufferWriter);
resource.swiftWriteMetadataFile(filename, "test", filename, 100, 1000);
Assert.assertEquals(expected, stringWriter.toString());
} finally {
File remnance = new File(filename);
remnance.delete();
}
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project cloudstack by apache.
the class UriUtilsParametrizedTest method validateUrl.
@Test
@PrepareForTest({ UriUtils.class })
public void validateUrl() throws Exception {
InetAddress inetAddressMock = Mockito.mock(InetAddress.class);
PowerMockito.mockStatic(InetAddress.class);
PowerMockito.when(InetAddress.getByName(Mockito.anyString())).thenReturn(inetAddressMock);
if (expectSuccess) {
UriUtils.validateUrl(format, url);
} else {
assertThrows(() -> UriUtils.validateUrl(format, url), IllegalArgumentException.class);
}
PowerMockito.verifyStatic(InetAddress.class);
InetAddress.getByName(Mockito.anyString());
Mockito.verify(inetAddressMock).isAnyLocalAddress();
Mockito.verify(inetAddressMock).isLinkLocalAddress();
Mockito.verify(inetAddressMock).isLoopbackAddress();
Mockito.verify(inetAddressMock).isMulticastAddress();
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project canal by alibaba.
the class UtilTest method parseDate2InputNotNullOutputNull.
// Test written by Diffblue Cover.
@PrepareForTest(StringUtils.class)
@Test
public void parseDate2InputNotNullOutputNull() throws Exception {
// Setup mocks
PowerMockito.mockStatic(StringUtils.class);
// Arrange
final String datetimeStr = "1a 2b 3c";
final Method isEmptyMethod = DTUMemberMatcher.method(StringUtils.class, "isEmpty", String.class);
PowerMockito.doReturn(true).when(StringUtils.class, isEmptyMethod).withArguments(or(isA(String.class), isNull(String.class)));
// Act
final Date actual = Util.parseDate2(datetimeStr);
// Assert result
Assert.assertNull(actual);
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project alluxio by Alluxio.
the class OSSOutputStreamTest method testConstructor.
/**
* Tests to ensure IOException is thrown if {@link FileOutputStream}() throws an IOException.
*/
@Test
@PrepareForTest(OSSOutputStream.class)
public void testConstructor() throws Exception {
PowerMockito.whenNew(File.class).withArguments(Mockito.anyString()).thenReturn(mFile);
String errorMessage = "protocol doesn't support output";
PowerMockito.whenNew(FileOutputStream.class).withArguments(mFile).thenThrow(new IOException(errorMessage));
mThrown.expect(IOException.class);
mThrown.expectMessage(errorMessage);
new OSSOutputStream("testBucketName", "testKey", mOssClient, sConf.getList(PropertyKey.TMP_DIRS, ",")).close();
}
Aggregations