List of usage examples for java.util EmptyStackException EmptyStackException
public EmptyStackException()
From source file:ArrayStack.java
/** * Pops the top item off of this stack and return it. * * @return the top item on the stack// w w w . j ava 2 s .c o m * @throws EmptyStackException if the stack is empty */ public Object pop() throws EmptyStackException { int n = size(); if (n <= 0) { throw new EmptyStackException(); } else { return remove(n - 1); } }
From source file:de.micromata.genome.gwiki.page.gspt.StandAlonePageContext.java
@Override public JspWriter popBody() { if (topOfWriterStack == null) { throw new EmptyStackException(); }/*w w w . j a va 2 s. c o m*/ JspWriter parent = topOfWriterStack.getEnclosingWriter(); if (parent instanceof BodyContent) { topOfWriterStack = (BodyContent) parent; } return parent; }
From source file:de.micromata.genome.gwiki.page.gspt.ServletStandalonePageContext.java
@Override public JspWriter popBody() { if (topOfWriterStack == null) { throw new EmptyStackException(); }/*from w ww. jav a 2 s. c o m*/ JspWriter parent = topOfWriterStack.getEnclosingWriter(); if (parent instanceof BodyContent) { topOfWriterStack = (BodyContent) parent; } else { topOfWriterStack = null; } return parent; }
From source file:org.auraframework.integration.test.service.ServerServiceImplTest.java
/** * Verifies first exception within handleServletException is caught and processed * we throw 'EmptyStackException' when getting InstanceStack, then verify * exceptionAdapter.handleException(death) is called with it *///from ww w. j ava 2 s . co m @Test public void testHandleExceptionDeathCaught() throws Exception { PrintWriter writer = mock(PrintWriter.class); HttpServletRequest mockRequest = mock(HttpServletRequest.class); HttpServletResponse mockResponse = mock(HttpServletResponse.class); ContextService mockContextService = mock(ContextService.class); AuraContext mockContext = mock(AuraContext.class); ConfigAdapter mockConfigAdapter = mock(ConfigAdapter.class); ExceptionAdapter mockExceptionAdapter = mock(ExceptionAdapter.class); Throwable firstException = new EmptyStackException(); Mockito.when(mockResponse.getWriter()).thenReturn(writer); Mockito.when(mockContext.getFormat()).thenReturn(AuraContext.Format.JSON); Mockito.when(mockContext.getMode()).thenReturn(Mode.PROD); Mockito.when(mockConfigAdapter.isProduction()).thenReturn(true); Mockito.when(mockContextService.getCurrentContext()).thenReturn(mockContext); Mockito.when(mockContext.getInstanceStack()).thenThrow(firstException); Throwable exception = new InterruptedException("opps"); ServletUtilAdapterImpl adapter = new ServletUtilAdapterImpl(); adapter.setContextService(mockContextService); adapter.setConfigAdapter(mockConfigAdapter); adapter.setExceptionAdapter(mockExceptionAdapter); adapter.handleServletException(exception, true, mockContext, mockRequest, mockResponse, true); ArgumentCaptor<Throwable> handledException = ArgumentCaptor.forClass(Throwable.class); Mockito.verify(mockExceptionAdapter, Mockito.times(1)).handleException(handledException.capture()); assertTrue("Should handle EmptyStackException", handledException.getValue() instanceof EmptyStackException); Mockito.verify(mockResponse, atLeastOnce()).setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); Mockito.verify(mockContextService, atLeastOnce()).endContext(); }
From source file:org.auraframework.integration.test.service.ServerServiceImplTest.java
/** * Verifies second exception within handleServletException is caught and processed * we throw 'EmptyStackException' when getting InstanceStack, when * exceptionAdapter.handleException(death) handle the exception, * we throw second exception, then verify we printout the error message to response's writer *//*from w ww. jav a 2 s . c om*/ @Test public void testHandleExceptionDoubleDeathCaught() throws Exception { PrintWriter writer = mock(PrintWriter.class); HttpServletRequest mockRequest = mock(HttpServletRequest.class); HttpServletResponse mockResponse = mock(HttpServletResponse.class); ContextService mockContextService = mock(ContextService.class); AuraContext mockContext = mock(AuraContext.class); ConfigAdapter mockConfigAdapter = mock(ConfigAdapter.class); ExceptionAdapter mockExceptionAdapter = mock(ExceptionAdapter.class); Throwable firstException = new EmptyStackException(); String ccmeMsg = "double dead"; Throwable secondException = new ConcurrentModificationException("double dead"); Mockito.when(mockResponse.getWriter()).thenReturn(writer); Mockito.when(mockContext.getFormat()).thenReturn(AuraContext.Format.HTML); Mockito.when(mockContext.getMode()).thenReturn(Mode.DEV); Mockito.when(mockConfigAdapter.isProduction()).thenReturn(false); Mockito.when(mockContextService.getCurrentContext()).thenReturn(mockContext); Mockito.when(mockContext.getInstanceStack()).thenThrow(firstException); Mockito.when(mockExceptionAdapter.handleException(firstException)).thenThrow(secondException); Throwable exception = new InterruptedException("opps"); ServletUtilAdapterImpl adapter = new ServletUtilAdapterImpl(); adapter.setContextService(mockContextService); adapter.setConfigAdapter(mockConfigAdapter); adapter.setExceptionAdapter(mockExceptionAdapter); adapter.handleServletException(exception, true, mockContext, mockRequest, mockResponse, true); ArgumentCaptor<String> exceptionMessage = ArgumentCaptor.forClass(String.class); Mockito.verify(writer, Mockito.times(1)).println(exceptionMessage.capture()); assertEquals(ccmeMsg, exceptionMessage.getValue()); Mockito.verify(mockResponse, atLeastOnce()).setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); Mockito.verify(mockContextService, atLeastOnce()).endContext(); }
From source file:org.auraframework.impl.adapter.ServletUtilAdapterImplUnitTest.java
/** * Verifies first exception within handleServletException is caught and processed * we throw 'EmptyStackException' when getting InstanceStack, then verify * exceptionAdapter.handleException(death) is called with it *///from w w w . j a v a 2 s . co m @Test public void testHandleExceptionDeathCaught() throws Exception { PrintWriter writer = Mockito.mock(PrintWriter.class); HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); HttpServletResponse mockResponse = Mockito.mock(HttpServletResponse.class); ContextService mockContextService = Mockito.mock(ContextService.class); AuraContext mockContext = Mockito.mock(AuraContext.class); ConfigAdapter mockConfigAdapter = Mockito.mock(ConfigAdapter.class); ExceptionAdapter mockExceptionAdapter = Mockito.mock(ExceptionAdapter.class); Throwable firstException = new EmptyStackException(); Mockito.when(mockResponse.getWriter()).thenReturn(writer); Mockito.when(mockResponse.getStatus()).thenReturn(HttpStatus.SC_OK); Mockito.when(mockContext.getFormat()).thenReturn(AuraContext.Format.JSON); Mockito.when(mockContext.getMode()).thenReturn(Mode.PROD); Mockito.when(mockConfigAdapter.isProduction()).thenReturn(true); Mockito.when(mockContextService.getCurrentContext()).thenReturn(mockContext); Mockito.when(mockContext.getInstanceStack()).thenThrow(firstException); Throwable exception = new InterruptedException("opps"); ServletUtilAdapterImpl adapter = Mockito.spy(new ServletUtilAdapterImpl()); adapter.setContextService(mockContextService); adapter.setConfigAdapter(mockConfigAdapter); adapter.setExceptionAdapter(mockExceptionAdapter); adapter.handleServletException(exception, true, mockContext, mockRequest, mockResponse, true); ArgumentCaptor<Throwable> handledException = ArgumentCaptor.forClass(Throwable.class); Mockito.verify(mockExceptionAdapter, Mockito.times(2)).handleException(handledException.capture()); assertTrue("Should handle EmptyStackException", handledException.getAllValues().get(1) instanceof EmptyStackException); Mockito.verify(mockResponse, Mockito.atLeastOnce()).setStatus(HttpStatus.SC_OK); Mockito.verify(mockContextService, Mockito.atLeastOnce()).endContext(); Mockito.verify(adapter, Mockito.times(1)).setNoCache(mockResponse); }
From source file:org.auraframework.impl.adapter.ServletUtilAdapterImplUnitTest.java
/** * Verifies second exception within handleServletException is caught and processed * we throw 'EmptyStackException' when getting InstanceStack, when * exceptionAdapter.handleException(death) handle the exception, * we throw second exception, then verify we printout the error message to response's writer *//*from w w w .j a v a2s.c om*/ @Test public void testHandleExceptionDoubleDeathCaught() throws Exception { PrintWriter writer = Mockito.mock(PrintWriter.class); HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); HttpServletResponse mockResponse = Mockito.mock(HttpServletResponse.class); ContextService mockContextService = Mockito.mock(ContextService.class); AuraContext mockContext = Mockito.mock(AuraContext.class); ConfigAdapter mockConfigAdapter = Mockito.mock(ConfigAdapter.class); ExceptionAdapter mockExceptionAdapter = Mockito.mock(ExceptionAdapter.class); Throwable firstException = new EmptyStackException(); String ccmeMsg = "double dead"; Throwable secondException = new ConcurrentModificationException("double dead"); Mockito.when(mockResponse.getWriter()).thenReturn(writer); Mockito.when(mockResponse.getStatus()).thenReturn(HttpStatus.SC_OK); Mockito.when(mockContext.getFormat()).thenReturn(AuraContext.Format.HTML); Mockito.when(mockContext.getMode()).thenReturn(Mode.DEV); Mockito.when(mockConfigAdapter.isProduction()).thenReturn(false); Mockito.when(mockContextService.getCurrentContext()).thenReturn(mockContext); Mockito.when(mockContext.getInstanceStack()).thenThrow(firstException); Mockito.when(mockExceptionAdapter.handleException(firstException)).thenThrow(secondException); Throwable exception = new InterruptedException("opps"); ServletUtilAdapterImpl adapter = Mockito.spy(new ServletUtilAdapterImpl()); adapter.setContextService(mockContextService); adapter.setConfigAdapter(mockConfigAdapter); adapter.setExceptionAdapter(mockExceptionAdapter); adapter.handleServletException(exception, true, mockContext, mockRequest, mockResponse, true); ArgumentCaptor<String> exceptionMessage = ArgumentCaptor.forClass(String.class); Mockito.verify(writer, Mockito.times(1)).println(exceptionMessage.capture()); assertEquals(ccmeMsg, exceptionMessage.getValue()); // in this case we return SC_OK, and we set non-cacheable. Mockito.verify(mockResponse, Mockito.atLeastOnce()).setStatus(HttpStatus.SC_OK); Mockito.verify(mockContextService, Mockito.atLeastOnce()).endContext(); Mockito.verify(adapter, Mockito.atLeastOnce()).setNoCache(mockResponse); }
From source file:org.apache.tomcat.util.digester.Digester.java
/** * <p>Pops (gets and removes) the top object from the stack with the given name.</p> * * <p><strong>Note:</strong> a stack is considered empty * if no objects have been pushed onto it yet.</p> * //from w ww .j a v a 2s . com * @param stackName the name of the stack from which the top value is to be popped * @return the top <code>Object</code> on the stack or or null if the stack is either * empty or has not been created yet * @throws EmptyStackException if the named stack is empty * * @since 1.6 */ public Object pop(String stackName) { Object result = null; ArrayStack namedStack = (ArrayStack) stacksByName.get(stackName); if (namedStack == null) { if (log.isDebugEnabled()) { log.debug("Stack '" + stackName + "' is empty"); } throw new EmptyStackException(); } else { result = namedStack.pop(); } return result; }
From source file:org.apache.tomcat.util.digester.Digester.java
/** * <p>Gets the top object from the stack with the given name. * This method does not remove the object from the stack. * </p>//from ww w . ja v a 2 s .c o m * <p><strong>Note:</strong> a stack is considered empty * if no objects have been pushed onto it yet.</p> * * @param stackName the name of the stack to be peeked * @return the top <code>Object</code> on the stack or null if the stack is either * empty or has not been created yet * @throws EmptyStackException if the named stack is empty * * @since 1.6 */ public Object peek(String stackName) { Object result = null; ArrayStack namedStack = (ArrayStack) stacksByName.get(stackName); if (namedStack == null) { if (log.isDebugEnabled()) { log.debug("Stack '" + stackName + "' is empty"); } throw new EmptyStackException(); } else { result = namedStack.peek(); } return result; }
From source file:org.polymap.core.runtime.MapBlockingQueue.java
public T remove() { T result = poll(); if (result == null) { throw new EmptyStackException(); } return result; }