Search in sources :

Example 1 with PrinterDiscoverySessionCallbacks

use of android.print.mockservice.PrinterDiscoverySessionCallbacks in project platform_frameworks_base by android.

the class BasePrintTest method createMockPrinterDiscoverySessionCallbacks.

@SuppressWarnings("unchecked")
protected PrinterDiscoverySessionCallbacks createMockPrinterDiscoverySessionCallbacks(Answer<Void> onStartPrinterDiscovery, Answer<Void> onStopPrinterDiscovery, Answer<Void> onValidatePrinters, Answer<Void> onStartPrinterStateTracking, Answer<Void> onRequestCustomPrinterIcon, Answer<Void> onStopPrinterStateTracking, Answer<Void> onDestroy) {
    PrinterDiscoverySessionCallbacks callbacks = mock(PrinterDiscoverySessionCallbacks.class);
    doCallRealMethod().when(callbacks).setSession(any(StubbablePrinterDiscoverySession.class));
    when(callbacks.getSession()).thenCallRealMethod();
    if (onStartPrinterDiscovery != null) {
        doAnswer(onStartPrinterDiscovery).when(callbacks).onStartPrinterDiscovery(any(List.class));
    }
    if (onStopPrinterDiscovery != null) {
        doAnswer(onStopPrinterDiscovery).when(callbacks).onStopPrinterDiscovery();
    }
    if (onValidatePrinters != null) {
        doAnswer(onValidatePrinters).when(callbacks).onValidatePrinters(any(List.class));
    }
    if (onStartPrinterStateTracking != null) {
        doAnswer(onStartPrinterStateTracking).when(callbacks).onStartPrinterStateTracking(any(PrinterId.class));
    }
    if (onRequestCustomPrinterIcon != null) {
        doAnswer(onRequestCustomPrinterIcon).when(callbacks).onRequestCustomPrinterIcon(any(PrinterId.class), any(CancellationSignal.class), any(CustomPrinterIconCallback.class));
    }
    if (onStopPrinterStateTracking != null) {
        doAnswer(onStopPrinterStateTracking).when(callbacks).onStopPrinterStateTracking(any(PrinterId.class));
    }
    if (onDestroy != null) {
        doAnswer(onDestroy).when(callbacks).onDestroy();
    }
    return callbacks;
}
Also used : LocaleList(android.os.LocaleList) ArrayList(java.util.ArrayList) List(java.util.List) PrinterId(android.print.PrinterId) CancellationSignal(android.os.CancellationSignal) StubbablePrinterDiscoverySession(android.print.mockservice.StubbablePrinterDiscoverySession) CustomPrinterIconCallback(android.printservice.CustomPrinterIconCallback) PrinterDiscoverySessionCallbacks(android.print.mockservice.PrinterDiscoverySessionCallbacks)

Example 2 with PrinterDiscoverySessionCallbacks

use of android.print.mockservice.PrinterDiscoverySessionCallbacks in project platform_frameworks_base by android.

the class IPrintManagerParametersTest method createMockCallbacks.

/**
     * Create mock print service callbacks.
     *
     * @return the callbacks
     */
private PrintServiceCallbacks createMockCallbacks() {
    return createMockPrintServiceCallbacks(new Answer<PrinterDiscoverySessionCallbacks>() {

        @Override
        public PrinterDiscoverySessionCallbacks answer(InvocationOnMock invocation) {
            return createMockPrinterDiscoverySessionCallbacks(new Answer<Void>() {

                @Override
                public Void answer(InvocationOnMock invocation) {
                    // Get the session.
                    StubbablePrinterDiscoverySession session = ((PrinterDiscoverySessionCallbacks) invocation.getMock()).getSession();
                    if (session.getPrinters().isEmpty()) {
                        final String PRINTER_NAME = "good printer";
                        List<PrinterInfo> printers = new ArrayList<>();
                        // Add the printer.
                        mGoodPrinterId = session.getService().generatePrinterId(PRINTER_NAME);
                        PrinterCapabilitiesInfo capabilities = new PrinterCapabilitiesInfo.Builder(mGoodPrinterId).setMinMargins(new Margins(200, 200, 200, 200)).addMediaSize(MediaSize.ISO_A4, true).addResolution(new Resolution("300x300", "300x300", 300, 300), true).setColorModes(PrintAttributes.COLOR_MODE_COLOR, PrintAttributes.COLOR_MODE_COLOR).build();
                        PrinterInfo printer = new PrinterInfo.Builder(mGoodPrinterId, PRINTER_NAME, PrinterInfo.STATUS_IDLE).setCapabilities(capabilities).build();
                        printers.add(printer);
                        session.addPrinters(printers);
                    }
                    onPrinterDiscoverySessionStartCalled();
                    return null;
                }
            }, null, null, null, null, null, null);
        }
    }, null, null);
}
Also used : ArrayList(java.util.ArrayList) PrinterDiscoverySessionCallbacks(android.print.mockservice.PrinterDiscoverySessionCallbacks) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Margins(android.print.PrintAttributes.Margins) StubbablePrinterDiscoverySession(android.print.mockservice.StubbablePrinterDiscoverySession) Resolution(android.print.PrintAttributes.Resolution)

