java.lang.IllegalArgumentException.getCause()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(239)

本文整理了Java中java.lang.IllegalArgumentException.getCause()方法的一些代码示例,展示了IllegalArgumentException.getCause()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IllegalArgumentException.getCause()方法的具体详情如下:
包路径:java.lang.IllegalArgumentException
类名称:IllegalArgumentException
方法名:getCause

IllegalArgumentException.getCause介绍

暂无

代码示例

代码示例来源:origin: org.mockito/mockito-core

@SuppressWarnings("unchecked")
@Override
public <T> Class<T> mockClass(final MockFeatures<T> params) {
  try {
    ClassLoader classLoader = params.mockedType.getClassLoader();
    return (Class<T>) typeCache.findOrInsert(classLoader,
        new MockitoMockKey(params.mockedType, params.interfaces, params.serializableMode, params.stripAnnotations),
        new Callable<Class<?>>() {
          @Override
          public Class<?> call() throws Exception {
            return bytecodeGenerator.mockClass(params);
          }
        }, BOOTSTRAP_LOCK);
  } catch (IllegalArgumentException exception) {
    Throwable cause = exception.getCause();
    if (cause instanceof RuntimeException) {
      throw (RuntimeException) cause;
    } else {
      throw exception;
    }
  }
}

代码示例来源:origin: prestodb/presto

