本文整理汇总了Java中org.powermock.reflect.internal.WhiteboxImpl类的典型用法代码示例。如果您正苦于以下问题:Java WhiteboxImpl类的具体用法?Java WhiteboxImpl怎么用?Java WhiteboxImpl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WhiteboxImpl类属于org.powermock.reflect.internal包,在下文中一共展示了WhiteboxImpl类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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"));
}
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:22,代码来源:JCloudsCloudHostProviderTest.java
示例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));
}
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:27,代码来源:JCloudsCloudHostProviderTest.java
示例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());
}
开发者ID:kstateome,项目名称:lti-attendance,代码行数:26,代码来源:SynchronizationServiceUTest.java
示例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);
}
开发者ID:awenblue,项目名称:powermock,代码行数:19,代码来源:DefaultConstructorExpectationSetup.java
示例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;
}
开发者ID:awenblue,项目名称:powermock,代码行数:22,代码来源:MockitoNewInvocationControl.java
示例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));
}
}
开发者ID:awenblue,项目名称:powermock,代码行数:17,代码来源:MethodReplaceStrategyImpl.java
示例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);
}
}
开发者ID:awenblue,项目名称:powermock,代码行数:20,代码来源:EasyMockMethodInvocationControl.java
示例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);
}
开发者ID:awenblue,项目名称:powermock,代码行数:26,代码来源:PowerMock.java
示例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"));
}
开发者ID:brdara,项目名称:ehcache-aws,代码行数:26,代码来源:AwsSecurityGroupAwareCacheManagerPeerProviderTest.java
示例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]));
}
开发者ID:yizhiru,项目名称:thulac4j,代码行数:28,代码来源:BaseSegmenterTest.java
示例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());
}
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:31,代码来源:CloudFileSystemTest.java
示例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);
}
开发者ID:kstateome,项目名称:lti-attendance,代码行数:16,代码来源:SynchronizationServiceUTest.java
示例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());
}
开发者ID:kstateome,项目名称:lti-attendance,代码行数:32,代码来源:SynchronizationServiceUTest.java
示例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());
}
开发者ID:kstateome,项目名称:lti-attendance,代码行数:37,代码来源:SynchronizationServiceUTest.java
示例16: synchronizeStudentsFromCanvasToDb_DroppedStudent
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
@Test
public void synchronizeStudentsFromCanvasToDb_DroppedStudent() throws Exception {
Long expectedCanvasSectionId = 200L;
Long expectedCanvasCourseId = 500L;
Section section = new Section();
section.setId(expectedCanvasSectionId);
section.setCourseId(expectedCanvasCourseId.intValue());
Map<Section, List<Enrollment>> canvasSectionMap = new HashMap<>();
canvasSectionMap.put(section, Collections.emptyList());
ArgumentCaptor<AttendanceStudent> capturedStudent = ArgumentCaptor.forClass(AttendanceStudent.class);
AttendanceStudent expectedStudentSavedToDb = new AttendanceStudent();
when(mockStudentRepository.save(any(AttendanceStudent.class))).thenReturn(expectedStudentSavedToDb);
when(mockStudentRepository.findByCanvasSectionIdOrderByNameAsc(anyLong())).thenReturn(Collections.singletonList(expectedStudentSavedToDb));
AttendanceStudent droppedStudent = new AttendanceStudent();
droppedStudent.setDeleted(true);
when(mockStudentRepository.save(
argThat(
Matchers.both(
Matchers.isA(AttendanceStudent.class)).
and(Matchers.hasProperty("deleted", Matchers.hasValue(true))))))
.thenReturn(droppedStudent);
List<AttendanceStudent> secondSetOfStudents = WhiteboxImpl.invokeMethod(synchronizationService, SYNC_STUDENTS_TO_DB, canvasSectionMap, anyBoolean());
verify(mockStudentRepository, atLeastOnce()).save(capturedStudent.capture());
assertEquals(droppedStudent, secondSetOfStudents.get(0));
assertTrue("Dropped student should be marked as deleted", secondSetOfStudents.get(0).getDeleted());
}
开发者ID:kstateome,项目名称:lti-attendance,代码行数:29,代码来源:SynchronizationServiceUTest.java
示例17: testOnRequestParseErr
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
/**
* Test method for
* {@link org.o3project.ocnrm.odenos.linklayerizer.LinkLayerizer#onRequest()}
*/
@Test
public final void testOnRequestParseErr() {
Method method = Request.Method.GET;
Object body = new Object();
Request request = new Request("LinkLayerizer", method, "settings/default_idle_timer", body);
Response result = target.onRequest(request);
assertThat(result.statusCode, is(Response.BAD_REQUEST));
assertThat((String) WhiteboxImpl.getInternalState(result, "body"),
is("Error unknown request "));
}
开发者ID:o3project,项目名称:ocnrm,代码行数:18,代码来源:LinkLayerizerTest.java
示例18: createNewSubstituteMock
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private static <T> OngoingStubbing<T> createNewSubstituteMock(Class<T> type, Class<?>[] parameterTypes, Object... arguments) throws Exception {
if (type == null) {
throw new IllegalArgumentException("type cannot be null");
}
final Class<T> unmockedType = (Class<T>) WhiteboxImpl.getUnmockedType(type);
if (parameterTypes == null) {
WhiteboxImpl.findUniqueConstructorOrThrowException(type, arguments);
} else {
WhiteboxImpl.getConstructor(unmockedType, parameterTypes);
}
/*
* Check if this type has been mocked before
*/
NewInvocationControl<OngoingStubbing<T>> newInvocationControl = (NewInvocationControl<OngoingStubbing<T>>) MockRepository
.getNewInstanceControl(unmockedType);
if (newInvocationControl == null) {
InvocationSubstitute<T> mock = MockCreator.mock(InvocationSubstitute.class, false, false, null, null, (Method[]) null);
newInvocationControl = new MockitoNewInvocationControl(mock);
MockRepository.putNewInstanceControl(type, newInvocationControl);
MockRepository.addObjectsToAutomaticallyReplayAndVerify(WhiteboxImpl.getUnmockedType(type));
}
return newInvocationControl.expectSubstitutionLogic(arguments);
}
开发者ID:awenblue,项目名称:powermock,代码行数:28,代码来源:DefaultConstructorExpectationSetup.java
示例19: invoke
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
public Object invoke(final Object obj, final Method method, final Object[] arguments) throws Throwable {
/*
* If we come here and it means that the class has been modified by
* PowerMock. If this handler has a delegator (i.e. is in spy mode in
* the current implementation) and it has been caught by the Mockito
* proxy before our Mockgateway we need to know if the method is private
* or not. Because if the previously described preconditions are met and
* the method is not private it means that Mockito has already processed
* the method invocation and we should NOT delegate the call to Mockito
* again (thus we return proceed). If we would do that Mockito will
* receive multiple method invocations to proxy for each method
* invocation. For privately spied methods Mockito haven't received the
* invocation and thus we should delegate the call to the Mockito proxy.
*/
final Object returnValue;
final int methodModifiers = method.getModifiers();
if (hasDelegator() && !Modifier.isPrivate(methodModifiers) && !Modifier.isFinal(methodModifiers)
&& !Modifier.isStatic(methodModifiers) && hasBeenCaughtByMockitoProxy()) {
returnValue = MockGateway.PROCEED;
} else {
boolean inVerificationMode = isInVerificationMode();
if (WhiteboxImpl.isClass(obj) && inVerificationMode) {
handleStaticVerification((Class<?>) obj);
}
returnValue = performIntercept(methodInterceptorFilter, obj, method, arguments);
if (returnValue == null) {
return MockGateway.SUPPRESS;
}
}
return returnValue;
}
开发者ID:awenblue,项目名称:powermock,代码行数:32,代码来源:MockitoMethodInvocationControl.java
示例20: methodsDeclaredIn
import org.powermock.reflect.internal.WhiteboxImpl; //导入依赖的package包/类
/**
* Get all methods in a class hierarchy of the supplied classes. Both
* declared an non-declared (no duplicates).
*
* @param cls
* The class whose methods to get.
* @param additionalClasses
* Additional classes whose methods to get.
* @return All methods declared in this class hierarchy.
*/
public static Method[] methodsDeclaredIn(final Class<?> cls, final Class<?>... additionalClasses) {
if (cls == null) {
throw new IllegalArgumentException("You need to supply at least one class.");
}
Set<Method> methods = new HashSet<Method>();
methods.addAll(asList(WhiteboxImpl.getAllMethods(cls)));
for (Class<?> klass : additionalClasses) {
methods.addAll(asList(WhiteboxImpl.getAllMethods(klass)));
}
return methods.toArray(new Method[methods.size()]);
}
开发者ID:awenblue,项目名称:powermock,代码行数:22,代码来源:MemberMatcher.java
注:本文中的org.powermock.reflect.internal.WhiteboxImpl类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论