Example 3 with PrinterDiscoverySessionCallbacks

use of android.print.mockservice.PrinterDiscoverySessionCallbacks in project android_frameworks_base by DirtyUnicorns.

the class IPrintManagerParametersTest method createMockCallbacks.

/**
     * Create mock print service callbacks.
     *
     * @return the callbacks
     */
private PrintServiceCallbacks createMockCallbacks() {
    return createMockPrintServiceCallbacks(new Answer<PrinterDiscoverySessionCallbacks>() {

        @Override
        public PrinterDiscoverySessionCallbacks answer(InvocationOnMock invocation) {
            return createMockPrinterDiscoverySessionCallbacks(new Answer<Void>() {

                @Override
                public Void answer(InvocationOnMock invocation) {
                    // Get the session.
                    StubbablePrinterDiscoverySession session = ((PrinterDiscoverySessionCallbacks) invocation.getMock()).getSession();
                    if (session.getPrinters().isEmpty()) {
                        final String PRINTER_NAME = "good printer";
                        List<PrinterInfo> printers = new ArrayList<>();
                        // Add the printer.
                        mGoodPrinterId = session.getService().generatePrinterId(PRINTER_NAME);
                        PrinterCapabilitiesInfo capabilities = new PrinterCapabilitiesInfo.Builder(mGoodPrinterId).setMinMargins(new Margins(200, 200, 200, 200)).addMediaSize(MediaSize.ISO_A4, true).addResolution(new Resolution("300x300", "300x300", 300, 300), true).setColorModes(PrintAttributes.COLOR_MODE_COLOR, PrintAttributes.COLOR_MODE_COLOR).build();
                        PrinterInfo printer = new PrinterInfo.Builder(mGoodPrinterId, PRINTER_NAME, PrinterInfo.STATUS_IDLE).setCapabilities(capabilities).build();
                        printers.add(printer);
                        session.addPrinters(printers);
                    }
                    onPrinterDiscoverySessionStartCalled();
                    return null;
                }
            }, null, null, null, null, null, null);
        }
    }, null, null);
}
Also used : ArrayList(java.util.ArrayList) PrinterDiscoverySessionCallbacks(android.print.mockservice.PrinterDiscoverySessionCallbacks) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Margins(android.print.PrintAttributes.Margins) StubbablePrinterDiscoverySession(android.print.mockservice.StubbablePrinterDiscoverySession) Resolution(android.print.PrintAttributes.Resolution)

Example 4 with PrinterDiscoverySessionCallbacks

use of android.print.mockservice.PrinterDiscoverySessionCallbacks in project android_frameworks_base by ResurrectionRemix.

the class BasePrintTest method createMockPrinterDiscoverySessionCallbacks.

