/** * Gets the combined the error message of this and any nested errors. * * @return the error message * @since 2.1 */ public String getMessage() { if (super.getMessage() != null) { return super.getMessage(); } else if (cause != null) { return cause.toString(); } else { return null; } }
@Test public void testMarkNotSupported() throws Exception { final Reader reader = new TestNullReader(100, false, true); assertFalse("Mark Should NOT be Supported", reader.markSupported()); try { reader.mark(5); fail("mark() should throw UnsupportedOperationException"); } catch (final UnsupportedOperationException e) { assertEquals("mark() error message", "Mark not supported", e.getMessage()); } try { reader.reset(); fail("reset() should throw UnsupportedOperationException"); } catch (final UnsupportedOperationException e) { assertEquals("reset() error message", "Mark not supported", e.getMessage()); } reader.close(); }
@Test public void testMarkNotSupported() throws Exception { final InputStream input = new TestNullInputStream(100, false, true); assertFalse("Mark Should NOT be Supported", input.markSupported()); try { input.mark(5); fail("mark() should throw UnsupportedOperationException"); } catch (final UnsupportedOperationException e) { assertEquals("mark() error message", "Mark not supported", e.getMessage()); } try { input.reset(); fail("reset() should throw UnsupportedOperationException"); } catch (final UnsupportedOperationException e) { assertEquals("reset() error message", "Mark not supported", e.getMessage()); } input.close(); }
@Test public void shouldNotAllowSettingOfConfigAttributes() throws Exception { KillAllChildProcessTask processTask = new KillAllChildProcessTask(); try { processTask.setConfigAttributes(new HashMap()); fail("should have failed, as configuration of kill-all task is not allowed"); } catch (UnsupportedOperationException e) { assertThat(e.getMessage(), is("Not a configurable task")); } }
@Test public void shouldNotAllowSettingOfConfigAttributes() throws Exception { Task task = new NullTask(); try { task.setConfigAttributes(new HashMap()); fail("should have failed, as configuration of kill-all task is not allowed"); } catch (UnsupportedOperationException e) { assertThat(e.getMessage(), is("Not a configurable task")); } }
@Test public void testMemoryFutureCancellation() { setUpCountStarFromOrdersWithJoin(); ListenableFuture future = userPool.reserve(fakeQueryId, "test", TEN_MEGABYTES.toBytes()); assertTrue(!future.isDone()); try { future.cancel(true); fail("cancel should fail"); } catch (UnsupportedOperationException e) { assertEquals(e.getMessage(), "cancellation is not supported"); } userPool.free(fakeQueryId, "test", TEN_MEGABYTES.toBytes()); assertTrue(future.isDone()); }
@Test void markAsStaleIsUnsupported() { UnsupportedOperationException uoe = assertThrows( UnsupportedOperationException.class, () -> indexReference.setStale() ); assertEquals( uoe.getMessage(), "Read only indexes can't be marked as stale." ); }
@Test void obtainingWriterIsUnsupported() { UnsupportedOperationException uoe = assertThrows( UnsupportedOperationException.class, () -> indexReference.getWriter() ); assertEquals( uoe.getMessage(), "Read only indexes do not have index writers." ); }
@Test public void testIterate() { try (AxisIterator ignored = attributeNode.iterateAxis(AxisInfo.SELF)) { fail("Exception is excepted"); } catch (UnsupportedOperationException ex) { assertEquals( "Invalid exception message", "Operation is not supported", ex.getMessage()); } }
@Test public void testIsIdref() { try { rootNode.isIdref(); fail("Exception is excepted"); } catch (UnsupportedOperationException ex) { assertEquals( "Invalid exception message", "Operation is not supported", ex.getMessage()); } }
@Test public void testAtomize() { try { rootNode.atomize(); fail("Exception is excepted"); } catch (UnsupportedOperationException ex) { assertEquals( "Invalid exception message", "Operation is not supported", ex.getMessage()); } }
@Test public void testGetAttributeValue() { try { attributeNode.getAttributeValue("", ""); fail("Exception is excepted"); } catch (UnsupportedOperationException ex) { assertEquals( "Invalid exception message", "Operation is not supported", ex.getMessage()); } }
@Test public void testGetColumnNumber() { try { attributeNode.getColumnNumber(); fail("Exception is excepted"); } catch (UnsupportedOperationException ex) { assertEquals( "Invalid exception message", "Operation is not supported", ex.getMessage()); } }
@Test public void testGetTokenType() { try { attributeNode.getTokenType(); fail("Exception is excepted"); } catch (UnsupportedOperationException ex) { assertEquals( "Invalid exception message", "Operation is not supported", ex.getMessage()); } }
@Test public void testGetObjectTypeWithNoTargetOrTargetSource() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS)); ITestBean tb = (ITestBean) bf.getBean("noTarget"); try { tb.getName(); fail(); } catch (UnsupportedOperationException ex) { assertEquals("getName", ex.getMessage()); } FactoryBean<?> pfb = (ProxyFactoryBean) bf.getBean("&noTarget"); assertTrue("Has correct object type", ITestBean.class.isAssignableFrom(pfb.getObjectType())); }
@Test void defaultQueryImplementationMustThrowForUnsupportedIndexOrder() { // Given IndexReader indexReader = stubIndexReader(); // Then String expectedMessage = String.format( "This reader only have support for index order %s. Provided index order was %s.", IndexOrder.NONE, IndexOrder.ASCENDING ); UnsupportedOperationException operationException = assertThrows( UnsupportedOperationException.class, () -> indexReader.query( new SimpleNodeValueClient(), IndexOrder.ASCENDING, false, IndexQuery.exists( 1 ) ) ); assertEquals( expectedMessage, operationException.getMessage() ); }
@Test public void testQueryElementNotImplementedAxis() throws Exception { final String xpath = "/CLASS_DEF//following-sibling::METHOD_DEF"; final RootNode rootNode = getRootNode("InputXpathMapperAst.java"); try { getXpathItems(xpath, rootNode); fail("Exception is excepted"); } catch (UnsupportedOperationException ex) { assertEquals("Invalid number of nodes", "Operation is not supported", ex.getMessage()); } }
@Test public void testQueryRootNotImplementedAxis() throws Exception { final String xpath = "//following-sibling::METHOD_DEF"; final RootNode rootNode = getRootNode("InputXpathMapperAst.java"); try { getXpathItems(xpath, rootNode); fail("Exception is excepted"); } catch (UnsupportedOperationException ex) { assertEquals("Invalid number of nodes", "Operation is not supported", ex.getMessage()); } }
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") @Test public void cacheExceptionRewriteCallStack() { final String keyItem = name.getMethodName(); UnsupportedOperationException first = null; long ref = service.exceptionInvocations(); try { service.cacheWithException(keyItem, true); fail("Should have thrown an exception"); } catch (UnsupportedOperationException e) { first = e; } // Sanity check, this particular call has called the service assertEquals("First call should not have been cached", ref + 1, service.exceptionInvocations()); UnsupportedOperationException second = methodInCallStack(keyItem); // Sanity check, this particular call has *not* called the service assertEquals("Second call should have been cached", ref + 1, service.exceptionInvocations()); assertEquals(first.getCause(), second.getCause()); assertEquals(first.getMessage(), second.getMessage()); assertFalse("Original stack must not contain any reference to methodInCallStack", contain(first, AbstractJCacheAnnotationTests.class.getName(), "methodInCallStack")); assertTrue("Cached stack should have been rewritten with a reference to methodInCallStack", contain(second, AbstractJCacheAnnotationTests.class.getName(), "methodInCallStack")); }
@Test public void throwExceptionWhenNotArrayValueForString() { buffer.setIntsToRead(COUNT_VALUE, OFFSET_VALUE, VALUE_ARRAY_INSTANCE_ID); buffer.setStringsToRead("abcdef"); addStringClassToSnapshotWithFields(snapshot, new Field[]{ new Field(Type.INT, "count"), new Field(Type.INT, "offset"), new Field(Type.OBJECT, "value") }); ClassInstance stringInstance = createStringInstance(); createObjectValueInstance(); try { HahaHelper.asString(stringInstance); fail("this test should have thrown UnsupportedOperationException"); } catch (UnsupportedOperationException uoe) { String message = uoe.getMessage(); assertTrue(message.equals("Could not find char array in " + stringInstance)); } }