Exemple #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void safeForAllShouldConsumeAllSubjectsRegardlessOfSuccess()
        internal virtual void SafeForAllShouldConsumeAllSubjectsRegardlessOfSuccess()
        {
            // given
            IList <string> seenSubjects   = new List <string>();
            IList <string> failedSubjects = new List <string>();
            ThrowingConsumer <string, Exception> consumer = new ThrowingConsumerAnonymousInnerClass(this, seenSubjects, failedSubjects);
            IEnumerable <string> subjects = asList("1", "2", "3", "4", "5");

            // when
            try
            {
                Iterables.SafeForAll(consumer, subjects);
                fail("Should have thrown exception");
            }
            catch (Exception e)
            {
                // then good
                assertEquals(subjects, seenSubjects);
                IEnumerator <string> failed = failedSubjects.GetEnumerator();
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue(failed.hasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals(e.Message, failed.next());
                foreach (Exception suppressed in e.Suppressed)
                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    assertTrue(failed.hasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                    assertEquals(suppressed.Message, failed.next());
                }
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(failed.hasNext());
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testFirstElement()
        internal virtual void TestFirstElement()
        {
            object @object = new object();
            object object2 = new object();

            // first Iterable
            assertEquals(@object, Iterables.First(asList(@object, object2)));
            assertEquals(@object, Iterables.First(asList(@object)));
            assertThrows(typeof(NoSuchElementException), () => Iterables.First(asList()));

            // first Iterator
            assertEquals(@object, Iterators.First(asList(@object, object2).GetEnumerator()));
            assertEquals(@object, Iterators.First(asList(@object).GetEnumerator()));
            assertThrows(typeof(NoSuchElementException), () => Iterators.First(asList().GetEnumerator()));

            // firstOrNull Iterable
            assertEquals(@object, Iterables.FirstOrNull(asList(@object, object2)));
            assertEquals(@object, Iterables.FirstOrNull(asList(@object)));
            assertNull(Iterables.FirstOrNull(asList()));

            // firstOrNull Iterator
            assertEquals(@object, Iterators.FirstOrNull(asList(@object, object2).GetEnumerator()));
            assertEquals(@object, Iterators.FirstOrNull(asList(@object).GetEnumerator()));
            assertNull(Iterators.FirstOrNull(asList().GetEnumerator()));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void iterablesStream()
        internal virtual void IterablesStream()
        {
            IList <object> list = new IList <object> {
                1, 2, "3", '4', null, "abc", "56789"
            };

            assertEquals(list, Iterables.Stream(list).collect(toList()));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void getItemFromEnd()
        internal virtual void getItemFromEnd()
        {
            IEnumerable <int> ints = asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);

            assertEquals(( int? )9, Iterables.FromEnd(ints, 0));
            assertEquals(( int? )8, Iterables.FromEnd(ints, 1));
            assertEquals(( int? )7, Iterables.FromEnd(ints, 2));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void iterablesStreamCharacteristics()
        internal virtual void IterablesStreamCharacteristics()
        {
            IEnumerable <int> iterable = asList(1, 2, 3);
            int characteristics        = Spliterator.DISTINCT | Spliterator.ORDERED | Spliterator.NONNULL;

            Stream <int> stream = Iterables.Stream(iterable, characteristics);

            assertEquals(characteristics, stream.spliterator().characteristics());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void iterablesStreamClosesResourceIterator()
        internal virtual void IterablesStreamClosesResourceIterator()
        {
            IList <object> list = new IList <object> {
                "a", "b", "c", "def"
            };

            Resource resource = mock(typeof(Resource));
            ResourceIterable <object> iterable = () => Iterators.ResourceIterator(list.GetEnumerator(), resource);

            using (Stream <object> stream = Iterables.Stream(iterable))
            {
                assertEquals(list, stream.collect(toList()));
            }
            verify(resource).close();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void iterablesStreamForNull()
        internal virtual void IterablesStreamForNull()
        {
            assertThrows(typeof(System.NullReferenceException), () => Iterables.Stream(null));
        }