Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static void verifyFusionCloseThrowIfAllThrow(AutoCloseable fusionCloseable, AutoCloseable... autoCloseables) throws Exception
        internal static void VerifyFusionCloseThrowIfAllThrow(AutoCloseable fusionCloseable, params AutoCloseable[] autoCloseables)
        {
            // given
            UncheckedIOException[] failures = new UncheckedIOException[autoCloseables.Length];
            for (int i = 0; i < autoCloseables.Length; i++)
            {
                failures[i] = new UncheckedIOException(new IOException("unknown"));
                doThrow(failures[i]).when(autoCloseables[i]).close();
            }

            try
            {
                // when
                fusionCloseable.close();
                fail("Should have failed");
            }
            catch (UncheckedIOException e)
            {
                // then
//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the Java 'super' constraint:
//ORIGINAL LINE: java.util.List<org.hamcrest.Matcher<? super java.io.UncheckedIOException>> matchers = new java.util.ArrayList<>();
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
                IList <Matcher> matchers = new List <Matcher>();
                foreach (UncheckedIOException failure in failures)
                {
                    matchers.Add(sameInstance(failure));
                }
                assertThat(e, anyOf(matchers));
            }
        }
Пример #2
0
 public override void UnregisterCloseableResource(AutoCloseable closeable)
 {
     if (_closeableResources != null)
     {
         _closeableResources.remove(closeable);
     }
 }
Пример #3
0
        // ResourceTracker

        public override void RegisterCloseableResource(AutoCloseable closeable)
        {
            if (_closeableResources == null)
            {
                _closeableResources = new List <AutoCloseable>(8);
            }
            _closeableResources.Add(closeable);
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCleanupAutoCloseable() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCleanupAutoCloseable()
        {
            // GIVEN
            CleanupRule   rule    = new CleanupRule();
            AutoCloseable toClose = rule.Add(mock(typeof(AutoCloseable)));

            // WHEN
            SimulateTestExecution(rule);

            // THEN
            verify(toClose).close();
        }
Пример #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void closeMustIgnoreNullResources() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CloseMustIgnoreNullResources()
        {
            AutoCloseable a = () =>
            {
            };
            AutoCloseable b = null;
            AutoCloseable c = () =>
            {
            };

//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
            IOUtils.Close(IOException::new, a, b, c);
        }
Пример #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static void verifyFusionCloseThrowOnSingleCloseThrow(AutoCloseable failingCloseable, AutoCloseable fusionCloseable) throws Exception
        internal static void VerifyFusionCloseThrowOnSingleCloseThrow(AutoCloseable failingCloseable, AutoCloseable fusionCloseable)
        {
            UncheckedIOException expectedFailure = new UncheckedIOException(new IOException("fail"));

            doThrow(expectedFailure).when(failingCloseable).close();
            try
            {
                fusionCloseable.close();
                fail("Should have failed");
            }
            catch (UncheckedIOException e)
            {
                assertSame(expectedFailure, e);
            }
        }
Пример #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCleanupMultipleObjectsInReverseAddedOrder() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCleanupMultipleObjectsInReverseAddedOrder()
        {
            // GIVEN
            CleanupRule   rule      = new CleanupRule();
            AutoCloseable closeable = rule.Add(mock(typeof(AutoCloseable)));
            Dirt          dirt      = rule.Add(mock(typeof(Dirt)));

            // WHEN
            SimulateTestExecution(rule);

            // THEN
            InOrder inOrder = inOrder(dirt, closeable);

            inOrder.verify(dirt, times(1)).shutdown();
            inOrder.verify(closeable, times(1)).close();
        }
Пример #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: java.util.List<long> assertInOrder(org.neo4j.internal.kernel.api.IndexOrder order, org.neo4j.internal.kernel.api.IndexQuery... predicates) throws Exception
        internal virtual IList <long> AssertInOrder(IndexOrder order, params IndexQuery[] predicates)
        {
            IList <long> actualIds;

            if (order == IndexOrder.NONE)
            {
                actualIds = Query(predicates);
            }
            else
            {
                SimpleNodeValueClient client = new SimpleNodeValueClient();
                using (AutoCloseable ignore = Query(client, order, predicates))
                {
                    actualIds = AssertClientReturnValuesInOrder(client, order);
                }
            }
            return(actualIds);
        }
Пример #9
0
 /// <summary>
 /// If the given obj is AutoCloseable, then close it.
 /// Any exceptions thrown from the close method will be wrapped in RuntimeExceptions.
 /// These RuntimeExceptions can get the given suppressedException attached to them, if any.
 /// If the given suppressedException argument is null, then it will not be added to the
 /// thrown RuntimeException.
 /// </summary>
 internal static void CloseSafely(object obj, Exception suppressedException)
 {
     if (obj is AutoCloseable)
     {
         AutoCloseable closeable = ( AutoCloseable )obj;
         try
         {
             closeable.close();
         }
         catch (Exception cause)
         {
             Exception exception = new Exception(cause);
             if (suppressedException != null)
             {
                 exception.addSuppressed(suppressedException);
             }
             throw exception;
         }
     }
 }
Пример #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static void verifyOtherIsClosedOnSingleThrow(AutoCloseable failingCloseable, AutoCloseable fusionCloseable, AutoCloseable... successfulCloseables) throws Exception
        internal static void VerifyOtherIsClosedOnSingleThrow(AutoCloseable failingCloseable, AutoCloseable fusionCloseable, params AutoCloseable[] successfulCloseables)
        {
            UncheckedIOException failure = new UncheckedIOException(new IOException("fail"));

            doThrow(failure).when(failingCloseable).close();

            // when
            try
            {
                fusionCloseable.close();
                fail("Should have failed");
            }
            catch (UncheckedIOException)
            {
            }

            // then
            foreach (AutoCloseable successfulCloseable in successfulCloseables)
            {
                verify(successfulCloseable, Mockito.times(1)).close();
            }
        }
Пример #11
0
 public override void UnregisterCloseableResource(AutoCloseable closeable)
 {
 }
Пример #12
0
 internal Closer(AutoCloseable closeable)
 {
     this.Closeable = closeable;
 }