diff --git a/media/json-binding/src/test/JsonBindingProviderTest.java b/media/json-binding/src/test/JsonBindingProviderTest.java new file mode 100644 index 00000000000..7f7df2d346f --- /dev/null +++ b/media/json-binding/src/test/JsonBindingProviderTest.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2020 Markus KARG + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.jsonb.internal; + +import static javax.ws.rs.core.MediaType.APPLICATION_JSON_PATCH_JSON_TYPE; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.NoContentException; +import javax.ws.rs.ext.MessageBodyReader; + +import org.junit.Test; + +/** + * Unit Test for {@link JsonBindingProvider}. + * + * @author Markus KARG (markus@headcrashing.eu) + */ +public final class JsonBindingProviderTest { + + @Test(expected = NoContentException.class) + public final void shouldThrowNoContentException() throws IOException { + // given + final MessageBodyReader mbr = new JsonBindingProvider<>(); + + // when + mbr.readFrom(Foo.class, Foo.class, new Annotation[0], APPLICATION_JSON_PATCH_JSON_TYPE, + new EmptyMultivaluedMap(), new ByteArrayInputStream(new byte[0])); + + // then + // should throw NoContentException + } + + private static final class Foo { + // no members + } + + private static final class EmptyMultivaluedMap implements MultivaluedMap { + + @Override + public final int size() { + return 0; + } + + @Override + public final boolean isEmpty() { + return true; + } + + @Override + public final boolean containsKey(final Object key) { + return false; + } + + @Override + public final boolean containsValue(final Object value) { + return false; + } + + @Override + public final List get(final Object key) { + return null; + } + + @Override + public final List put(final K key, final List value) { + return null; + } + + @Override + public final List remove(final Object key) { + return null; + } + + @Override + public final void putAll(final Map> m) { + } + + @Override + public final void clear() { + } + + @Override + public final Set keySet() { + return Collections.emptySet(); + } + + @Override + public final Collection> values() { + return Collections.emptySet(); + } + + @Override + public final Set>> entrySet() { + return Collections.emptySet(); + } + + @Override + public final void putSingle(final K key, final V value) { + } + + @Override + public final void add(final K key, final V value) { + } + + @Override + public final V getFirst(final K key) { + return null; + } + + @Override + public final void addAll(final K key, final V... newValues) { + } + + @Override + public final void addAll(final K key, final List valueList) { + } + + @Override + public final void addFirst(final K key, final V value) { + } + + @Override + public final boolean equalsIgnoreValueOrder(final MultivaluedMap otherMap) { + return false; + } + + } + +}