|
| 1 | +/** |
| 2 | + * Copyright 2012-2018 The Feign Authors |
| 3 | + * |
| 4 | + * <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | + * except in compliance with the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * <p>http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * <p>Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 11 | + * express or implied. See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + */ |
| 14 | +package feign.querymap; |
| 15 | + |
| 16 | +import static org.junit.Assert.assertEquals; |
| 17 | +import static org.junit.Assert.assertTrue; |
| 18 | + |
| 19 | +import feign.QueryMapEncoder; |
| 20 | +import java.util.HashMap; |
| 21 | +import java.util.Map; |
| 22 | +import org.junit.Rule; |
| 23 | +import org.junit.Test; |
| 24 | +import org.junit.rules.ExpectedException; |
| 25 | + |
| 26 | +/** Test for {@link FieldQueryMapEncoder} */ |
| 27 | +public class FieldQueryMapEncoderTest { |
| 28 | + |
| 29 | + @Rule public final ExpectedException thrown = ExpectedException.none(); |
| 30 | + |
| 31 | + private final QueryMapEncoder encoder = new FieldQueryMapEncoder(); |
| 32 | + |
| 33 | + @Test |
| 34 | + public void testDefaultEncoder_normalClassWithValues() { |
| 35 | + final Map<String, Object> expected = new HashMap<>(); |
| 36 | + expected.put("foo", "fooz"); |
| 37 | + expected.put("bar", "barz"); |
| 38 | + final NormalObject normalObject = new NormalObject("fooz", "barz"); |
| 39 | + |
| 40 | + final Map<String, Object> encodedMap = encoder.encode(normalObject); |
| 41 | + |
| 42 | + assertEquals("Unexpected encoded query map", expected, encodedMap); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void testDefaultEncoder_normalClassWithOutValues() { |
| 47 | + final NormalObject normalObject = new NormalObject(null, null); |
| 48 | + |
| 49 | + final Map<String, Object> encodedMap = encoder.encode(normalObject); |
| 50 | + |
| 51 | + assertTrue("Non-empty map generated from null getter: " + encodedMap, encodedMap.isEmpty()); |
| 52 | + } |
| 53 | + |
| 54 | + class NormalObject { |
| 55 | + |
| 56 | + private NormalObject(String foo, String bar) { |
| 57 | + this.foo = foo; |
| 58 | + this.bar = bar; |
| 59 | + } |
| 60 | + |
| 61 | + private final String foo; |
| 62 | + private final String bar; |
| 63 | + } |
| 64 | +} |
0 commit comments