Skip to content

Commit

Permalink
Add MediaTypes for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 28, 2024
1 parent c23e445 commit e3db7f0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fasterxml.jackson.jaxrs.xml;

import java.lang.annotation.Annotation;
import java.util.*;

import javax.ws.rs.core.MediaType;
Expand Down Expand Up @@ -34,15 +35,20 @@ public void testDefaultUntouchables() throws Exception
{
JacksonXMLProvider prov = new JacksonXMLProvider();
// By default, no reason to exclude, say, this test class...
assertTrue(prov.isReadable(getClass(), getClass(), null, null));
assertTrue(prov.isWriteable(getClass(), getClass(), null, null));
assertTrue(prov.isReadable(getClass(), getClass(),
new Annotation[0], MediaType.APPLICATION_XML_TYPE));
assertTrue(prov.isWriteable(getClass(), getClass(),
new Annotation[0], MediaType.APPLICATION_XML_TYPE));

// but some types should be ignored (set of ignorable may change over time tho!)
assertFalse(prov.isWriteable(StreamingOutput.class, StreamingOutput.class, null, null));
assertFalse(prov.isWriteable(StreamingOutput.class, StreamingOutput.class,
new Annotation[0], MediaType.APPLICATION_XML_TYPE));

// and then on-the-fence things (see [Issue-1])
assertFalse(prov.isReadable(String.class, getClass(), null, null));
assertFalse(prov.isReadable(byte[].class, getClass(), null, null));
assertFalse(prov.isReadable(String.class, getClass(),
new Annotation[0], MediaType.APPLICATION_XML_TYPE));
assertFalse(prov.isReadable(byte[].class, getClass(),
new Annotation[0], MediaType.APPLICATION_XML_TYPE));
}

public void testCustomUntouchables() throws Exception
Expand All @@ -51,13 +57,17 @@ public void testCustomUntouchables() throws Exception
// can mark this as ignorable...
prov.addUntouchable(getClass());
// and then it shouldn't be processable
assertFalse(prov.isReadable(getClass(), getClass(), null, null));
assertFalse(prov.isWriteable(getClass(), getClass(), null, null));
assertFalse(prov.isReadable(getClass(), getClass(),
new Annotation[0], MediaType.APPLICATION_XML_TYPE));
assertFalse(prov.isWriteable(getClass(), getClass(),
new Annotation[0], MediaType.APPLICATION_XML_TYPE));

// Same for interfaces, like:
prov.addUntouchable(Collection.class);
assertFalse(prov.isReadable(ArrayList.class, ArrayList.class, null, null));
assertFalse(prov.isWriteable(HashSet.class, HashSet.class, null, null));
assertFalse(prov.isReadable(ArrayList.class, ArrayList.class,
new Annotation[0], MediaType.APPLICATION_XML_TYPE));
assertFalse(prov.isWriteable(HashSet.class, HashSet.class,
new Annotation[0], MediaType.APPLICATION_XML_TYPE));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.StreamingOutput;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
Expand All @@ -19,7 +21,7 @@ public class TestUntouchables
* remains overridable.
*/
public static class MyJacksonProvider extends JacksonYAMLProvider {
// ensure isJsonType remains "protected" this is a compile-time check.
// ensure isJsonType remains "protected" this is a compile-time check.
// Some users of JacksonJsonProvider override this method;
// changing to "private" would regress them.
@Override
Expand All @@ -36,15 +38,20 @@ public void testDefaultUntouchables() throws Exception
{
JacksonYAMLProvider prov = new JacksonYAMLProvider();
// By default, no reason to exclude, say, this test class...
assertTrue(prov.isReadable(getClass(), getClass(), null, null));
assertTrue(prov.isWriteable(getClass(), getClass(), null, null));
assertTrue(prov.isReadable(getClass(), getClass(),
new Annotation[0], null));
assertTrue(prov.isWriteable(getClass(), getClass(),
new Annotation[0], null));

// but some types should be ignored (set of ignorable may change over time tho!)
assertFalse(prov.isWriteable(StreamingOutput.class, StreamingOutput.class, null, null));
assertFalse(prov.isWriteable(StreamingOutput.class, StreamingOutput.class,
new Annotation[0], null));

// and then on-the-fence things (see [Issue-1])
assertFalse(prov.isReadable(String.class, getClass(), null, null));
assertFalse(prov.isReadable(byte[].class, getClass(), null, null));
assertFalse(prov.isReadable(String.class, getClass(),
new Annotation[0], null));
assertFalse(prov.isReadable(byte[].class, getClass(),
new Annotation[0], null));
}

public void testCustomUntouchables() throws Exception
Expand All @@ -53,13 +60,16 @@ public void testCustomUntouchables() throws Exception
// can mark this as ignorable...
prov.addUntouchable(getClass());
// and then it shouldn't be processable
assertFalse(prov.isReadable(getClass(), getClass(), null, null));
assertFalse(prov.isWriteable(getClass(), getClass(), null, null));
assertFalse(prov.isReadable(getClass(), getClass(),
new Annotation[0], null));
assertFalse(prov.isWriteable(getClass(), getClass(),
new Annotation[0], null));

// Same for interfaces, like:
prov.addUntouchable(Collection.class);
assertFalse(prov.isReadable(ArrayList.class, ArrayList.class, null, null));
assertFalse(prov.isWriteable(HashSet.class, HashSet.class, null, null));
assertFalse(prov.isReadable(ArrayList.class, ArrayList.class,
new Annotation[0], null));
assertFalse(prov.isWriteable(HashSet.class, HashSet.class,
new Annotation[0], null));
}
}

0 comments on commit e3db7f0

Please sign in to comment.