本文整理汇总了Java中org.mockito.exceptions.base.MockitoException类的典型用法代码示例。如果您正苦于以下问题:Java MockitoException类的具体用法?Java MockitoException怎么用?Java MockitoException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MockitoException类属于org.mockito.exceptions.base包,在下文中一共展示了MockitoException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fullEmptyGroups
import org.mockito.exceptions.base.MockitoException; //导入依赖的package包/类
@Test
public void fullEmptyGroups() throws IOException, InterruptedException {
final BatchTaskVo<UserImportEntry> importTask = full("Loubli;Sébastien;kloubli9;[email protected];gfi;,jira,");
// Check the result
final UserImportEntry importEntry = checkImportTask(importTask);
Assert.assertEquals("kloubli9", importEntry.getId());
Assert.assertTrue(importEntry.getStatus());
Assert.assertNull(importEntry.getStatusText());
// Check LDAP
Mockito.verify(mockLdapResource, new DefaultVerificationMode(data -> {
if (data.getAllInvocations().size() != 1) {
throw new MockitoException("Expect one call");
}
final UserOrgEditionVo userLdap = (UserOrgEditionVo) data.getAllInvocations().get(0).getArguments()[0];
Assert.assertNotNull(userLdap);
Assert.assertEquals("kloubli9", userLdap.getId());
Assert.assertEquals(1, userLdap.getGroups().size());
Assert.assertEquals("jira", userLdap.getGroups().iterator().next());
})).create(null);
}
示例2: fullDefaultHeader
import org.mockito.exceptions.base.MockitoException; //导入依赖的package包/类
@Test
public void fullDefaultHeader() throws IOException, InterruptedException {
final InputStream input = new ByteArrayInputStream("Loubli;Sébastien;kloubli5;[email protected];gfi;jira".getBytes("cp1250"));
initSpringSecurityContext(DEFAULT_USER);
@SuppressWarnings("unchecked")
final BatchTaskVo<UserImportEntry> importTask = (BatchTaskVo<UserImportEntry>) waitImport(
resource.getImportTask(resource.full(input, new String[0], "cp1250")));
Assert.assertEquals(Boolean.TRUE, importTask.getEntries().get(0).getStatus());
Assert.assertNull(importTask.getEntries().get(0).getStatusText());
// Check LDAP
Mockito.verify(mockLdapResource, new DefaultVerificationMode(data -> {
if (data.getAllInvocations().size() != 1) {
throw new MockitoException("Expect one call");
}
final UserOrgEditionVo userLdap = (UserOrgEditionVo) data.getAllInvocations().get(0).getArguments()[0];
Assert.assertNotNull(userLdap);
Assert.assertNotNull(userLdap);
Assert.assertEquals("Sébastien", userLdap.getFirstName());
Assert.assertEquals("Loubli", userLdap.getLastName());
Assert.assertEquals("kloubli5", userLdap.getId());
Assert.assertEquals("gfi", userLdap.getCompany());
Assert.assertEquals("[email protected]", userLdap.getMail());
})).create(null);
}
示例3: checkAttribute
import org.mockito.exceptions.base.MockitoException; //导入依赖的package包/类
private void checkAttribute(final Function<UserOrgEditionVo, String> function, final String value) {
// Check LDAP
Mockito.verify(task.resource, new DefaultVerificationMode(data -> {
if (data.getAllInvocations().size() != 2) {
throw new MockitoException("Expect two calls");
}
// "findBy" call
Assert.assertEquals(DEFAULT_USER, data.getAllInvocations().get(0).getArguments()[0]);
// "update" call
final UserOrgEditionVo userLdap = (UserOrgEditionVo) data.getAllInvocations().get(1).getArguments()[0];
Assert.assertNotNull(userLdap);
Assert.assertEquals(value, function.apply(userLdap));
})).update(null);
}
示例4: imposterise
import org.mockito.exceptions.base.MockitoException; //导入依赖的package包/类
public <T> T imposterise(final MethodInterceptor interceptor, Class<T> mockedType, Class<?>... ancillaryTypes) {
Class<Factory> proxyClass = null;
Object proxyInstance = null;
try {
setConstructorsAccessible(mockedType, true);
proxyClass = createProxyClass(mockedType, ancillaryTypes);
proxyInstance = createProxy(proxyClass, interceptor);
return mockedType.cast(proxyInstance);
} catch (ClassCastException cce) {
throw new MockitoException(join(
"ClassCastException occurred while creating the mockito proxy :",
" class to mock : " + describeClass(mockedType),
" created class : " + describeClass(proxyClass),
" proxy instance class : " + describeClass(proxyInstance),
" instance creation by : " + instantiator.getClass().getSimpleName(),
"",
"You might experience classloading issues, disabling the Objenesis cache *might* help (see MockitoConfiguration)"
), cce);
} finally {
setConstructorsAccessible(mockedType, false);
}
}
示例5: createNewUserException
import org.mockito.exceptions.base.MockitoException; //导入依赖的package包/类
@Test(expected = MockitoException.class)
public void createNewUserException() {
//Throw an exception to test the try-catch surrounding the creation of a new user
when(database.create(any(User.class))).thenThrow(new NoSuchAlgorithmException());
Map newUserMap = new HashMap();
newUserMap.put("name", "John Doe");
newUserMap.put("email", "[email protected]");
newUserMap.put("username", loginInfo1[0]);
newUserMap.put("password", loginInfo1[1]);
User result = null;
try {
result = userService.create(newUserMap);
} catch (Exception ex) {
Logger.getLogger(UserServiceTest.class.getName()).log(Level.SEVERE, null, ex);
}
///Result is null when exception is thrown
Assert.assertNull(result);
}
示例6: verify
import org.mockito.exceptions.base.MockitoException; //导入依赖的package包/类
public void verify(VerificationData verificationData) {
List<Invocation> invocations = verificationData.getAllInvocations();
InvocationMatcher invocationMatcher = verificationData.getWanted();
if (invocations == null || invocations.isEmpty()) {
throw new MockitoException(
"\nNo interactions with "
+ invocationMatcher.getInvocation().getMock()
+ " mock so far");
}
Invocation invocation = invocations.get(invocations.size() - 1);
if (!invocationMatcher.matches(invocation)) {
throw new MockitoException("\nWanted but not invoked:\n" + invocationMatcher);
}
}
示例7: filterCandidate
import org.mockito.exceptions.base.MockitoException; //导入依赖的package包/类
public OngoingInjecter filterCandidate(final Collection<Object> mocks, final Field field, final Object fieldInstance) {
if(mocks.size() == 1) {
final Object matchingMock = mocks.iterator().next();
return new OngoingInjecter() {
public boolean thenInject() {
try {
if (!new BeanPropertySetter(fieldInstance, field).set(matchingMock)) {
new FieldSetter(fieldInstance, field).set(matchingMock);
}
} catch (Exception e) {
throw new MockitoException("Problems injecting dependency in " + field.getName(), e);
}
return true;
}
};
}
return new OngoingInjecter() {
public boolean thenInject() {
return false;
}
};
}
示例8: scanMocks
import org.mockito.exceptions.base.MockitoException; //导入依赖的package包/类
private static Set<Object> scanMocks(Object testClass, Class<?> clazz) {
Set<Object> mocks = new HashSet<Object>();
for (Field field : clazz.getDeclaredFields()) {
// mock or spies only
if (null != field.getAnnotation(Spy.class) || null != field.getAnnotation(org.mockito.Mock.class)
|| null != field.getAnnotation(Mock.class)) {
Object fieldInstance = null;
boolean wasAccessible = field.isAccessible();
field.setAccessible(true);
try {
fieldInstance = field.get(testClass);
} catch (IllegalAccessException e) {
throw new MockitoException("Problems injecting dependencies in " + field.getName(), e);
} finally {
field.setAccessible(wasAccessible);
}
if (fieldInstance != null) {
mocks.add(fieldInstance);
}
}
}
return mocks;
}
示例9: initMocks
import org.mockito.exceptions.base.MockitoException; //导入依赖的package包/类
/**
* Initializes objects annotated with Mockito annotations for given testClass:
* @{@link org.mockito.Mock}, @{@link Spy}, @{@link Captor}, @{@link InjectMocks}
* <p>
* See examples in javadoc for {@link MockitoAnnotations} class.
*/
public static void initMocks(Object testClass) {
if (testClass == null) {
throw new MockitoException("testClass cannot be null. For info how to use @Mock annotations see examples in javadoc for MockitoAnnotations class");
}
AnnotationEngine annotationEngine = new GlobalConfiguration().getAnnotationEngine();
Class<?> clazz = testClass.getClass();
//below can be removed later, when we get read rid of deprecated stuff
if (annotationEngine.getClass() != new DefaultMockitoConfiguration().getAnnotationEngine().getClass()) {
//this means user has his own annotation engine and we have to respect that.
//we will do annotation processing the old way so that we are backwards compatible
while (clazz != Object.class) {
scanDeprecatedWay(annotationEngine, testClass, clazz);
clazz = clazz.getSuperclass();
}
}
//anyway act 'the new' way
annotationEngine.process(testClass.getClass(), testClass);
}
示例10: shouldThrowMeaningfulMockitoExceptionIfNoValidJUnitFound
import org.mockito.exceptions.base.MockitoException; //导入依赖的package包/类
@Test
public void
shouldThrowMeaningfulMockitoExceptionIfNoValidJUnitFound() throws Exception{
//given
RunnerProvider provider = new RunnerProvider() {
public boolean isJUnit45OrHigherAvailable() {
return false;
}
public RunnerImpl newInstance(String runnerClassName, Class<?> constructorParam) throws Exception {
throw new InitializationError("Where is JUnit, dude?");
}
};
RunnerFactory factory = new RunnerFactory(provider);
try {
//when
factory.create(RunnerFactoryTest.class);
fail();
} catch (MockitoException e) {
//then
assertContains("upgrade your JUnit version", e.getMessage());
}
}
示例11: process
import org.mockito.exceptions.base.MockitoException; //导入依赖的package包/类
public void process(Class<?> clazz, Object testInstance) {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
boolean alreadyAssigned = false;
for(Annotation annotation : field.getAnnotations()) {
Object mock = createMockFor(annotation, field);
if (mock != null) {
throwIfAlreadyAssigned(field, alreadyAssigned);
alreadyAssigned = true;
try {
new FieldSetter(testInstance, field).set(mock);
} catch (Exception e) {
throw new MockitoException("Problems setting field " + field.getName() + " annotated with "
+ annotation, e);
}
}
}
}
}
示例12: processAnnotationDeprecatedWay
import org.mockito.exceptions.base.MockitoException; //导入依赖的package包/类
@SuppressWarnings("deprecation")
static void processAnnotationDeprecatedWay(AnnotationEngine annotationEngine, Object testClass, Field field) {
boolean alreadyAssigned = false;
for(Annotation annotation : field.getAnnotations()) {
Object mock = annotationEngine.createMockFor(annotation, field);
if (mock != null) {
throwIfAlreadyAssigned(field, alreadyAssigned);
alreadyAssigned = true;
try {
new FieldSetter(testClass, field).set(mock);
} catch (Exception e) {
throw new MockitoException("Problems setting field " + field.getName() + " annotated with "
+ annotation, e);
}
}
}
}
示例13: full
import org.mockito.exceptions.base.MockitoException; //导入依赖的package包/类
@Test
public void full() throws IOException, InterruptedException {
final BatchTaskVo<GroupImportEntry> importTask = full("Gfi France;Fonction");
// Check the result
final GroupImportEntry importEntry = checkImportTask(importTask);
Assert.assertEquals("Gfi France", importEntry.getName());
Assert.assertEquals("Fonction", importEntry.getType());
Assert.assertNull(importEntry.getDepartment());
Assert.assertNull(importEntry.getOwner());
Assert.assertNull(importEntry.getAssistant());
Assert.assertNull(importEntry.getParent());
Assert.assertTrue(importEntry.getStatus());
Assert.assertNull(importEntry.getStatusText());
// Check LDAP
Mockito.verify(mockLdapResource, new DefaultVerificationMode(data -> {
if (data.getAllInvocations().size() != 1) {
throw new MockitoException("Expect one call");
}
final GroupEditionVo group = (GroupEditionVo) data.getAllInvocations().get(0).getArguments()[0];
Assert.assertNotNull(group);
Assert.assertEquals("Gfi France", group.getName());
Assert.assertNotNull(group.getScope());
Assert.assertTrue(group.getDepartments().isEmpty());
Assert.assertTrue(group.getOwners().isEmpty());
Assert.assertTrue(group.getAssistants().isEmpty());
Assert.assertNull(group.getParent());
})).create(null);
}
示例14: fullFull
import org.mockito.exceptions.base.MockitoException; //导入依赖的package包/类
@Test
public void fullFull() throws IOException, InterruptedException {
final BatchTaskVo<GroupImportEntry> importTask = full("Opérations Spéciales;Fonction;Operations;fdaugan,alongchu;jdoe5,wuser;700301,700302");
// Check the result
final GroupImportEntry importEntry = checkImportTask(importTask);
Assert.assertEquals("Opérations Spéciales", importEntry.getName());
Assert.assertEquals("Fonction", importEntry.getType());
Assert.assertEquals("Operations", importEntry.getParent());
Assert.assertEquals("fdaugan,alongchu", importEntry.getOwner());
Assert.assertEquals("jdoe5,wuser", importEntry.getAssistant());
Assert.assertEquals("700301,700302", importEntry.getDepartment());
Assert.assertTrue(importEntry.getStatus());
Assert.assertNull(importEntry.getStatusText());
// Check LDAP
Mockito.verify(mockLdapResource, new DefaultVerificationMode(data -> {
if (data.getAllInvocations().size() != 1) {
throw new MockitoException("Expect one call");
}
final GroupEditionVo group = (GroupEditionVo) data.getAllInvocations().get(0).getArguments()[0];
Assert.assertNotNull(group);
Assert.assertEquals("Opérations Spéciales", group.getName());
Assert.assertNotNull(group.getScope());
Assert.assertEquals(2, group.getOwners().size());
Assert.assertEquals("fdaugan", group.getOwners().get(0));
Assert.assertEquals(2, group.getAssistants().size());
Assert.assertEquals("jdoe5", group.getAssistants().get(0));
Assert.assertEquals(2, group.getDepartments().size());
Assert.assertEquals("700301", group.getDepartments().get(0));
Assert.assertEquals("Operations", group.getParent());
})).create(null);
}
示例15: full
import org.mockito.exceptions.base.MockitoException; //导入依赖的package包/类
@Test
public void full() throws IOException, InterruptedException {
final BatchTaskVo<UserImportEntry> importTask = full("Loubli;Sébastien;kloubli;[email protected];gfi;jira");
// Check the result
final UserImportEntry importEntry = checkImportTask(importTask);
Assert.assertEquals("gfi", importEntry.getCompany());
Assert.assertEquals("Sébastien", importEntry.getFirstName());
Assert.assertEquals("Loubli", importEntry.getLastName());
Assert.assertEquals("kloubli", importEntry.getId());
Assert.assertEquals("jira", importEntry.getGroups());
Assert.assertEquals("[email protected]", importEntry.getMail());
Assert.assertTrue(importEntry.getStatus());
Assert.assertNull(importEntry.getStatusText());
// Check LDAP
Mockito.verify(mockLdapResource, new DefaultVerificationMode(data -> {
if (data.getAllInvocations().size() != 1) {
throw new MockitoException("Expect one call");
}
final UserOrgEditionVo userLdap = (UserOrgEditionVo) data.getAllInvocations().get(0).getArguments()[0];
Assert.assertNotNull(userLdap);
Assert.assertEquals("Sébastien", userLdap.getFirstName());
Assert.assertEquals("Loubli", userLdap.getLastName());
Assert.assertEquals("kloubli", userLdap.getId());
Assert.assertEquals("gfi", userLdap.getCompany());
Assert.assertEquals("[email protected]", userLdap.getMail());
})).create(null);
}