junit.framework.Assert.fail()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(243)

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

Assert.fail介绍

[英]Fails a test with no message.
[中]没有消息的测试失败。

代码示例

代码示例来源:origin: google/guava

/**
 * Asserts that an escaper behaves correctly with respect to null inputs.
 *
 * @param escaper the non-null escaper to test
 */
public static void assertBasic(Escaper escaper) throws IOException {
 // Escapers operate on characters: no characters, no escaping.
 Assert.assertEquals("", escaper.escape(""));
 // Assert that escapers throw null pointer exceptions.
 try {
  escaper.escape((String) null);
  Assert.fail("exception not thrown when escaping a null string");
 } catch (NullPointerException e) {
  // pass
 }
}

代码示例来源:origin: google/guava

/**
 * Verify that the listener completes in a reasonable amount of time, and Asserts that the future
 * throws an {@code ExecutableException} and that the cause of the {@code ExecutableException} is
 * {@code expectedCause}.
 */
public void assertException(Throwable expectedCause) throws Exception {
 // Verify that the listener executed in a reasonable amount of time.
 Assert.assertTrue(countDownLatch.await(1L, TimeUnit.SECONDS));
 try {
  future.get();
  Assert.fail("This call was supposed to throw an ExecutionException");
 } catch (ExecutionException expected) {
  Assert.assertSame(expectedCause, expected.getCause());
 }
}

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

@Override public Boolean apply(Object o) {
    assertNotNull(o);
    Future<Integer> fut = (Future<Integer>)o;
    try {
      assertEquals(42, (int)fut.get());
    }
    catch (Exception ignored) {
      fail("Failed submit task.");
    }
    return true;
  }
}

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

@Test
public void testV1() throws IOException {
 BasicConfigurator.configure();
 Logger.getRootLogger().setLevel(Level.DEBUG);
 final String expected = "test";
 final String ciphered = "eyJ2ZXIiOiIxLjAiLCJ2YWwiOiJOd1hRejdOMjBXUU05SXEzaE94RVZnPT0ifQ==";
 final String passphrase = "test1234";
 final Crypto crypto = new Crypto();
 final String actual = crypto.decrypt(ciphered, passphrase);
 Assert.assertEquals(expected, actual);
 try {
  new CryptoV1_1().decrypt(ciphered, passphrase);
  Assert.fail("Should have failed when decrypt v1 ciphered text with v1.1 decryption.");
 } catch (final Exception e) {
  Assert.assertTrue(e instanceof RuntimeException);
 }
}

代码示例来源:origin: facebook/facebook-android-sdk

@Test
public void testNotNullOrEmptyOnNull() {
  try {
    Validate.notNullOrEmpty(null, "name");
    fail("expected exception");
  } catch (Exception e) {
  }
}

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

@Test
public void testEmptyPartitionList() {
  PartitionListIterator plistItr = new PartitionListIterator(store, new ArrayList<Integer>());
  assertEquals("Empty list cannot have a next element", false, plistItr.hasNext());
  try {
    plistItr.next();
    fail("Should have thrown an exception for next()");
  } catch(NoSuchElementException ne) {
  } finally {
    plistItr.close();
  }
}

代码示例来源:origin: facebook/facebook-android-sdk

@Test
public void testAddAttachmentsForCallWithNullBitmap() throws Exception {
  try {
    List<NativeAppCallAttachmentStore.Attachment> attachments =
        createAttachments(CALL_ID, null);
    NativeAppCallAttachmentStore.addAttachments(attachments);
    fail("expected exception");
  } catch (NullPointerException ex) {
    assertTrue(ex.getMessage().contains("attachmentBitmap"));
  }
}

代码示例来源:origin: Impetus/Kundera

@Test
public void testWithNullEntity()
{
  try
  {
    KunderaMetadataManager.getEntityMetadata(kunderaMetadata, null);
    Assert.fail("Should have gone to catch block!");
  }
  catch (KunderaException kex)
  {
    Assert.assertNotNull(kex);
  }
}

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

@Override public Boolean apply(Object o) {
    assertNotNull(o);
    IgniteMessaging msg = client.message();
    msg.send(null, "Test message.");
    try {
      assertTrue(recvLatch.await(2, SECONDS));
    }
    catch (InterruptedException ignored) {
      fail("Message wasn't received.");
    }
    return true;
  }
}

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

@Override public void run() {
    try {
      client.dataStreamer(CACHE_NAME);
      fail();
    }
    catch (IgniteClientDisconnectedException e) {
      assertNotNull(e.reconnectFuture());
    }
  }
});

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

@Test
 public void testInvalidParams() throws IOException {
  BasicConfigurator.configure();
  Logger.getRootLogger().setLevel(Level.DEBUG);

  final String expected = "test";
  final String[] cipheredtexts = {
    "eyJ2ZXIiOiIxLjAiLCJ2YWwiOiJOd1hRejdOMjBXUU05SXEzaE94RVZnPT0ifQ==", null, ""};
  final String[] passphrases = {"test1234", null, ""};

  for (final String cipheredtext : cipheredtexts) {
   for (final String passphrase : passphrases) {
    final Crypto crypto = new Crypto();
    if (!StringUtils.isEmpty(cipheredtext) && !StringUtils.isEmpty(passphrase)) {
     final String actual = crypto.decrypt(cipheredtext, passphrase);
     Assert.assertEquals(expected, actual);
    } else {
     try {
      crypto.decrypt(cipheredtext, passphrase);
      Assert.fail("Encyption should have failed with invalid parameters. cipheredtext: "
        + cipheredtext + " , passphrase: " + passphrase);
     } catch (final Exception e) {
      Assert.assertTrue(e instanceof IllegalArgumentException);
     }
    }
   }
  }
 }
}

