/** * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. * * <p>The created matcher assumes no relationship between specified type and the examined object.</p> * For example: * <pre>assertThat(new Canoe(), instanceOf(Paddlable.class));</pre> * */ @SuppressWarnings("unchecked") public static <T> Matcher<T> instanceOf(Class<?> type) { return (Matcher<T>) new IsInstanceOf(type); }
/** * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. * * <p>The created matcher forces a relationship between specified type and the examined object, and should be * used when it is necessary to make generics conform, for example in the JMock clause * <code>with(any(Thing.class))</code></p> * For example: * <pre>assertThat(new Canoe(), instanceOf(Canoe.class));</pre> * */ @SuppressWarnings("unchecked") public static <T> Matcher<T> any(Class<T> type) { return (Matcher<T>) new IsInstanceOf(type); }
/** * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. * * <p>The created matcher assumes no relationship between specified type and the examined object.</p> * <p/> * For example: * <pre>assertThat(new Canoe(), instanceOf(Paddlable.class));</pre> * */ @SuppressWarnings("unchecked") @Factory public static <T> Matcher<T> instanceOf(Class<?> type) { return (Matcher<T>) new IsInstanceOf(type); }
/** * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. * * <p>The created matcher assumes no relationship between specified type and the examined object.</p> * <p/> * For example: * <pre>assertThat(new Canoe(), instanceOf(Paddlable.class));</pre> * */ @SuppressWarnings("unchecked") @Factory public static <T> Matcher<T> instanceOf(Class<?> type) { return (Matcher<T>) new IsInstanceOf(type); }
/** * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. * * <p>The created matcher forces a relationship between specified type and the examined object, and should be * used when it is necessary to make generics conform, for example in the JMock clause * <code>with(any(Thing.class))</code></p> * <p/> * For example: * <pre>assertThat(new Canoe(), instanceOf(Canoe.class));</pre> * */ @SuppressWarnings("unchecked") @Factory public static <T> Matcher<T> any(Class<T> type) { return (Matcher<T>) new IsInstanceOf(type); }
/** * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. * * <p>The created matcher forces a relationship between specified type and the examined object, and should be * used when it is necessary to make generics conform, for example in the JMock clause * <code>with(any(Thing.class))</code></p> * <p/> * For example: * <pre>assertThat(new Canoe(), instanceOf(Canoe.class));</pre> * */ @SuppressWarnings("unchecked") @Factory public static <T> Matcher<T> any(Class<T> type) { return (Matcher<T>) new IsInstanceOf(type); }
@Test public void testTake() { Assert.assertThat(resourceHolderObj, new IsInstanceOf(ResourceHolder.class)); Object expectedObject = resourceHolderObj.get(); Assert.assertEquals(expectedObject, defaultString); }
/** * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. * * <p>The created matcher assumes no relationship between specified type and the examined object.</p> * For example: * <pre>assertThat(new Canoe(), instanceOf(Paddlable.class));</pre> * */ @SuppressWarnings("unchecked") public static <T> Matcher<T> instanceOf(Class<?> type) { return (Matcher<T>) new IsInstanceOf(type); }
/** * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. * * <p>The created matcher forces a relationship between specified type and the examined object, and should be * used when it is necessary to make generics conform, for example in the JMock clause * <code>with(any(Thing.class))</code></p> * For example: * <pre>assertThat(new Canoe(), instanceOf(Canoe.class));</pre> * */ @SuppressWarnings("unchecked") public static <T> Matcher<T> any(Class<T> type) { return (Matcher<T>) new IsInstanceOf(type); }
/** * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. * * <p>The created matcher assumes no relationship between specified type and the examined object.</p> * <p/> * For example: * <pre>assertThat(new Canoe(), instanceOf(Paddlable.class));</pre> * */ @SuppressWarnings("unchecked") @Factory public static <T> Matcher<T> instanceOf(Class<?> type) { return (Matcher<T>) new IsInstanceOf(type); }
/** * Creates a matcher that matches when the examined object is an instance of the specified <code>type</code>, * as determined by calling the {@link java.lang.Class#isInstance(Object)} method on that type, passing the * the examined object. * * <p>The created matcher forces a relationship between specified type and the examined object, and should be * used when it is necessary to make generics conform, for example in the JMock clause * <code>with(any(Thing.class))</code></p> * <p/> * For example: * <pre>assertThat(new Canoe(), instanceOf(Canoe.class));</pre> * */ @SuppressWarnings("unchecked") @Factory public static <T> Matcher<T> any(Class<T> type) { return (Matcher<T>) new IsInstanceOf(type); }
protected IsInstanceOf matcher() { if (matcher == null) { matcher = new IsInstanceOf(clazz); } return matcher; }
/** * @deprecated * use {@link #aNonNull} or {@link #any} until type inference actually works in a future version of Java * @param type Class to match. Do not use for native parameters. * @return an IsInstanceOf matcher */ @Deprecated public static Matcher<Object> a(Class<?> type) { return new IsInstanceOf(type); }
/** * Is the value an instance of a particular type? */ @Factory public static Matcher<Object> instanceOf(Class<?> type) { return new IsInstanceOf(type); }
/** * Is the value an instance of a particular type? */ @Factory public static Matcher<Object> instanceOf(Class<?> type) { return new IsInstanceOf(type); }
assertThat(tree, new IsInstanceOf(IIOMetadataNode.class));
assertThat(tree, new IsInstanceOf(IIOMetadataNode.class));
@Test public void testComponentIdOutOfRange() throws IOException { // Image has SOF and SOS component ids that are negative, setFromTree chokes on this... JPEGImageReader reader = createReader(); try { reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/jfif-component-id-out-of-range.jpg"))); IIOMetadata metadata = reader.getImageMetadata(0); assertNotNull(metadata); Node tree = metadata.getAsTree(metadata.getNativeMetadataFormatName()); assertNotNull(tree); assertThat(tree, new IsInstanceOf(IIOMetadataNode.class)); } finally { reader.dispose(); } }
@Test public void testInvalidDHTIssue() throws IOException { // Image has empty (!) DHT that is okay on read, but not when you set back from tree... JPEGImageReader reader = createReader(); try { reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/jfif-progressive-invalid-dht.jpg"))); IIOMetadata metadata = reader.getImageMetadata(0); assertNotNull(metadata); Node tree = metadata.getAsTree(metadata.getNativeMetadataFormatName()); assertNotNull(tree); assertThat(tree, new IsInstanceOf(IIOMetadataNode.class)); } finally { reader.dispose(); } }
assertThat(tree, new IsInstanceOf(IIOMetadataNode.class)); assertThat(knownIssue.getCause(), new IsInstanceOf(NegativeArraySizeException.class));