Search in sources :

Example 1 with MemoryManager

use of au.gov.asd.tac.constellation.utilities.memory.MemoryManager in project constellation by constellation-app.

the class VisualManagerNGTest method testExportToBufferedImage.

/**
 * Test of exportToBufferedImage method, of class VisualManager.
 */
@Test
public void testExportToBufferedImage() {
    System.out.println("exportToBufferedImage");
    try (final MockedStatic<MemoryManager> memoryManagerMockedStatic = mockStatic(MemoryManager.class)) {
        memoryManagerMockedStatic.when(() -> MemoryManager.newObject(Mockito.eq(VisualManager.class))).thenAnswer((Answer<Void>) invocation -> null);
        memoryManagerMockedStatic.when(() -> MemoryManager.finalizeObject(Mockito.eq(VisualManager.class))).thenAnswer((Answer<Void>) invocation -> null);
        final VisualAccess access = mock(VisualAccess.class);
        final BufferedImage[] imageFile = new BufferedImage[555];
        final Semaphore waiter = mock(Semaphore.class);
        final VisualOperation op = mock(VisualOperation.class);
        final VisualProcessor processor = mock(VisualProcessor.class);
        when(processor.exportToBufferedImage(Mockito.eq(imageFile), Mockito.eq(waiter))).thenReturn(op);
        final VisualManager instance = new VisualManager(access, processor);
        final PriorityBlockingQueue<VisualOperation> queueBefore = instance.getOperations();
        final int size = queueBefore.size();
        final boolean containsOP = queueBefore.contains(op);
        instance.exportToBufferedImage(imageFile, waiter);
        final PriorityBlockingQueue<VisualOperation> queueAfter = instance.getOperations();
        assertEquals(queueAfter.size(), size + 1);
        assertFalse(containsOP);
        assertTrue(queueAfter.contains(op));
        verify(processor, times(1)).exportToBufferedImage(Mockito.eq(imageFile), Mockito.eq(waiter));
    }
}
Also used : Mockito.mockStatic(org.mockito.Mockito.mockStatic) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.testng.annotations.Test) Mockito.spy(org.mockito.Mockito.spy) AfterMethod(org.testng.annotations.AfterMethod) ArrayList(java.util.ArrayList) PriorityBlockingQueue(java.util.concurrent.PriorityBlockingQueue) Answer(org.mockito.stubbing.Answer) Assert(org.testng.Assert) ExecutorService(java.util.concurrent.ExecutorService) AfterClass(org.testng.annotations.AfterClass) MemoryManager(au.gov.asd.tac.constellation.utilities.memory.MemoryManager) BufferedImage(java.awt.image.BufferedImage) Semaphore(java.util.concurrent.Semaphore) Collection(java.util.Collection) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) Mockito.times(org.mockito.Mockito.times) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) Component(java.awt.Component) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) List(java.util.List) MockedStatic(org.mockito.MockedStatic) Mockito.mock(org.mockito.Mockito.mock) Semaphore(java.util.concurrent.Semaphore) MemoryManager(au.gov.asd.tac.constellation.utilities.memory.MemoryManager) BufferedImage(java.awt.image.BufferedImage) Test(org.testng.annotations.Test)

Example 2 with MemoryManager

use of au.gov.asd.tac.constellation.utilities.memory.MemoryManager in project constellation by constellation-app.

the class VisualManagerNGTest method testExportToImage.

/**
 * Test of exportToImage method, of class VisualManager.
 */
