@Override @SafeVarargs public final ObjectArrayAssert<ELEMENT> containsExactly(ELEMENT... values) { return super.containsExactly(values); }
@Override @SafeVarargs public final ObjectArrayAssert<ELEMENT> containsExactly(ELEMENT... values) { return super.containsExactly(values); }
/** * Same as {@link #containsExactly(Object...)} but handles the {@link Iterable} to array conversion : verifies that * actual contains exactly the elements of the given {@code Iterable} and nothing else <b>in the same order</b>. * <p> * Example : * <pre><code class='java'> Ring[] elvesRings = {vilya, nenya, narya}; * * // assertion will pass * assertThat(elvesRings).containsExactlyElementsOf(newLinkedList(vilya, nenya, narya)); * * // assertion will fail as actual and expected order differ * assertThat(elvesRings).containsExactlyElementsOf(newLinkedList(nenya, vilya, narya));</code></pre> * * @param iterable the given {@code Iterable} we will get elements from. */ @Override public SELF containsExactlyElementsOf(Iterable<? extends ELEMENT> iterable) { return containsExactly(toArray(iterable)); }
/** * Same as {@link #containsExactly(Object...)} but handles the {@link Iterable} to array conversion : verifies that * actual contains exactly the elements of the given {@code Iterable} and nothing else <b>in the same order</b>. * <p> * Example : * <pre><code class='java'> Ring[] elvesRings = {vilya, nenya, narya}; * * // assertion will pass * assertThat(elvesRings).containsExactlyElementsOf(newLinkedList(vilya, nenya, narya)); * * // assertion will fail as actual and expected order differ * assertThat(elvesRings).containsExactlyElementsOf(newLinkedList(nenya, vilya, narya));</code></pre> * * @param iterable the given {@code Iterable} we will get elements from. */ @Override public SELF containsExactlyElementsOf(Iterable<? extends ELEMENT> iterable) { return containsExactly(toArray(iterable)); }
@Test public void contact() { String[] array = new String[] { "d", "a", "c" }; assertThat(ArrayUtil.concat("z", array)).containsExactly("z", "d", "a", "c"); assertThat(ArrayUtil.concat(array, "z")).containsExactly("d", "a", "c", "z"); }
@Test public void offerWithOneLength() throws Exception { Queue<Integer> queue = new ConcurrentEvictingQueue<>(1); assertThat(queue.size()).isEqualTo(0); queue.offer(1); assertThat(queue.toArray()).containsExactly(1); assertThat(queue.size()).isEqualTo(1); queue.offer(2); assertThat(queue.toArray()).containsExactly(2); assertThat(queue.size()).isEqualTo(1); }
@Test public void offer() throws Exception { Queue<Integer> queue = new ConcurrentEvictingQueue<>(3); assertThat(queue.isEmpty()).isTrue(); boolean offer = queue.offer(1); assertThat(offer).isTrue(); assertThat(queue.toArray()).containsExactly(1); assertThat(queue.size()).isEqualTo(1); queue.offer(2); assertThat(queue.toArray()).containsExactly(1, 2); assertThat(queue.size()).isEqualTo(2); queue.offer(3); assertThat(queue.toArray()).containsExactly(1, 2, 3); assertThat(queue.size()).isEqualTo(3); queue.offer(4); assertThat(queue.toArray()).containsExactly(2, 3, 4); assertThat(queue.size()).isEqualTo(3); }
@Test public void peek() throws Exception { Queue<Integer> queue = new ConcurrentEvictingQueue<>(2); Integer emptyPeek = queue.peek(); assertThat(emptyPeek).isNull(); queue.offer(1); assertThat(queue.toArray()).containsExactly(1); Integer first = queue.peek(); assertThat(first).isEqualTo(1); assertThat(queue.toArray()).containsExactly(1); queue.offer(2); assertThat(queue.toArray()).containsExactly(1, 2); Integer second = queue.peek(); assertThat(second).isEqualTo(1); assertThat(queue.toArray()).containsExactly(1, 2); }
@Test public void clear() throws Exception { Queue<Integer> queue = new ConcurrentEvictingQueue<>(2); assertThat(queue).isEmpty(); queue.clear(); assertThat(queue).isEmpty(); queue.offer(1); assertThat(queue.toArray()).containsExactly(1); queue.offer(2); assertThat(queue.toArray()).containsExactly(1, 2); queue.clear(); assertThat(queue).isEmpty(); assertThat(queue.size()).isEqualTo(0); queue.offer(3); assertThat(queue.toArray()).containsExactly(3); }
@Test public void toArray() throws Exception { Queue<Integer> queue = new ConcurrentEvictingQueue<>(5); Object[] objects = queue.toArray(); assertThat(objects.length).isEqualTo(0); queue.add(1); assertThat(queue.toArray()).containsExactly(1); queue.clear(); queue.addAll(asList(1, 2, 3, 4, 5)); assertThat(queue.toArray()).containsExactly(1, 2, 3, 4, 5); queue.clear(); assertThat(queue).isEmpty(); queue.addAll(asList(1, 2, 3, 4, 5, 6, 7, 8, 9)); assertThat(queue.toArray()).containsExactly(5, 6, 7, 8, 9); queue.clear(); assertThat(queue).isEmpty(); }
@Test public void shuffle() { String[] arrays = new String[] { "d", "a", "c", "b", "e", "i", "g" }; String[] arraysClone = Arrays.copyOf(arrays, arrays.length); Arrays.sort(arrays); assertThat(arrays).containsExactly("a", "b", "c", "d", "e", "g", "i"); ArrayUtil.shuffle(arrays); assertFalse("should not be equal to origin array", Arrays.equals(arrays, arraysClone)); // System.out.println(Arrays.toString(arrays)); Arrays.sort(arrays); ArrayUtil.shuffle(arrays, RandomUtil.secureRandom()); assertFalse("should not be equal to origin array", Arrays.equals(arrays, arraysClone)); }
assertThat(queue.toArray()).containsExactly(1); queue.clear(); assertThat(first).containsExactly(1, 2, 3, 4, 5); assertThat(second).containsExactly(1, 2, 3, 4, 5, null, null); assertThat(third).containsExactly(null, null); assertThat(thirdResult).containsExactly(1, 2, 3, 4, 5); assertThat(queue.toArray(fourth)).containsExactly(5, 6, 7, 8, 9, 66, 77, 88); queue.clear(); assertThat(queue).isEmpty();
@Test public void shutdown() { taskList.add(task1); serialQueue.runningTask = task2; final DownloadTask[] tasks = serialQueue.shutdown(); verify(task2).cancel(); assertThat(serialQueue.shutedDown).isTrue(); assertThat(tasks).containsExactly(task1); }
@Test public void build() { DownloadListenerBunch.Builder builder = new DownloadListenerBunch.Builder(); DownloadListenerBunch listenerBunch = builder.append(listener1).append(listener2).build(); assertThat(listenerBunch.listenerList).containsExactly(listener1, listener2); }
@Test public void testNullInStringArray() { PersistableBundleCompat bundle = new PersistableBundleCompat(); String[] array = {"111", null, "333"}; bundle.putStringArray("array", array); bundle = PersistableBundleCompat.fromXml(bundle.saveToXml()); String[] inflated = bundle.getStringArray("array"); assertThat(inflated).isNotNull().hasSize(3).containsExactly("111", null, "333"); } }
assertThat(inflated.getLongArray("longArr")).isNotEmpty().containsExactly(4L, 5L, 6L); assertThat(inflated.getDoubleArray("doubleArr")).isNotEmpty().containsExactly(7.0, 8.0, 9.0); assertThat(inflated.getStringArray("stringArr")).isNotEmpty().containsExactly("Hello", "world");
@Test public void shouldReplaceMethodsReturningArraysMatchingArgumentType() throws Exception { final Mutant mutant = getFirstMutant(HasArrayMethod.class); final String[] expected = { "1", "2" }; final String[] actual = mutateAndCall(new HasArrayMethod(), mutant); assertThat(actual).containsExactly(expected); }
@Test public void test$ShouldReturnObjectArrayWithAllElementsForMultipleArg() { // Given: long millis = System.currentTimeMillis(); Date now = new Date(); // When: Object[] result = $(millis, now, "equals"); // Then: assertThat(result).containsExactly(millis, now, "equals"); }
@Test public void testConvertShouldCreateVarargsArrayForOneLastVarargsArguments() { // Given: Object[] data = new Object[] { 'a', (byte) 2, 1.0 }; Class<?>[] parameterTypes = new Class<?>[] { char.class, byte.class, double[].class }; // When: Object[] result = underTest.convert(data, true, parameterTypes); // Then: assertThat(result).containsExactly('a', (byte) 2, new double[] { 1.0 }); }
public GenericRestExceptionAssert matches(String i18nMessageKey, String... i18nProperties) { assertEquals("The message key of the exception did not match up", i18nMessageKey, actual.getI18nKey()); assertThat(actual.getI18nParameters()).as("I18n properties").containsExactly(i18nProperties); return this; }