本文整理汇总了Java中org.powermock.reflect.internal.WhiteboxImpl类的典型用法代码示例。如果您正苦于以下问题:Java WhiteboxImpl类的具体用法?Java WhiteboxImpl怎么用?Java WhiteboxImpl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WhiteboxImpl类属于org.powermock.reflect.internal包,在下文中一共展示了WhiteboxImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateCloudFileSystemInternalWillCreateTheFileSystemIfItHasntBeenCreatedYet
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
@Test
public void testCreateCloudFileSystemInternalWillCreateTheFileSystemIfItHasntBeenCreatedYet() {
CloudHostConfiguration config = context.mock(CloudHostConfiguration.class);
FileSystemProvider provider = context.mock(FileSystemProvider.class);
BlobStoreContext blobStoreContext = context.mock(BlobStoreContext.class);
context.checking(new Expectations() {{
allowing(config).getName();
will(returnValue("test-config"));
exactly(1).of(config).createBlobStoreContext();
will(returnValue(blobStoreContext));
}});
Assert.assertTrue(((Map<?,?>)WhiteboxImpl.getInternalState(impl, "cloudFileSystems")).isEmpty());
impl.createCloudFilesystemInternal(provider, config);
Map<String,CloudFileSystem> cloudFileSystemsMap =
((Map<String,CloudFileSystem>)WhiteboxImpl.getInternalState(impl, "cloudFileSystems"));
Assert.assertTrue(cloudFileSystemsMap.containsKey("test-config"));
Assert.assertNotNull(cloudFileSystemsMap.get("test-config"));
}
示例2: testCreateCloudFileSystemWillUseTheCloudHostConfigurationBuilderToCreateACloudFileSystem
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
@Test
public void testCreateCloudFileSystemWillUseTheCloudHostConfigurationBuilderToCreateACloudFileSystem() throws URISyntaxException, IOException {
FileSystemProvider provider = context.mock(FileSystemProvider.class);
URI uri = new URI("cloud", "mock-fs", "/path", "fragment"); // The host holds the name
Map<String,Object> env = new HashMap<>();
env.put(JCloudsCloudHostProvider.CLOUD_TYPE_ENV, "mock-test");
// Test we can create the FS
Assert.assertTrue(((Map<?,?>)WhiteboxImpl.getInternalState(impl, "cloudFileSystems")).isEmpty());
impl.createCloudFileSystem(provider, uri, env);
Map<String,CloudFileSystem> cloudFileSystemsMap =
((Map<String,CloudFileSystem>)WhiteboxImpl.getInternalState(impl, "cloudFileSystems"));
Assert.assertTrue(cloudFileSystemsMap.containsKey("mock-fs"));
Assert.assertNotNull(cloudFileSystemsMap.get("mock-fs"));
// Now get the FS back
CloudFileSystem cloudFileSystem = impl.getCloudFileSystem(uri);
Assert.assertNotNull(cloudFileSystem);
Assert.assertEquals(provider, cloudFileSystem.provider());
Assert.assertEquals(MockCloudHostConfiguration.class, cloudFileSystem.getCloudHostConfiguration().getClass());
Assert.assertEquals("mock-fs", cloudFileSystem.getCloudHostConfiguration().getName());
// Close it and make sure we don't get it back
cloudFileSystem.close();
Assert.assertNull(impl.getCloudFileSystem(uri));
}
示例3: synchronizeSectionsFromCanvasToDb_SectionDoesntExistInDB
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
@Test
public void synchronizeSectionsFromCanvasToDb_SectionDoesntExistInDB() throws Exception {
String expectedSectionName = "CIS 200 B";
Long expectedCanvasSectionId = 17000L;
Long expectedCanvasCourseId = 550L;
int expectedListSize = 1;
List<Section> sections = new ArrayList<>();
Section section = new Section();
section.setName(expectedSectionName);
section.setId(expectedCanvasSectionId);
section.setCourseId(expectedCanvasCourseId.intValue());
sections.add(section);
AttendanceSection expectedDbSection = new AttendanceSection();
ArgumentCaptor<AttendanceSection> capturedSection = ArgumentCaptor.forClass(AttendanceSection.class);
when(mockSectionRepository.save(any(AttendanceSection.class))).thenReturn(expectedDbSection);
List<AttendanceSection> actualSections = WhiteboxImpl.invokeMethod(synchronizationService, SYNC_SECTIONS_TO_DB, sections);
verify(mockSectionRepository, atLeastOnce()).save(capturedSection.capture());
assertThat(actualSections.size(), is(equalTo(expectedListSize)));
assertSame(expectedDbSection, actualSections.get(0));
assertEquals(expectedSectionName, capturedSection.getValue().getName());
assertEquals(expectedCanvasSectionId, capturedSection.getValue().getCanvasSectionId());
assertEquals(expectedCanvasCourseId, capturedSection.getValue().getCanvasCourseId());
}
示例4: withAnyArguments
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
public OngoingStubbing<T> withAnyArguments() throws Exception {
if (mockType == null) {
throw new IllegalArgumentException("Class to expected cannot be null");
}
final Class<T> unmockedType = (Class<T>) WhiteboxImpl.getUnmockedType(mockType);
final Constructor<?>[] allConstructors = WhiteboxImpl.getAllConstructors(unmockedType);
final Constructor<?> constructor = allConstructors[0];
final Class<?>[] parameterTypes = constructor.getParameterTypes();
Object[] paramArgs = new Object[parameterTypes.length];
for (int i = 0; i < parameterTypes.length; i++) {
Class<?> paramType = parameterTypes[i];
paramArgs[i] = Matchers.any(paramType);
}
final OngoingStubbing<T> ongoingStubbing = createNewSubstituteMock(mockType, parameterTypes, paramArgs);
Constructor<?>[] otherCtors = new Constructor<?>[allConstructors.length-1];
System.arraycopy(allConstructors, 1, otherCtors, 0, allConstructors.length-1);
return new DelegatingToConstructorsOngoingStubbing<T>(otherCtors, ongoingStubbing);
}
示例5: invoke
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
public Object invoke(Class<?> type, Object[] args, Class<?>[] sig) throws Exception {
Constructor<?> constructor = WhiteboxImpl.getConstructor(type, sig);
if (constructor.isVarArgs()) {
Object varArgs = args[args.length - 1];
final int varArgsLength = Array.getLength(varArgs);
Object[] oldArgs = args;
args = new Object[args.length + varArgsLength - 1];
System.arraycopy(oldArgs, 0, args, 0, oldArgs.length - 1);
for (int i = oldArgs.length - 1, j=0; i < args.length; i++, j++) {
args[i] = Array.get(varArgs, j);
}
}
try {
return substitute.performSubstitutionLogic(args);
} catch (MockitoAssertionError e) {
InvocationControlAssertionError.throwAssertionErrorForNewSubstitutionFailure(e, type);
}
// Won't happen
return null;
}
示例6: with
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
public void with(Method method) {
if (method == null) {
throw new IllegalArgumentException("A metod cannot be replaced with null.");
}
if (!Modifier.isStatic(this.method.getModifiers())) {
throw new IllegalArgumentException(String.format("Replace requires static methods, '%s' is not static", this.method));
} else if (!Modifier.isStatic(method.getModifiers())) {
throw new IllegalArgumentException(String.format("Replace requires static methods, '%s' is not static", method));
} else if(!this.method.getReturnType().isAssignableFrom(method.getReturnType())) {
throw new IllegalArgumentException(String.format("The replacing method (%s) needs to return %s and not %s.",method.toString(), this.method.getReturnType().getName(), method.getReturnType().getName()));
} else if(!WhiteboxImpl.checkIfParameterTypesAreSame(this.method.isVarArgs(),this.method.getParameterTypes(), method.getParameterTypes())) {
throw new IllegalArgumentException(String.format("The replacing method, \"%s\", needs to have the same number of parameters of the same type as as method \"%s\".",method.toString(),this.method.toString()));
} else {
MethodProxy.proxy(this.method, new MethodInvocationHandler(method));
}
}
示例7: getMockType
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
public MocksControl.MockType getMockType() {
final MocksControl control = invocationHandler.getControl();
if (WhiteboxImpl.getFieldsOfType(control, MocksControl.MockType.class).isEmpty()) {
// EasyMock is of version 3.2+
final MockType mockType = WhiteboxImpl.getInternalState(control, MockType.class);
switch (mockType) {
case DEFAULT:
return MocksControl.MockType.DEFAULT;
case NICE:
return MocksControl.MockType.NICE;
case STRICT:
return MocksControl.MockType.STRICT;
default:
throw new IllegalStateException("PowerMock doesn't seem to work with the used EasyMock version. Please report to the PowerMock mailing list");
}
} else {
return WhiteboxImpl.getInternalState(control, MocksControl.MockType.class);
}
}
示例8: expectPrivate
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
/**
* Used to specify expectations on private methods. Use this method to
* handle overloaded methods.
*/
@SuppressWarnings("all")
public static synchronized <T> IExpectationSetters<T> expectPrivate(Object instance, String methodName,
Class<?>[] parameterTypes, Object... arguments) throws Exception {
if (arguments == null) {
arguments = new Object[0];
}
if (instance == null) {
throw new IllegalArgumentException("instance cannot be null.");
} else if (arguments.length != parameterTypes.length) {
throw new IllegalArgumentException(
"The length of the arguments must be equal to the number of parameter types.");
}
Method foundMethod = Whitebox.getMethod(instance.getClass(), methodName, parameterTypes);
WhiteboxImpl.throwExceptionIfMethodWasNotFound(instance.getClass(), methodName, foundMethod, parameterTypes);
return doExpectPrivate(instance, foundMethod, arguments);
}
示例9: testSetCachePeerHostsSetsANewListOfHosts
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
@Test
public void testSetCachePeerHostsSetsANewListOfHosts() {
invokeInitAndCheckDiscoveryServiceHasBeenStarted();
context.checking(new Expectations() {{
allowing(discoveryServiceConfig).getRmiListenerPort(); will(returnValue(61616));
}});
// Make sure that the initial list is empty
Assert.assertTrue(((Set<String>)WhiteboxImpl.getInternalState(peerProvider, PEER_URLS_SET_VARIABLE_NAME)).isEmpty());
// Set up a list of hosts. Because these hosts are actually resolved they need to be real.
Set<CachePeerHost> cachePeerHosts = new HashSet<>();
cachePeerHosts.add(new CachePeerHost("www.google.com", 61616));
cachePeerHosts.add(new CachePeerHost("www.yahoo.com", 61618));
// Set the hosts
peerProvider.setCachePeerHosts(cachePeerHosts);
// Check that RMI URL's should be formed from the values
Set<String> peerUrls = (Set<String>)WhiteboxImpl.getInternalState(peerProvider, PEER_URLS_SET_VARIABLE_NAME);
Assert.assertEquals(2, peerUrls.size());
Assert.assertTrue(peerUrls.contains("//www.google.com:61616"));
Assert.assertTrue(peerUrls.contains("//www.yahoo.com:61618"));
}
示例10: setPreviousTrans
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
@Test
public void setPreviousTrans() throws Exception {
BaseSegmenter segmenter = new SegOnly(SEG_ONLY_WEIGHTS_PATH, SEG_ONLY_FEATURES_PATH);
int[][] previousTrans = WhiteboxImpl.invokeMethod(
segmenter,
"setPreviousTrans",
new Class<?>[]{String[].class},
(Object) segmenter.model.labelValues);
assertEquals("[[1, 2], [0, 3], [1, 2], [0, 3]]",
Arrays.deepToString(previousTrans));
segmenter = new SegPos(SEG_POS_WEIGHTS_PATH, SEG_POS_FEATURES_PATH);
previousTrans = WhiteboxImpl.invokeMethod(
segmenter,
"setPreviousTrans",
new Class<?>[]{String[].class},
(Object) segmenter.model.labelValues);
assertEquals("[1, 2, 4, 5, 7, 10, 13, 15, 17, 18, 19, 23, 25, 27, " +
"30, 32, 33, 34, 35, 36, 37, 38, 39, 41, 44, 45, 48, 50, 53, " +
"56, 57, 59, 61, 63, 67, 69, 72, 74, 76, 80, 81, 82, 83, 88, " +
"89, 90, 91, 95]",
Arrays.toString(previousTrans[0]));
assertEquals("[0, 20]", Arrays.toString(previousTrans[1]));
assertEquals("[54, 55]", Arrays.toString(previousTrans[56]));
assertEquals("[93, 94]", Arrays.toString(previousTrans[95]));
}
示例11: createAclEntrySetMock
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
protected CloudAclEntrySet createAclEntrySetMock(String name) {
CloudAclEntrySet aclEntrySet = context.mock(CloudAclEntrySet.class, name);
// The next part we have to do because of the aclEntrySet.equals method which uses this,
// so we have to set this value in the mock or we get an NPE
WhiteboxImpl.setInternalState(aclEntrySet, "ownersLock", new ReentrantReadWriteLock());
return aclEntrySet;
}
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:8,代码来源:DefaultCloudFileSystemImplementationTest.java
示例12: testNewWatchServiceWillTrackTheServiceAndCloseWillCloseAllWatchers
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
@Test
public void testNewWatchServiceWillTrackTheServiceAndCloseWillCloseAllWatchers() throws IOException {
CloudWatchService service = context.mock(CloudWatchService.class, "service1");
CloudWatchService service2 = context.mock(CloudWatchService.class, "service2");
Sequence sequence = context.sequence("watch-service-sequence");
context.checking(new Expectations() {{
allowing(cloudHostSettings).getName();
will(returnValue("unit-test"));
exactly(1).of(cloudHostSettings).createWatchService();
will(returnValue(service));
inSequence(sequence);
exactly(1).of(cloudHostSettings).createWatchService();
will(returnValue(service2));
inSequence(sequence);
exactly(1).of(blobStoreContext).close();
exactly(1).of(service).close();
exactly(1).of(service2).close();
}});
Assert.assertEquals(service, impl.newWatchService());
Assert.assertEquals(service2, impl.newWatchService());
Assert.assertEquals(2, ((Collection<?>)WhiteboxImpl.getInternalState(impl, "cloudWatchServices")).size());
impl.close();
Assert.assertEquals(0, ((Collection<?>)WhiteboxImpl.getInternalState(impl, "cloudWatchServices")).size());
}
示例13: synchronizeCourseFromCanvasToDb_NoExistingCourse
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
@Test
public void synchronizeCourseFromCanvasToDb_NoExistingCourse() throws Exception {
Long expectedCanvasCourseId = 500L;
ArgumentCaptor<AttendanceCourse> capturedCourse = ArgumentCaptor.forClass(AttendanceCourse.class);
AttendanceCourse expectedDbCourse = new AttendanceCourse();
when(mockCourseRepository.save(any(AttendanceCourse.class))).thenReturn(expectedDbCourse);
AttendanceCourse actualCourse = WhiteboxImpl.invokeMethod(synchronizationService, SYNC_COURSE_TO_DB, expectedCanvasCourseId);
verify(mockCourseRepository, atLeastOnce()).save(capturedCourse.capture());
assertEquals(expectedCanvasCourseId, capturedCourse.getValue().getCanvasCourseId());
assertEquals(Integer.valueOf(SynchronizationService.DEFAULT_MINUTES_PER_CLASS), capturedCourse.getValue().getDefaultMinutesPerSession());
assertEquals(Integer.valueOf(SynchronizationService.DEFAULT_TOTAL_CLASS_MINUTES), capturedCourse.getValue().getTotalMinutes());
assertEquals(expectedDbCourse, actualCourse);
}
示例14: synchronizeSectionsFromCanvasToDb_SectionExistsInDB
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
@Test
public void synchronizeSectionsFromCanvasToDb_SectionExistsInDB() throws Exception {
String previousSectionName = "CIS 200 B";
Long previousCanvasSectionId = 17000L;
Long previousCanvasCourseId = 550L;
String expectedSectionName = "CIS 400 B";
Long expectedCanvasSectionId = 18000L;
Long expectedCanvasCourseId = 560L;
int expectedListSize = 1;
List<Section> sections = new ArrayList<>();
Section section = new Section();
section.setName(expectedSectionName);
section.setId(expectedCanvasSectionId);
section.setCourseId(expectedCanvasCourseId.intValue());
sections.add(section);
AttendanceSection expectedDbSection = new AttendanceSection();
expectedDbSection.setName(previousSectionName);
expectedDbSection.setCanvasSectionId(previousCanvasSectionId);
expectedDbSection.setCanvasCourseId(previousCanvasCourseId);
when(mockSectionRepository.findByCanvasSectionId(expectedCanvasSectionId)).thenReturn(expectedDbSection);
when(mockSectionRepository.save(any(AttendanceSection.class))).thenReturn(expectedDbSection);
List<AttendanceSection> actualSections = WhiteboxImpl.invokeMethod(synchronizationService, SYNC_SECTIONS_TO_DB, sections);
verify(mockSectionRepository, atLeastOnce()).save(expectedDbSection);
assertThat(actualSections.size(), is(equalTo(expectedListSize)));
assertSame(expectedDbSection, actualSections.get(0));
assertEquals(expectedSectionName, expectedDbSection.getName());
assertEquals(expectedCanvasSectionId, expectedDbSection.getCanvasSectionId());
assertEquals(expectedCanvasCourseId, expectedDbSection.getCanvasCourseId());
}
示例15: synchronizeStudentsFromCanvasToDb_NewStudent
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
@Test
public void synchronizeStudentsFromCanvasToDb_NewStudent() throws Exception {
Long expectedCanvasSectionId = 200L;
Long expectedCanvasCourseId = 500L;
String expectedSisUserId = "uniqueSisId";
String expectedName = "Smith, John";
Integer expectedStudentsSavedToDb = 1;
Boolean expectedDeleted = Boolean.FALSE;
User user = new User();
user.setSisUserId(expectedSisUserId);
user.setSortableName(expectedName);
Enrollment enrollment = new Enrollment();
enrollment.setUser(user);
List<Enrollment> enrollments = new ArrayList<>();
enrollments.add(enrollment);
Section section = new Section();
section.setId(expectedCanvasSectionId);
section.setCourseId(expectedCanvasCourseId.intValue());
Map<Section, List<Enrollment>> canvasSectionMap = new HashMap<>();
canvasSectionMap.put(section, enrollments);
ArgumentCaptor<AttendanceStudent> capturedStudent = ArgumentCaptor.forClass(AttendanceStudent.class);
AttendanceStudent expectedStudentSavedToDb = new AttendanceStudent();
when(mockStudentRepository.save(any(AttendanceStudent.class))).thenReturn(expectedStudentSavedToDb);
List<AttendanceStudent> actualStudents = WhiteboxImpl.invokeMethod(synchronizationService, SYNC_STUDENTS_TO_DB, canvasSectionMap, anyBoolean());
verify(mockStudentRepository, atLeastOnce()).save(capturedStudent.capture());
assertThat(actualStudents.size(), is(equalTo(expectedStudentsSavedToDb)));
assertSame(expectedStudentSavedToDb, actualStudents.get(0));
assertEquals(expectedCanvasSectionId, capturedStudent.getValue().getCanvasSectionId());
assertEquals(expectedCanvasCourseId, capturedStudent.getValue().getCanvasCourseId());
assertEquals(expectedSisUserId, capturedStudent.getValue().getSisUserId());
assertEquals(expectedName, capturedStudent.getValue().getName());
assertEquals(expectedDeleted, capturedStudent.getValue().getDeleted());
}