本文整理汇总了Java中org.powermock.reflect.internal.WhiteboxImpl.invokeMethod方法的典型用法代码示例。如果您正苦于以下问题:Java WhiteboxImpl.invokeMethod方法的具体用法?Java WhiteboxImpl.invokeMethod怎么用?Java WhiteboxImpl.invokeMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.powermock.reflect.internal.WhiteboxImpl
的用法示例。
在下文中一共展示了WhiteboxImpl.invokeMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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);
}
示例3: 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]));
}
示例4: 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());
}
示例5: 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());
}
示例6: 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());
}
示例7: getPattern
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
private Pattern getPattern(AssetType assetType) throws Exception {
return WhiteboxImpl.invokeMethod(filePickerProxy, "getPattern", assetType);
}
示例8: synchronizeStudentsFromCanvasToDb_UpdateExistingStudentInCourse
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
public void synchronizeStudentsFromCanvasToDb_UpdateExistingStudentInCourse() throws Exception {
Long previousCanvasSectionId = 350L;
Long previousCanvasCourseId = 350L;
String previousSisUserId = "uniqueSisId";
String previousName = "Doe, Jane";
AttendanceStudent expectedStudentInDb = new AttendanceStudent();
expectedStudentInDb.setCanvasCourseId(previousCanvasCourseId);
expectedStudentInDb.setCanvasSectionId(previousCanvasSectionId);
expectedStudentInDb.setSisUserId(previousSisUserId);
expectedStudentInDb.setName(previousName);
List<AttendanceStudent> studentsInDbForCourse = new ArrayList<>();
studentsInDbForCourse.add(expectedStudentInDb);
Long expectedCanvasSectionId = 250L;
Long expectedCanvasCourseId = 550L;
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);
when(mockStudentRepository.findByCanvasSectionIdOrderByNameAsc(expectedCanvasSectionId)).thenReturn(studentsInDbForCourse);
when(mockStudentRepository.save(any(AttendanceStudent.class))).thenReturn(expectedStudentInDb);
List<AttendanceStudent> actualStudents = WhiteboxImpl.invokeMethod(synchronizationService, SYNC_STUDENTS_TO_DB, canvasSectionMap, anyBoolean());
verify(mockStudentRepository, atLeastOnce()).save(expectedStudentInDb);
assertThat(actualStudents.size(), is(equalTo(expectedStudentsSavedToDb)));
assertSame(expectedStudentInDb, actualStudents.get(0));
assertEquals(expectedCanvasSectionId, expectedStudentInDb.getCanvasSectionId());
assertEquals(expectedCanvasCourseId, expectedStudentInDb.getCanvasCourseId());
assertEquals(expectedSisUserId, expectedStudentInDb.getSisUserId());
assertEquals(expectedName, expectedStudentInDb.getName());
assertEquals(expectedDeleted, expectedStudentInDb.getDeleted());
}
示例9: getEnrollmentsFromCanvas_HappyPath
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void getEnrollmentsFromCanvas_HappyPath() throws Exception {
Section firstSection = new Section();
Long firstSectiondId = 1L;
firstSection.setId(firstSectiondId);
Section secondSection = new Section();
int secondSectionId = 2;
secondSection.setId(2L);
List<Section> sections = new ArrayList<>();
sections.add(firstSection);
sections.add(secondSection);
Enrollment firstEnrollmentOfFirstSection = new Enrollment();
firstEnrollmentOfFirstSection.setId(10L);
Enrollment secondEnrollmentOfFirstSection = new Enrollment();
secondEnrollmentOfFirstSection.setId(20L);
Enrollment firstEnrollmentOfSecondSection = new Enrollment();
firstEnrollmentOfSecondSection.setId(30L);
List<Enrollment> firstSectionEnrollments = new ArrayList<>();
firstSectionEnrollments.add(firstEnrollmentOfFirstSection);
firstSectionEnrollments.add(secondEnrollmentOfFirstSection);
List<Enrollment> secondSectionEnrollments = new ArrayList<>();
secondSectionEnrollments.add(firstEnrollmentOfSecondSection);
EnrollmentReader mockEnrollmentReader = mock(EnrollmentReader.class);
OauthToken mockOAuthToken = mock(OauthToken.class);
int expectedMapSize = 2;
GetEnrollmentOptions enrollmentOptions1 = new GetEnrollmentOptions(Long.toString(firstSectiondId));
enrollmentOptions1.type(Collections.singletonList(GetEnrollmentOptions.EnrollmentType.STUDENT));
GetEnrollmentOptions enrollmentOptions2 = new GetEnrollmentOptions(Long.toString(secondSectionId));
enrollmentOptions2.type(Collections.singletonList(GetEnrollmentOptions.EnrollmentType.STUDENT));
when(mockLtiSession.getOauthToken()).thenReturn(mockOAuthToken);
when(mockCanvasApiFactory.getReader(eq(EnrollmentReader.class), any(OauthToken.class))).thenReturn(mockEnrollmentReader);
when(enrollmentOptionsFactory.buildEnrollmentOptions(eq(firstSection))).thenReturn(enrollmentOptions1);
when(enrollmentOptionsFactory.buildEnrollmentOptions(eq(secondSection))).thenReturn(enrollmentOptions2);
when(mockEnrollmentReader.getSectionEnrollments(enrollmentOptions1)).thenReturn(firstSectionEnrollments);
when(mockEnrollmentReader.getSectionEnrollments(enrollmentOptions2)).thenReturn(secondSectionEnrollments);
Map<Section, List<Enrollment>> actualMap = WhiteboxImpl.invokeMethod(canvasService, "getEnrollmentsFromCanvas", sections, mockLtiSession.getOauthToken());
assertEquals(expectedMapSize, actualMap.keySet().size());
assertThat(actualMap.keySet(), containsInAnyOrder(firstSection, secondSection));
assertThat(actualMap.get(firstSection), containsInAnyOrder(firstEnrollmentOfFirstSection, secondEnrollmentOfFirstSection));
assertThat(actualMap.get(secondSection), containsInAnyOrder(firstEnrollmentOfSecondSection));
}
示例10: invokeMethod
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
/**
* Invoke a private or inner class method. This might be useful to test
* private methods.
*/
public static synchronized <T> T invokeMethod(Object instance, String methodToExecute, Object... arguments)
throws Exception {
return WhiteboxImpl.<T> invokeMethod(instance, methodToExecute, arguments);
}
示例11: testManageBarrierResultsChildShouldBeKO
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
public void testManageBarrierResultsChildShouldBeKO() throws Exception {
String barrierPath = "/stratio/decision/barrier";
ActionCallbackDto parsedResponse = new ActionCallbackDto();
parsedResponse.setDescription(ReplyCode.KO_GENERAL_ERROR.getMessage());
parsedResponse.setErrorCode(ReplyCode.KO_GENERAL_ERROR.getCode());
byte[] data = new Gson().toJson(parsedResponse).getBytes();
when(curatorFramework.getData().forPath(anyString())).thenReturn(data);
final ClusterSyncManager spyClusterSyncManager = PowerMockito.spy(new ClusterSyncManager(STREAMING
.ZK_CLUSTER_MANAGER_PATH, "id", configurationContext, failOverTask, curatorFramework, zkUtils,
clusterBarrierManager));
ActionCallbackDto reply = WhiteboxImpl.invokeMethod(spyClusterSyncManager, "manageBarrierResults", message,
nodeReply, barrierPath, true);
Assert.assertEquals(ReplyCode.KO_GENERAL_ERROR.getCode(), reply.getErrorCode());
}
示例12: testManageBarrierResultsChildShouldBeOK
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
public void testManageBarrierResultsChildShouldBeOK() throws Exception {
String barrierPath = "/stratio/decision/barrier";
ActionCallbackDto parsedResponse = new ActionCallbackDto();
parsedResponse.setDescription(ReplyCode.OK.getMessage());
parsedResponse.setErrorCode(ReplyCode.OK.getCode());
byte[] data = new Gson().toJson(parsedResponse).getBytes();
when(curatorFramework.getData().forPath(anyString())).thenReturn(data);
final ClusterSyncManager spyClusterSyncManager = PowerMockito.spy(new ClusterSyncManager(STREAMING
.ZK_CLUSTER_MANAGER_PATH, "id", configurationContext, failOverTask, curatorFramework, zkUtils,
clusterBarrierManager));
ActionCallbackDto reply = WhiteboxImpl.invokeMethod(spyClusterSyncManager, "manageBarrierResults", message,
nodeReply, barrierPath, true);
Assert.assertEquals(ReplyCode.OK.getCode(), reply.getErrorCode());
}
示例13: testManageBarrierResultsShouldBeNodeNotReply
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
public void testManageBarrierResultsShouldBeNodeNotReply() throws Exception {
String barrierPath = "/stratio/decision/barrier";
ActionCallbackDto reply = WhiteboxImpl.invokeMethod(clusterSyncManager, "manageBarrierResults", message,
nodeReply, barrierPath, false);
Assert.assertEquals(ReplyCode.KO_NODE_NOT_REPLY.getCode(), reply.getErrorCode());
}
示例14: testManageBarrierResultsShouldBeKO
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
public void testManageBarrierResultsShouldBeKO() throws Exception {
String barrierPath = "/stratio/decision/barrier";
when(nodeReply.getErrorCode()).thenReturn(ReplyCode.KO_GENERAL_ERROR.getCode());
when(nodeReply.getDescription()).thenReturn(ReplyCode.KO_GENERAL_ERROR.getMessage());
ActionCallbackDto reply = WhiteboxImpl.invokeMethod(clusterSyncManager, "manageBarrierResults", message,
nodeReply, barrierPath, true);
Assert.assertEquals(ReplyCode.KO_GENERAL_ERROR.getCode(), reply.getErrorCode()) ;
}
示例15: testManageBarrierResultsShouldBeOK
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
public void testManageBarrierResultsShouldBeOK() throws Exception {
String barrierPath = "/stratio/decision/barrier";
when(nodeReply.getErrorCode()).thenReturn(ReplyCode.KO_GENERAL_ERROR.getCode());
when(nodeReply.getDescription()).thenReturn(ReplyCode.KO_GENERAL_ERROR.getMessage());
ActionCallbackDto reply = WhiteboxImpl.invokeMethod(clusterSyncManager, "manageBarrierResults", message,
nodeReply, barrierPath, true);
Assert.assertEquals(ReplyCode.KO_GENERAL_ERROR.getCode(), reply.getErrorCode());
}