/** * 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 } }
/** * 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()); } }
@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; } }
@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); } }
@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(); } }
@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")); } }
@Test public void testWithNullEntity() { try { KunderaMetadataManager.getEntityMetadata(kunderaMetadata, null); Assert.fail("Should have gone to catch block!"); } catch (KunderaException kex) { Assert.assertNotNull(kex); } }
@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; } }
@Override public void run() { try { client.dataStreamer(CACHE_NAME); fail(); } catch (IgniteClientDisconnectedException e) { assertNotNull(e.reconnectFuture()); } } });
@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); } } } } } }
@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()); } }
@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")); } }
/** * 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); } }
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); } } }
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()); }
@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(); } }
@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()); } } });
@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); } }