Esempio n. 1
0
  @Test
  public void testException() throws Exception {
    try {
      ClassLookup.find().orThrow(new NullPointerException()).get();
      fail(NullPointerException.class.getSimpleName() + " expected");
    } catch (NullPointerException e) {
      // expected
    }

    try {
      ClassLookup.find().orThrow(new IOException()).get();
      fail(RuntimeException.class.getSimpleName() + " expected");
    } catch (RuntimeException e) {
      assertSame(IOException.class, e.getCause().getClass());
    }

    String msg = "I knew it!";
    try {
      ClassLookup.find().orThrow(msg).get();
      fail(RuntimeException.class.getSimpleName() + " expected");
    } catch (RuntimeException e) {
      assertEquals(true, e.toString().endsWith(ExceptionUtils.getMessage(e)));
    }

    try {
      ClassLookup.find().orThrow(msg).list();
      fail(RuntimeException.class.getSimpleName() + " expected");
    } catch (Exception e) {
      assertEquals(true, e.toString().endsWith(ExceptionUtils.getMessage(e)));
    }
  }
Esempio n. 2
0
  @Test
  public void testNull() throws Exception {
    assertEquals(null, ClassLookup.forName(null));
    assertEquals(null, ClassLookup.forName(""));

    assertEquals(null, ClassLookup.find().get());
    assertEquals(null, ClassLookup.find(ArrayUtils.EMPTY_STRING_ARRAY).get());
    assertEquals(null, ClassLookup.find((String) null).get());
    assertEquals(null, ClassLookup.find((String[]) null).get());
    assertEquals(null, ClassLookup.find(new String[] {null}).get());

    ClassLookup lookup = ClassLookup.find(null, Byte.class.getName());
    assertEquals(
        (Class) Byte.class,
        lookup
            .or((Class<?>) null)
            .or((String) null)
            .orThrow(null)
            .orThrow(null, (String) null)
            .get());
  }
Esempio n. 3
0
 @Test
 public void testList() throws Exception {
   assertEquals(0, ClassLookup.find().list().size());
   assertEquals(0, ClassLookup.find("").list().size());
   assertEquals(1, ClassLookup.find("", Object.class.getName()).list().size());
 }