### Question:
PortMapping extends Descriptor { public static Builder builder() { return new Builder().protocol(TCP); } PortMapping(@JsonProperty("ip") @Nullable final String ip,
                     @JsonProperty("internalPort") final int internalPort,
                     @JsonProperty("externalPort") @Nullable final Integer externalPort,
                     @JsonProperty("protocol") @Nullable final String protocol);  PortMapping(final int internalPort, final Integer externalPort);  PortMapping(final int internalPort); private  PortMapping(final Builder builder); @Nullable String getIp(); int getInternalPort(); boolean hasExternalPort(); @Nullable Integer getExternalPort(); String getProtocol(); PortMapping withExternalPort(final Integer externalPort); static PortMapping of(final int internalPort); static PortMapping of(final int internalPort, final Integer externalPort); static PortMapping of(final int internalPort, final Integer externalPort,
                               final String protocol); static PortMapping of(final int internalPort, final String protocol); static Builder builder(); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString(); static final String TCP; static final String UDP; }### Answer:
@Test public void testJsonDeserializationFromFull() throws Exception { final PortMapping pm = portMappingFromResource("portmapping-full.json"); assertThat(pm, equalTo(PortMapping.builder() .ip("1.2.3.4") .externalPort(123) .internalPort(456) .protocol(UDP) .build())); }
@Test public void testJsonDeserializationFromPartial() throws Exception { final PortMapping pm = portMappingFromResource("portmapping-partial.json"); assertThat(pm, equalTo(PortMapping.builder() .externalPort(123) .internalPort(456) .protocol(TCP) .build())); }
@Test public void testJsonDeserializationFromInternalPortOnly() throws Exception { final PortMapping pm = portMappingFromResource("portmapping-internal-port-only.json"); assertThat(pm, equalTo(PortMapping.builder() .internalPort(456) .protocol(TCP) .build())); }
@Test public void testJsonDeserializationUnknownFields() throws Exception { final PortMapping pm = portMappingFromResource("portmapping-unknown-fields.json"); assertThat(pm, equalTo(PortMapping.builder() .internalPort(456) .externalPort(123) .protocol(TCP) .build())); }
@Test public void testJsonSerialization() throws Exception { final PortMapping pm = PortMapping.builder() .ip("1.2.3.4") .internalPort(456) .externalPort(123) .protocol(UDP) .build(); final String json = toJson(pm); assertThat(json, equalTo(stringFromResource("portmapping-full.json"))); }
@Test public void testJsonSerializationWithDefaults() throws Exception { final PortMapping pm = PortMapping.builder() .internalPort(456) .externalPort(123) .build(); final String json = toJson(pm); assertThat(json, equalTo(stringFromResource("portmapping-defaults.json"))); }
@Test public void testJsonSerializationFromInternalPortOnly() throws Exception { final PortMapping pm = PortMapping.builder() .internalPort(456) .build(); final String json = toJson(pm); assertThat(json, equalTo(stringFromResource("portmapping-serialized-internal-port-only.json"))); }