Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCatchArithmeticExceptionsAndTryNext()
        public virtual void ShouldCatchArithmeticExceptionsAndTryNext()
        {
            // GIVEN
            NumberArrayFactory  throwingMemoryFactory = mock(typeof(NumberArrayFactory));
            ArithmeticException failure = new ArithmeticException("This is an artificial failure");

            doThrow(failure).when(throwingMemoryFactory).newByteArray(anyLong(), any(typeof(sbyte[])), anyLong());
            FailureMonitor     monitor = new FailureMonitor();
            NumberArrayFactory factory = new NumberArrayFactory_Auto(monitor, throwingMemoryFactory, NumberArrayFactory.HEAP);
            int itemSize = 4;

            // WHEN
            ByteArray array = factory.NewByteArray(KILO, new sbyte[itemSize], 0);

            array.SetInt(KILO - 10, 0, 12345);

            // THEN
            verify(throwingMemoryFactory, times(1)).newByteArray(eq(KILO), any(typeof(sbyte[])), eq(0L));
            assertTrue(array is HeapByteArray);
            assertEquals(12345, array.GetInt(KILO - 10, 0));
            assertEquals(KILO * itemSize, monitor.Memory);
            assertEquals(NumberArrayFactory.HEAP, monitor.SuccessfulFactory);
            assertEquals(throwingMemoryFactory, single(monitor.AttemptedAllocationFailures).Factory);
            assertThat(single(monitor.AttemptedAllocationFailures).Failure.Message, containsString(failure.Message));
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPickFirstAvailableCandidateIntArray()
        public virtual void ShouldPickFirstAvailableCandidateIntArray()
        {
            // GIVEN
            FailureMonitor     monitor = new FailureMonitor();
            NumberArrayFactory factory = new NumberArrayFactory_Auto(monitor, NumberArrayFactory.HEAP);

            // WHEN
            IntArray array = factory.NewIntArray(KILO, -1);

            array.Set(KILO - 10, 12345);

            // THEN
            assertTrue(array is HeapIntArray);
            assertEquals(12345, array.Get(KILO - 10));
            assertEquals(NumberArrayFactory.HEAP, monitor.SuccessfulFactory);
            assertFalse(monitor.AttemptedAllocationFailures.GetEnumerator().hasNext());
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowOomOnNotEnoughMemory()
        public virtual void ShouldThrowOomOnNotEnoughMemory()
        {
            // GIVEN
            FailureMonitor     monitor          = new FailureMonitor();
            NumberArrayFactory lowMemoryFactory = mock(typeof(NumberArrayFactory));

            doThrow(typeof(System.OutOfMemoryException)).when(lowMemoryFactory).newLongArray(anyLong(), anyLong(), anyLong());
            NumberArrayFactory factory = new NumberArrayFactory_Auto(monitor, lowMemoryFactory);

            // WHEN
            try
            {
                factory.NewLongArray(KILO, -1);
                fail("Should have thrown");
            }
            catch (System.OutOfMemoryException)
            {
                // THEN OK
                assertFalse(monitor.Called);
            }
        }