代码示例来源:origin: facebook/facebook-android-sdk

@Test
public void testNotNullOnNull() {
  try {
    Validate.notNull(null, "name");
    fail("expected exception");
  } catch (Exception e) {
  }
}

代码示例来源:origin: sockeqwe/AdapterDelegates

@Test
public void viewTypeInConflictWithFallbackDelegate() {
  try {
    AdapterDelegatesManager<List> manager = new AdapterDelegatesManager<>();
    manager.addDelegate(AdapterDelegatesManager.FALLBACK_DELEGATE_VIEW_TYPE,
        new SpyableAdapterDelegate<List>(0));
    Assert.fail(
        "An exception should be thrown because view type integer is already reserved for fallback delegate");
  } catch (IllegalArgumentException e) {
    Assert.assertEquals("The view type = "
            + AdapterDelegatesManager.FALLBACK_DELEGATE_VIEW_TYPE
            + " is reserved for fallback adapter delegate (see setFallbackDelegate() ). Please use another view type.",
        e.getMessage());
  }
}

代码示例来源:origin: facebook/facebook-android-sdk

@Test
public void testAddAttachmentsForCallWithNullCallId() throws Exception {
  try {
    List<NativeAppCallAttachmentStore.Attachment> attachments =
        createAttachments(null, createBitmap());
    NativeAppCallAttachmentStore.addAttachments(attachments);
    fail("expected exception");
  } catch (NullPointerException ex) {
    assertTrue(ex.getMessage().contains("callId"));
  }
}

代码示例来源:origin: Impetus/Kundera

/**
 * Test method for
 * {@link com.impetus.kundera.lifecycle.states.ManagedState#handleRefresh(com.impetus.kundera.lifecycle.NodeStateContext)}
 * .
 */
@Test
public void testHandleRefresh()
{
  try
  {
    Node storeNode = StoreBuilder.buildStoreNode(pc, state, CascadeType.REFRESH);
    state.handleRefresh(storeNode);
    Assert.fail("Exception should be thrown because client is not available");
  }
  catch (Exception e)
  {
    Assert.assertNotNull(e);
  }
}

代码示例来源:origin: facebook/facebook-android-sdk

public static void assertEqualContents(final Bundle a, final Bundle b) {
  for (String key : a.keySet()) {
    if (!b.containsKey(key)) {
      Assert.fail("bundle does not include key " + key);
    }
    Assert.assertEquals(a.get(key), b.get(key));
  }
  for (String key : b.keySet()) {
    if (!a.containsKey(key)) {
      Assert.fail("bundle does not include key " + key);
    }
  }
}

代码示例来源:origin: google/guava

public static void assertEqualIgnoringOrder(Iterable<?> expected, Iterable<?> actual) {
 List<?> exp = copyToList(expected);
 List<?> act = copyToList(actual);
 String actString = act.toString();
 // Of course we could take pains to give the complete description of the
 // problem on any failure.
 // Yeah it's n^2.
 for (Object object : exp) {
  if (!act.remove(object)) {
   Assert.fail(
     "did not contain expected element "
       + object
       + ", "
       + "expected = "
       + exp
       + ", actual = "
       + actString);
  }
 }
 assertTrue("unexpected elements: " + act, act.isEmpty());
}

代码示例来源:origin: Impetus/Kundera

@Override
protected void update()
{
  try
  {
    PersonU1M p = (PersonU1M) dao.findPerson(PersonU1M.class, "unionetomany_1");
    Assert.assertNotNull(p);
    Assert.assertEquals(2, p.getAddresses().size());
    p.setPersonName("Saurabh");
    for (AddressU1M address : p.getAddresses())
    {
      address.setStreet("Brand New Street");
    }
    dao.merge(p);
    assertPersonAfterUpdate();
  }
  catch (Exception e)
  {
    
    Assert.fail();
  }
}

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

@Override public void run() {
    try {
      tx.commit();
      fail();
    }
    catch (IgniteClientDisconnectedException e) {
      log.info("Expected error: " + e);
      assertNotNull(e.reconnectFuture());
    }
    try {
      txs.txStart();
      fail();
    }
    catch (IgniteClientDisconnectedException e) {
      log.info("Expected error: " + e);
      assertNotNull(e.reconnectFuture());
    }
  }
});

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

@Test
public void testV1_1() throws IOException {
 BasicConfigurator.configure();
 Logger.getRootLogger().setLevel(Level.DEBUG);
 final String expected = "test";
 final String ciphered = "eyJ2ZXIiOiIxLjEiLCJ2YWwiOiJpaE9CM2VzTzBad2F4cHZBV2Z5YUVicHZLQzJBWDJZZnVzS3hVWFN2R3A0PSJ9";
 final String passphrase = "test1234";
 final Crypto crypto = new Crypto();
 final String actual = crypto.decrypt(ciphered, passphrase);
 Assert.assertEquals(expected, actual);
 try {
  new CryptoV1().decrypt(ciphered, passphrase);
  Assert.fail("Should have failed when decrypt v1.1 ciphered text with v1 decryption.");
 } catch (final Exception e) {
  Assert.assertTrue(e instanceof RuntimeException);
 }
}

相关文章