|
| 1 | +/* |
| 2 | + * Copyright (c) 2020 Markus KARG |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Eclipse Public License v. 2.0, which is available at |
| 6 | + * http://www.eclipse.org/legal/epl-2.0. |
| 7 | + * |
| 8 | + * This Source Code may also be made available under the following Secondary |
| 9 | + * Licenses when the conditions for such availability set forth in the |
| 10 | + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, |
| 11 | + * version 2 with the GNU Classpath Exception, which is available at |
| 12 | + * https://www.gnu.org/software/classpath/license.html. |
| 13 | + * |
| 14 | + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 |
| 15 | + */ |
| 16 | + |
| 17 | +package org.glassfish.jersey.jsonb.internal; |
| 18 | + |
| 19 | +import static javax.ws.rs.core.MediaType.APPLICATION_JSON_PATCH_JSON_TYPE; |
| 20 | + |
| 21 | +import java.io.ByteArrayInputStream; |
| 22 | +import java.io.IOException; |
| 23 | +import java.lang.annotation.Annotation; |
| 24 | +import java.util.Collection; |
| 25 | +import java.util.Collections; |
| 26 | +import java.util.List; |
| 27 | +import java.util.Map; |
| 28 | +import java.util.Set; |
| 29 | + |
| 30 | +import javax.ws.rs.core.MultivaluedMap; |
| 31 | +import javax.ws.rs.core.NoContentException; |
| 32 | +import javax.ws.rs.ext.MessageBodyReader; |
| 33 | + |
| 34 | +import org.junit.Test; |
| 35 | + |
| 36 | +/** |
| 37 | + * Unit Test for {@link JsonBindingProvider}. |
| 38 | + * |
| 39 | + * @author Markus KARG (markus@headcrashing.eu) |
| 40 | + */ |
| 41 | +public final class JsonBindingProviderTest { |
| 42 | + |
| 43 | + @Test(expected = NoContentException.class) |
| 44 | + public final void shouldThrowNoContentException() throws IOException { |
| 45 | + // given |
| 46 | + final MessageBodyReader<Foo> mbr = new JsonBindingProvider<>(); |
| 47 | + |
| 48 | + // when |
| 49 | + mbr.readFrom(Foo.class, Foo.class, new Annotation[0], APPLICATION_JSON_PATCH_JSON_TYPE, |
| 50 | + new EmptyMultivaluedMap<String, String>(), new ByteArrayInputStream(new byte[0])); |
| 51 | + |
| 52 | + // then |
| 53 | + // should throw NoContentException |
| 54 | + } |
| 55 | + |
| 56 | + private static final class Foo { |
| 57 | + // no members |
| 58 | + } |
| 59 | + |
| 60 | + private static final class EmptyMultivaluedMap<K, V> implements MultivaluedMap<K, V> { |
| 61 | + |
| 62 | + @Override |
| 63 | + public final int size() { |
| 64 | + return 0; |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public final boolean isEmpty() { |
| 69 | + return true; |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public final boolean containsKey(final Object key) { |
| 74 | + return false; |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public final boolean containsValue(final Object value) { |
| 79 | + return false; |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public final List<V> get(final Object key) { |
| 84 | + return null; |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public final List<V> put(final K key, final List<V> value) { |
| 89 | + return null; |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public final List<V> remove(final Object key) { |
| 94 | + return null; |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public final void putAll(final Map<? extends K, ? extends List<V>> m) { |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + public final void clear() { |
| 103 | + } |
| 104 | + |
| 105 | + @Override |
| 106 | + public final Set<K> keySet() { |
| 107 | + return Collections.emptySet(); |
| 108 | + } |
| 109 | + |
| 110 | + @Override |
| 111 | + public final Collection<List<V>> values() { |
| 112 | + return Collections.emptySet(); |
| 113 | + } |
| 114 | + |
| 115 | + @Override |
| 116 | + public final Set<Entry<K, List<V>>> entrySet() { |
| 117 | + return Collections.emptySet(); |
| 118 | + } |
| 119 | + |
| 120 | + @Override |
| 121 | + public final void putSingle(final K key, final V value) { |
| 122 | + } |
| 123 | + |
| 124 | + @Override |
| 125 | + public final void add(final K key, final V value) { |
| 126 | + } |
| 127 | + |
| 128 | + @Override |
| 129 | + public final V getFirst(final K key) { |
| 130 | + return null; |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public final void addAll(final K key, final V... newValues) { |
| 135 | + } |
| 136 | + |
| 137 | + @Override |
| 138 | + public final void addAll(final K key, final List<V> valueList) { |
| 139 | + } |
| 140 | + |
| 141 | + @Override |
| 142 | + public final void addFirst(final K key, final V value) { |
| 143 | + } |
| 144 | + |
| 145 | + @Override |
| 146 | + public final boolean equalsIgnoreValueOrder(final MultivaluedMap<K, V> otherMap) { |
| 147 | + return false; |
| 148 | + } |
| 149 | + |
| 150 | + } |
| 151 | + |
| 152 | +} |
0 commit comments