@Test public void usingUnsupportedBuildAreaWithLiftDistance() throws Exception { AbstractPrintFileProcessor processor = createNewPrintFileProcessor(); Graphics2D graphics = Mockito.mock(Graphics2D.class); PrintJob printJob = createTestPrintJob(processor); Mockito.when( printJob.getPrinter().getConfiguration().getSlicingProfile().getZLiftDistanceGCode()) .thenReturn("G99 ${1 + UnknownVariable * 2} ;dependent on buildArea"); Double whenBuilAreaMMCalled = printJob.getPrintFileProcessor().getBuildAreaMM(Mockito.any(PrintJob.class)); Mockito.when(whenBuilAreaMMCalled).thenReturn(null); DataAid aid = processor.initializeJobCacheWithDataAid(printJob); try { aid.customizer.setNextStep(PrinterStep.PerformExposure); processor.printImageAndPerformPostProcessing(aid, image); Assert.fail("Must throw InappropriateDeviceException"); } catch (InappropriateDeviceException e) { Mockito.verify(printJob.getPrintFileProcessor(), Mockito.times(2)) .getBuildAreaMM(Mockito.any(PrintJob.class)); } Mockito.when( printJob.getPrinter().getConfiguration().getSlicingProfile().getZLiftDistanceGCode()) .thenReturn("G99 ${1 + buildAreaMM * 2} ;dependent on buildArea"); try { aid.customizer.setNextStep(PrinterStep.PerformExposure); processor.printImageAndPerformPostProcessing(aid, image); Mockito.verify(printJob.getPrintFileProcessor(), Mockito.times(5)) .getBuildAreaMM(Mockito.any(PrintJob.class)); } catch (InappropriateDeviceException e) { Assert.fail("Should not throw InappropriateDeviceException"); } }
@Test public void noNullPointerWhenWeReturnNull() throws Exception { AbstractPrintFileProcessor processor = createNewPrintFileProcessor(); PrintJob printJob = createTestPrintJob(processor); Mockito.when( printJob .getPrinter() .getConfiguration() .getSlicingProfile() .getzLiftDistanceCalculator()) .thenReturn(";"); Mockito.when(printJob.getPrintFileProcessor().getBuildAreaMM(Mockito.any(PrintJob.class))) .thenReturn(null); DataAid aid = processor.initializeJobCacheWithDataAid(printJob); try { aid.customizer.setNextStep(PrinterStep.PerformExposure); processor.printImageAndPerformPostProcessing(aid, image); Mockito.verify(printJob.getPrinter().getGCodeControl(), Mockito.times(1)) .executeGCodeWithTemplating(Mockito.any(PrintJob.class), Mockito.anyString()); } catch (IllegalArgumentException e) { Assert.assertEquals( "The result of your lift distance script needs to evaluate to an instance of java.lang.Number", e.getMessage()); } }
@Test public void unsupportedBuildAreaDoesntBreakLiftDistanceCalculator() throws Exception { AbstractPrintFileProcessor processor = createNewPrintFileProcessor(); PrintJob printJob = createTestPrintJob(processor); Mockito.when( printJob .getPrinter() .getConfiguration() .getSlicingProfile() .getzLiftDistanceCalculator()) .thenReturn("var mm = $buildAreaMM * 2;mm"); Mockito.when(printJob.getPrintFileProcessor().getBuildAreaMM(Mockito.any(PrintJob.class))) .thenReturn(null); DataAid aid = processor.initializeJobCacheWithDataAid(printJob); aid.customizer.setNextStep(PrinterStep.PerformExposure); processor.printImageAndPerformPostProcessing(aid, image); Mockito.verify(printJob.getPrinter().getGCodeControl(), Mockito.times(1)) .executeGCodeWithTemplating(Mockito.any(PrintJob.class), Mockito.anyString()); }
@Test public void unsupportedBuildAreaDoesntBreakProjectorGradient() throws InappropriateDeviceException, ScriptException, Exception { AbstractPrintFileProcessor processor = createNewPrintFileProcessor(); Graphics2D graphics = Mockito.mock(Graphics2D.class); PrintJob printJob = createTestPrintJob(processor); Mockito.when( printJob .getPrinter() .getConfiguration() .getSlicingProfile() .getProjectorGradientCalculator()) .thenReturn("var mm = $buildAreaMM * 2;java.awt.Color.ORANGE"); Mockito.when(printJob.getPrintFileProcessor().getBuildAreaMM(Mockito.any(PrintJob.class))) .thenReturn(null); DataAid aid = processor.initializeJobCacheWithDataAid(printJob); // apply image transform processor.applyBulbMask(aid, graphics, 0, 0); // processor.applyImageTransforms(aid, graphics, 0, 0); // processor.applyImageTransforms(aid, null, 0, 0); }
@Test public void properGCodeCreated() throws Exception { AbstractPrintFileProcessor processor = createNewPrintFileProcessor(); Graphics2D graphics = Mockito.mock(Graphics2D.class); PrintJob printJob = createTestPrintJob(processor); Mockito.when( printJob.getPrinter().getConfiguration().getSlicingProfile().getZLiftDistanceGCode()) .thenReturn("${1 + buildAreaMM * 2}"); Double whenBuilAreaMMCalled = printJob.getPrintFileProcessor().getBuildAreaMM(Mockito.any(PrintJob.class)); Mockito.when(whenBuilAreaMMCalled).thenReturn(new Double("5.0")); DataAid aid = processor.initializeJobCacheWithDataAid(printJob); Mockito.when(printJob.getPrinter().getGCodeControl().sendGcode(Mockito.anyString())) .then( new Answer<String>() { private int count = 0; @Override public String answer(InvocationOnMock invocation) throws Throwable { switch (count) { case 0: Assert.assertEquals("11", invocation.getArguments()[0]); break; case 1: Assert.assertEquals("Lift z", invocation.getArguments()[0]); break; } count++; return (String) invocation.getArguments()[0]; } }); aid.customizer.setNextStep(PrinterStep.PerformExposure); processor.printImageAndPerformPostProcessing(aid, image); // The two executes are for getZLiftDistanceGCode and the life gcode itself Mockito.verify(printJob.getPrinter().getGCodeControl(), Mockito.times(2)) .executeGCodeWithTemplating(Mockito.any(PrintJob.class), Mockito.anyString()); }
@Test public void EnsureMethodsThrowExceptionIfNotInitialized() throws Exception { AbstractPrintFileProcessor processor = Mockito.mock(AbstractPrintFileProcessor.class, Mockito.CALLS_REAL_METHODS); PrintJob printJob = createTestPrintJob(processor); DataAid aid = null; try { // applyimagetransform processor.applyBulbMask(aid, null, 0, 0); Assert.fail("Failed to throw IllegalStateException."); } catch (IllegalStateException e) { } try { // applyimagetransform processor.applyImageTransforms(aid, null); Assert.fail("Failed to throw IllegalStateException."); } catch (IllegalStateException e) { } try { processor.performFooter(aid); Assert.fail("Failed to throw IllegalStateException."); } catch (IllegalStateException e) { } try { processor.performHeader(aid); Assert.fail("Failed to throw IllegalStateException."); } catch (IllegalStateException e) { } try { processor.printImageAndPerformPostProcessing(aid, image); Assert.fail("Failed to throw IllegalStateException."); } catch (IllegalStateException e) { } try { processor.performPreSlice(aid, null); Assert.fail("Failed to throw IllegalStateException."); } catch (IllegalStateException e) { } }