PlaceRequest { public String getParameter(String key, String defaultValue) { return params.getOrDefault(key, defaultValue); } private  PlaceRequest(String nameToken, Map<String, String> params); String getNameToken(); String getParameter(String key, String defaultValue); Set<String> getParameterNames(); boolean matchesNameToken(PlaceRequest other); boolean matchesNameToken(String nameToken); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static Builder of(String nameToken);  }
@Test public void builderFromPlaceRequestShouldNotShareParams() { PlaceRequest request = new PlaceRequest.Builder() .nameToken("nameToken") .with("name1", "value1") .with("name2", "value2") .build(); PlaceRequest.Builder copyBuilder = new PlaceRequest.Builder(request); copyBuilder.with("name3", "value3").build(); assertNull(request.getParameter("name3", null)); }
@Test public void builderWithoutDoesRemoveParam() { PlaceRequest request = new PlaceRequest.Builder() .nameToken("nameToken") .with("name1", "value1") .with("name2", "value2") .build(); PlaceRequest.Builder copyBuilder = new PlaceRequest.Builder(request); PlaceRequest copy = copyBuilder.without("name2").build(); assertNull(copy.getParameter("name2", null)); }