@SuppressWarnings("unchecked")
protected PrinterDiscoverySessionCallbacks createMockPrinterDiscoverySessionCallbacks(Answer<Void> onStartPrinterDiscovery, Answer<Void> onStopPrinterDiscovery, Answer<Void> onValidatePrinters, Answer<Void> onStartPrinterStateTracking, Answer<Void> onRequestCustomPrinterIcon, Answer<Void> onStopPrinterStateTracking, Answer<Void> onDestroy) {
    PrinterDiscoverySessionCallbacks callbacks = mock(PrinterDiscoverySessionCallbacks.class);
    doCallRealMethod().when(callbacks).setSession(any(StubbablePrinterDiscoverySession.class));
    when(callbacks.getSession()).thenCallRealMethod();
    if (onStartPrinterDiscovery != null) {
        doAnswer(onStartPrinterDiscovery).when(callbacks).onStartPrinterDiscovery(any(List.class));
    }
    if (onStopPrinterDiscovery != null) {
        doAnswer(onStopPrinterDiscovery).when(callbacks).onStopPrinterDiscovery();
    }
    if (onValidatePrinters != null) {
        doAnswer(onValidatePrinters).when(callbacks).onValidatePrinters(any(List.class));
    }
    if (onStartPrinterStateTracking != null) {
        doAnswer(onStartPrinterStateTracking).when(callbacks).onStartPrinterStateTracking(any(PrinterId.class));
    }
    if (onRequestCustomPrinterIcon != null) {
        doAnswer(onRequestCustomPrinterIcon).when(callbacks).onRequestCustomPrinterIcon(any(PrinterId.class), any(CancellationSignal.class), any(CustomPrinterIconCallback.class));
    }
    if (onStopPrinterStateTracking != null) {
        doAnswer(onStopPrinterStateTracking).when(callbacks).onStopPrinterStateTracking(any(PrinterId.class));
    }
    if (onDestroy != null) {
        doAnswer(onDestroy).when(callbacks).onDestroy();
    }
    return callbacks;
}
Also used : LocaleList(android.os.LocaleList) ArrayList(java.util.ArrayList) List(java.util.List) PrinterId(android.print.PrinterId) CancellationSignal(android.os.CancellationSignal) StubbablePrinterDiscoverySession(android.print.mockservice.StubbablePrinterDiscoverySession) CustomPrinterIconCallback(android.printservice.CustomPrinterIconCallback) PrinterDiscoverySessionCallbacks(android.print.mockservice.PrinterDiscoverySessionCallbacks)

Example 5 with PrinterDiscoverySessionCallbacks

use of android.print.mockservice.PrinterDiscoverySessionCallbacks in project android_frameworks_base by ResurrectionRemix.

the class IPrintManagerParametersTest method createMockCallbacks.

/**
     * Create mock print service callbacks.
     *
     * @return the callbacks
     */
private PrintServiceCallbacks createMockCallbacks() {
    return createMockPrintServiceCallbacks(new Answer<PrinterDiscoverySessionCallbacks>() {

        @Override
        public PrinterDiscoverySessionCallbacks answer(InvocationOnMock invocation) {
            return createMockPrinterDiscoverySessionCallbacks(new Answer<Void>() {

                @Override
                public Void answer(InvocationOnMock invocation) {
                    // Get the session.
                    StubbablePrinterDiscoverySession session = ((PrinterDiscoverySessionCallbacks) invocation.getMock()).getSession();
                    if (session.getPrinters().isEmpty()) {
                        final String PRINTER_NAME = "good printer";
                        List<PrinterInfo> printers = new ArrayList<>();
                        // Add the printer.
                        mGoodPrinterId = session.getService().generatePrinterId(PRINTER_NAME);
                        PrinterCapabilitiesInfo capabilities = new PrinterCapabilitiesInfo.Builder(mGoodPrinterId).setMinMargins(new Margins(200, 200, 200, 200)).addMediaSize(MediaSize.ISO_A4, true).addResolution(new Resolution("300x300", "300x300", 300, 300), true).setColorModes(PrintAttributes.COLOR_MODE_COLOR, PrintAttributes.COLOR_MODE_COLOR).build();
                        PrinterInfo printer = new PrinterInfo.Builder(mGoodPrinterId, PRINTER_NAME, PrinterInfo.STATUS_IDLE).setCapabilities(capabilities).build();
                        printers.add(printer);
                        session.addPrinters(printers);
                    }
                    onPrinterDiscoverySessionStartCalled();
                    return null;
                }
            }, null, null, null, null, null, null);
        }
    }, null, null);
}
Also used : ArrayList(java.util.ArrayList) PrinterDiscoverySessionCallbacks(android.print.mockservice.PrinterDiscoverySessionCallbacks) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Margins(android.print.PrintAttributes.Margins) StubbablePrinterDiscoverySession(android.print.mockservice.StubbablePrinterDiscoverySession) Resolution(android.print.PrintAttributes.Resolution)

Aggregations

PrinterDiscoverySessionCallbacks (android.print.mockservice.PrinterDiscoverySessionCallbacks)10 StubbablePrinterDiscoverySession (android.print.mockservice.StubbablePrinterDiscoverySession)10 ArrayList (java.util.ArrayList)10 CancellationSignal (android.os.CancellationSignal)5 LocaleList (android.os.LocaleList)5 Margins (android.print.PrintAttributes.Margins)5 Resolution (android.print.PrintAttributes.Resolution)5 PrinterId (android.print.PrinterId)5 CustomPrinterIconCallback (android.printservice.CustomPrinterIconCallback)5 List (java.util.List)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 Answer (org.mockito.stubbing.Answer)5