@Test
public void testExportToImage() {
    System.out.println("exportToImage");
    try (final MockedStatic<MemoryManager> memoryManagerMockedStatic = mockStatic(MemoryManager.class)) {
        memoryManagerMockedStatic.when(() -> MemoryManager.newObject(Mockito.eq(VisualManager.class))).thenAnswer((Answer<Void>) invocation -> null);
        memoryManagerMockedStatic.when(() -> MemoryManager.finalizeObject(Mockito.eq(VisualManager.class))).thenAnswer((Answer<Void>) invocation -> null);
        final VisualAccess access = mock(VisualAccess.class);
        final File imageFile = mock(File.class);
        final VisualOperation op = mock(VisualOperation.class);
        final VisualProcessor processor = mock(VisualProcessor.class);
        when(processor.exportToImage(Mockito.eq(imageFile))).thenReturn(op);
        final VisualManager instance = new VisualManager(access, processor);
        final PriorityBlockingQueue<VisualOperation> queueBefore = instance.getOperations();
        final int size = queueBefore.size();
        final boolean containsOP = queueBefore.contains(op);
        instance.exportToImage(imageFile);
        final PriorityBlockingQueue<VisualOperation> queueAfter = instance.getOperations();
        assertEquals(queueAfter.size(), size + 1);
        assertFalse(containsOP);
        assertTrue(queueAfter.contains(op));
        verify(processor, times(1)).exportToImage(Mockito.eq(imageFile));
    }
}
Also used : Mockito.mockStatic(org.mockito.Mockito.mockStatic) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.testng.annotations.Test) Mockito.spy(org.mockito.Mockito.spy) AfterMethod(org.testng.annotations.AfterMethod) ArrayList(java.util.ArrayList) PriorityBlockingQueue(java.util.concurrent.PriorityBlockingQueue) Answer(org.mockito.stubbing.Answer) Assert(org.testng.Assert) ExecutorService(java.util.concurrent.ExecutorService) AfterClass(org.testng.annotations.AfterClass) MemoryManager(au.gov.asd.tac.constellation.utilities.memory.MemoryManager) BufferedImage(java.awt.image.BufferedImage) Semaphore(java.util.concurrent.Semaphore) Collection(java.util.Collection) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) Mockito.times(org.mockito.Mockito.times) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) Component(java.awt.Component) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) List(java.util.List) MockedStatic(org.mockito.MockedStatic) Mockito.mock(org.mockito.Mockito.mock) MemoryManager(au.gov.asd.tac.constellation.utilities.memory.MemoryManager) File(java.io.File) Test(org.testng.annotations.Test)

Example 3 with MemoryManager

use of au.gov.asd.tac.constellation.utilities.memory.MemoryManager in project constellation by constellation-app.

the class VisualManagerNGTest method testGetVisualComponent.

/**
 * Test of getVisualComponent method, of class VisualManager.
 */
@Test
public void testGetVisualComponent() {
    System.out.println("getVisualComponent");
    try (final MockedStatic<MemoryManager> memoryManagerMockedStatic = mockStatic(MemoryManager.class)) {
        memoryManagerMockedStatic.when(() -> MemoryManager.newObject(Mockito.eq(VisualManager.class))).thenAnswer((Answer<Void>) invocation -> null);
        final VisualProcessor processor = mock(VisualProcessor.class);
        final Component canvas = mock(Component.class);
        when(processor.getCanvas()).thenReturn(canvas);
        final VisualAccess access = mock(VisualAccess.class);
        final VisualManager instance = new VisualManager(access, processor);
        final Component result = instance.getVisualComponent();
        assertEquals(result, canvas);
        verify(processor, times(1)).getCanvas();
    }
}
Also used : Mockito.mockStatic(org.mockito.Mockito.mockStatic) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.testng.annotations.Test) Mockito.spy(org.mockito.Mockito.spy) AfterMethod(org.testng.annotations.AfterMethod) ArrayList(java.util.ArrayList) PriorityBlockingQueue(java.util.concurrent.PriorityBlockingQueue) Answer(org.mockito.stubbing.Answer) Assert(org.testng.Assert) ExecutorService(java.util.concurrent.ExecutorService) AfterClass(org.testng.annotations.AfterClass) MemoryManager(au.gov.asd.tac.constellation.utilities.memory.MemoryManager) BufferedImage(java.awt.image.BufferedImage) Semaphore(java.util.concurrent.Semaphore) Collection(java.util.Collection) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) Mockito.times(org.mockito.Mockito.times) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) Component(java.awt.Component) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) List(java.util.List) MockedStatic(org.mockito.MockedStatic) Mockito.mock(org.mockito.Mockito.mock) MemoryManager(au.gov.asd.tac.constellation.utilities.memory.MemoryManager) Component(java.awt.Component) Test(org.testng.annotations.Test)

Aggregations

MemoryManager (au.gov.asd.tac.constellation.utilities.memory.MemoryManager)3 Component (java.awt.Component)3 BufferedImage (java.awt.image.BufferedImage)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ExecutorService (java.util.concurrent.ExecutorService)3 PriorityBlockingQueue (java.util.concurrent.PriorityBlockingQueue)3 Semaphore (java.util.concurrent.Semaphore)3 MockedStatic (org.mockito.MockedStatic)3 Mockito (org.mockito.Mockito)3 Mockito.doNothing (org.mockito.Mockito.doNothing)3 Mockito.mock (org.mockito.Mockito.mock)3 Mockito.mockStatic (org.mockito.Mockito.mockStatic)3 Mockito.spy (org.mockito.Mockito.spy)3 Mockito.times (org.mockito.Mockito.times)3 Mockito.verify (org.mockito.Mockito.verify)3 Mockito.when (org.mockito.Mockito.when)3