Throwable cause = e.getCause();
if (cause instanceof UnrecognizedPropertyException) {
  UnrecognizedPropertyException ex = (UnrecognizedPropertyException) cause;

代码示例来源:origin: prestodb/presto

Throwable cause = e.getCause();
if (cause instanceof UnrecognizedPropertyException) {
  UnrecognizedPropertyException ex = (UnrecognizedPropertyException) cause;

代码示例来源:origin: eclipse-vertx/vert.x

private void testInvalidValueToPOJO(String key) {
 try {
  new JsonObject().put(key, "1").mapTo(MyType2.class);
  fail();
 } catch (IllegalArgumentException e) {
  assertThat(e.getCause(), is(instanceOf(InvalidFormatException.class)));
  InvalidFormatException ife = (InvalidFormatException) e.getCause();
  assertEquals("1", ife.getValue());
 }
}

代码示例来源:origin: apache/hbase

@Test
public void testParseOptsWrongThreads() {
 Queue<String> opts = new LinkedList<>();
 String cmdName = "sequentialWrite";
 opts.offer(cmdName);
 opts.offer("qq");
 try {
  PerformanceEvaluation.parseOpts(opts);
 } catch (IllegalArgumentException e) {
  System.out.println(e.getMessage());
  assertEquals("Command " + cmdName + " does not have threads number", e.getMessage());
  assertTrue(e.getCause() instanceof NumberFormatException);
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testThatInvalidValuesAsDefaultValueAreReported() throws CLIException {
 try {
  cli.addArgument(new TypedArgument<Integer>()
    .setIndex(0).setArgName("1").setType(Integer.class).setDefaultValue("a"));
 } catch (IllegalArgumentException e) {
  assertThat(e.getCause()).isInstanceOf(InvalidValueException.class);
  InvalidValueException cause = (InvalidValueException) e.getCause();
  assertThat(cause.getArgument().getIndex()).isEqualTo(0);
  assertThat(cause.getArgument().getArgName()).isEqualTo("1");
  assertThat(cause.getValue()).isEqualTo("a");
 }
}

代码示例来源:origin: apache/hbase

@Test
public void testParseOptsNoThreads() {
 Queue<String> opts = new LinkedList<>();
 String cmdName = "sequentialWrite";
 try {
  PerformanceEvaluation.parseOpts(opts);
 } catch (IllegalArgumentException e) {
  System.out.println(e.getMessage());
  assertEquals("Command " + cmdName + " does not have threads number", e.getMessage());
  assertTrue(e.getCause() instanceof NoSuchElementException);
 }
}

代码示例来源:origin: voldemort/voldemort

public void testClassWithNoParseFrom() {
  try {
    new ProtoBufSerializer<Message>("java=" + MessageWithNoParseFrom.class.getName());
  } catch(IllegalArgumentException e) {
    assertEquals(NoSuchMethodException.class, e.getCause().getClass());
    return;
  }
  fail("IllegalArgumentException should have been thrown");
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testIncorrectSyntax() {
  Session s = openSession();
  Transaction t = s.beginTransaction();
  try {
    s.createQuery( "update Human set Human.description = 'xyz' where Human.id = 1 and Human.description is null" );
    fail( "expected failure" );
  }
  catch (IllegalArgumentException e) {
    assertTyping( QueryException.class, e.getCause() );
  }
  catch( QueryException expected ) {
    // ignore : expected behavior
  }
  t.commit();
  s.close();
}

代码示例来源:origin: voldemort/voldemort

public void testNonExistentClass() {
  try {
    new ProtoBufSerializer<Message>("java=com.foo.Bar");
  } catch(IllegalArgumentException e) {
    assertEquals(ClassNotFoundException.class, e.getCause().getClass());
    return;
  }
  fail("IllegalArgumentException should have been thrown");
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testDeleteNonExistentEntity() {
  Session s = openSession();
  Transaction t = s.beginTransaction();
  try {
    s.createQuery( "delete NonExistentEntity" ).executeUpdate();
    fail( "no exception thrown" );
  }
  catch (IllegalArgumentException e) {
    assertTyping( QueryException.class, e.getCause() );
  }
  catch( QueryException ignore ) {
  }
  t.commit();
  s.close();
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testUpdateNonExistentEntity() {
  Session s = openSession();
  Transaction t = s.beginTransaction();
  try {
    s.createQuery( "update NonExistentEntity e set e.someProp = ?" ).executeUpdate();
    fail( "no exception thrown" );
  }
  catch (IllegalArgumentException e) {
    assertTyping( QueryException.class, e.getCause() );
  }
  catch( QueryException e ) {
  }
  t.commit();
  s.close();
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testTupleReturnFails() {
  Session s = openSession();
  Transaction txn = s.beginTransaction();
  try {
    s.createQuery( "select a, a.weight from Animal a inner join fetch a.offspring" ).scroll();
    fail( "scroll allowed with collection fetch and reurning tuples" );
  }
  catch (IllegalArgumentException e) {
    assertTyping( QueryException.class, e.getCause() );
  }
  catch( HibernateException e ) {
    // expected result...
  }
  txn.commit();
  s.close();
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testSelectWithNamedParamProjection() {
  Session s = openSession();
  try {
    s.createQuery("select :someParameter, id from Car");
    fail("Should throw an unsupported exception");
  }
  catch (IllegalArgumentException e) {
    assertTyping( QueryException.class, e.getCause() );
  }
  catch(QueryException q) {
    // allright
  }
  finally {
    s.close();
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testFetchInSubqueryFails() {
  Session s = openSession();
  try {
    s.createQuery( "from Animal a where a.mother in (select m from Animal a1 inner join a1.mother as m join fetch m.mother)" ).list();
    fail( "fetch join allowed in subquery" );
  }
  catch (IllegalArgumentException e) {
    assertTyping( QueryException.class, e.getCause() );
  }
  catch( QueryException expected ) {
    // expected behavior
  }
  s.close();
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testIoExceptionWhenLoadingHeader() throws Exception {
  final HeaderCheck check = PowerMockito.spy(new HeaderCheck());
  PowerMockito.doThrow(new IOException("expected exception")).when(check, "loadHeader",
      any());
  try {
    check.setHeader("header");
    fail("Exception expected");
  }
  catch (IllegalArgumentException ex) {
    assertTrue("Invalid exception cause", ex.getCause() instanceof IOException);
    assertEquals("Invalid exception message", "unable to load header", ex.getMessage());
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-11942" )
public void testOrderByExtraParenthesis() throws Exception {
  try {
    doInHibernate( this::sessionFactory, session -> {
      session.createQuery(
        "select a from Product a " +
        "where " +
        "coalesce(a.description, :description) = :description ) " +
        "order by a.description ", Product.class)
      .setParameter( "description", "desc" )
      .getResultList();
      fail("Should have thrown exception");
    } );
  }
  catch (IllegalArgumentException e) {
    final Throwable cause = e.getCause();
    assertThat( cause, instanceOf( QuerySyntaxException.class ) );
    assertTrue( cause.getMessage().contains( "expecting EOF, found ')'" ) );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testWithClauseFailsWithFetch() {
  TestData data = new TestData();
  data.prepare();
  Session s = openSession();
  Transaction txn = s.beginTransaction();
  try {
    s.createQuery( "from Animal a inner join fetch a.offspring as o with o.bodyWeight = :someLimit" )
        .setDouble( "someLimit", 1 )
        .list();
    fail( "ad-hoc on clause allowed with fetched association" );
  }
  catch (IllegalArgumentException e) {
    assertTyping( QueryException.class, e.getCause() );
  }
  catch ( HibernateException e ) {
    // the expected response...
  }
  txn.commit();
  s.close();
  data.cleanup();
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testUpdateOnImplicitJoinFails() {
  inTransaction(
      s -> {
        try {
          s.createQuery( "update Human set mother.name.initial = :initial" ).setString( "initial", "F" ).executeUpdate();
          fail( "update allowed across implicit join" );
        }
        catch (IllegalArgumentException e) {
          assertTyping( QueryException.class, e.getCause() );
        }
        catch( QueryException e ) {
        }
      }
  );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testMultipleBagFetchesFail() {
  try ( final SessionImplementor s = (SessionImplementor) openSession() ) {
    inTransaction(
        s,
        session-> {
          try {
            s.createQuery( "from Human h join fetch h.friends f join fetch f.friends fof" ).list();
            fail( "failure expected" );
          }
          catch (IllegalArgumentException e) {
            assertTyping( MultipleBagFetchException.class, e.getCause() );
          }
          catch( HibernateException e ) {
            assertTrue( "unexpected failure reason : " + e, e.getMessage().indexOf( "multiple bags" ) > 0 );
          }
        }
    );
  }
}

相关文章