Refine search
private void testItems() { for (Object item : Iterables.concat(equalityGroups)) { assertTrue(item + " must not be Object#equals to null", !item.equals(null)); assertTrue( item + " must not be Object#equals to an arbitrary object of another class", !item.equals(NotAnInstance.EQUAL_TO_NOTHING)); assertEquals(item + " must be Object#equals to itself", item, item); assertEquals( "the Object#hashCode of " + item + " must be consistent", item.hashCode(), item.hashCode()); } }
/** * 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 } }
/** * Asserts that a Unicode escaper escapes the given code point into the expected string. * * @param escaper the non-null escaper to test * @param expected the expected output string * @param cp the Unicode code point to escape */ public static void assertEscaping(UnicodeEscaper escaper, String expected, int cp) { String escaped = computeReplacement(escaper, cp); Assert.assertNotNull(escaped); Assert.assertEquals(expected, escaped); }
/** * 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()); } }
private void findByNameAndAgeGTAndLT() { EntityManager em; String query; Query q; List<StudentBooleanPrimitive> students; em = emf.createEntityManager(); query = "Select s From StudentBooleanPrimitive s where s.name = Amresh and s.age > " + getMinValue(short.class) + " and s.age < " + getMaxValue(short.class); q = em.createQuery(query); students = q.getResultList(); Assert.assertNotNull(students); Assert.assertTrue(students.isEmpty()); em.close(); }
/** * Test having. */ private void testHaving() { String queryString = "Select sum(p.salary) from Person p group by p.age having avg(p.age) > 20"; Query query = em.createQuery(queryString); List resultList = query.getResultList(); Assert.assertEquals(2, resultList.size()); Assert.assertEquals(1000.0, (resultList.get(0))); Assert.assertEquals(1200.0, (resultList.get(1))); }
private <E extends Object> void assertFindByName(EntityManager em, String clazz, E e, String name, String fieldName) { String query = "Select p from PF p where p." + fieldName + " = " + name; // // find by name. Query q = em.createQuery(query); List<E> results = q.getResultList(); Assert.assertNotNull(results); Assert.assertFalse(results.isEmpty()); Assert.assertEquals(3, results.size()); }
public void testFindById(boolean useSameEm) { EntityManager em = emf.createEntityManager(); StudentMongoCalendar studentMax = em.find(StudentMongoCalendar.class, getMaxValue(Calendar.class)); Assert.assertNotNull(studentMax); Assert.assertEquals(getMaxValue(short.class), studentMax.getAge()); Assert.assertEquals(getMaxValue(String.class), studentMax.getName()); em.close(); }
@SuppressWarnings({"SelfComparison", "SelfEquals"}) public static <T extends Comparable<? super T>> void testCompareToAndEquals( List<T> valuesInExpectedOrder) { // This does an O(n^2) test of all pairs of values in both orders for (int i = 0; i < valuesInExpectedOrder.size(); i++) { T t = valuesInExpectedOrder.get(i); for (int j = 0; j < i; j++) { T lesser = valuesInExpectedOrder.get(j); assertTrue(lesser + ".compareTo(" + t + ')', lesser.compareTo(t) < 0); assertFalse(lesser.equals(t)); } assertEquals(t + ".compareTo(" + t + ')', 0, t.compareTo(t)); assertTrue(t.equals(t)); for (int j = i + 1; j < valuesInExpectedOrder.size(); j++) { T greater = valuesInExpectedOrder.get(j); assertTrue(greater + ".compareTo(" + t + ')', greater.compareTo(t) > 0); assertFalse(greater.equals(t)); } } }
@Override protected Object handleInvocation(Object p, Method calledMethod, Object[] args) throws Throwable { assertEquals(method, calledMethod); assertEquals(method + " invoked more than once.", 0, called.get()); for (int i = 0; i < passedArgs.length; i++) { assertEquals( "Parameter #" + i + " of " + method + " not forwarded", passedArgs[i], args[i]); } called.getAndIncrement(); return returnValue; }
private void deleteNamedQueryOnCounter() { EntityManager em = emf.createEntityManager(); String deleteQuery = "Delete From Counters c where c.id <= " + id2; Query q = em.createQuery(deleteQuery); q.executeUpdate(); Counters counter2 = new Counters(); counter2 = em.find(Counters.class, id1); Assert.assertNull(counter2); Counters counter3 = new Counters(); counter3 = em.find(Counters.class, id2); Assert.assertNull(counter3); em.close(); } }
public void deleteCounter() { EntityManager em = emf.createEntityManager(); Counters counters = new Counters(); counters = em.find(Counters.class, id3); Assert.assertNotNull(counters); Assert.assertNotNull(counters.getCounter()); em.remove(counters); EntityManager em1 = emf.createEntityManager(); counters = em1.find(Counters.class, id3); Assert.assertNull(counters); em.close(); }
private void testSelect() { Query q = em.createQuery("select c from Collecte c where c.id =:id"); q.setParameter("id", "0001"); List<Collecte> collectes = q.getResultList(); Collecte c = collectes.get(0); Assert.assertEquals(c.getEAN(), "3251248033108"); Assert.assertEquals(c.getPhotos().size(), 3); Assert.assertEquals(c.getPhotos().iterator().next().getMd5(), "1235847EA873"); }
/** * @param b */ private void testNativeQuery(boolean b) { String s = "Select * From " + "\"StudentUUID\""; EntityManager em = emf.createEntityManager(); Query q = em.createNativeQuery(s, StudentUUID.class); List<StudentUUID> results = q.getResultList(); Assert.assertNotNull(results); }
/** * Causes this thread to call the named method, and asserts that this thread becomes blocked on * the lock-like object. The lock-like object must have a method equivalent to {@link * java.util.concurrent.locks.ReentrantLock#hasQueuedThread(Thread)}. */ public void callAndAssertBlocks(String methodName, Object... arguments) throws Exception { checkNotNull(methodName); checkNotNull(arguments); assertEquals(false, invokeMethod("hasQueuedThread", this)); sendRequest(methodName, arguments); Thread.sleep(DUE_DILIGENCE_MILLIS); assertEquals(true, invokeMethod("hasQueuedThread", this)); assertNull(responseQueue.poll()); }
/** * Test delete simple. */ private void testDeleteSimple() { persistData(); int result = em.createQuery("delete from PersonEmbed p").executeUpdate(); Assert.assertEquals(4, result); assertDeleted(T, T, T, T); }
static void checkEmpty(Cache<?, ?> cache) { assertEquals(0, cache.size()); assertFalse(cache.asMap().containsKey(null)); assertFalse(cache.asMap().containsKey(6)); assertFalse(cache.asMap().containsValue(null)); assertFalse(cache.asMap().containsValue(6)); checkEmpty(cache.asMap()); }
@Test public void testLoadInvalidJsonString() { LottieResult<LottieComposition> result = LottieCompositionFactory.fromJsonStringSync(NOT_JSON, "not_json"); assertNotNull(result.getException()); assertNull(result.getValue()); }
public void testFailedFuture(@Nullable String message) throws InterruptedException { assertTrue(future.isDone()); assertFalse(future.isCancelled()); assertTrue(latch.await(5, TimeUnit.SECONDS)); assertTrue(future.isDone()); assertFalse(future.isCancelled()); try { future.get(); fail("Future should rethrow the exception."); } catch (ExecutionException e) { assertThat(e).hasCauseThat().hasMessageThat().isEqualTo(message); } } }
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()); }