Proxy { public Proxy setType( String type ) { if ( this.type.equals( type ) || ( type == null && this.type.length() <= 0 ) ) { return this; } return new Proxy( type, host, port, auth ); } Proxy( String type, String host, int port, Authentication auth ); String getType(); Proxy setType( String type ); String getHost(); Proxy setHost( String host ); int getPort(); Proxy setPort( int port ); Authentication getAuthentication(); Proxy setAuthentication( Authentication auth ); @Override String toString(); @Override boolean equals( Object obj ); @Override int hashCode(); static final String TYPE_HTTP; static final String TYPE_HTTPS; }
@Test public void testSetType() { Proxy p1 = new Proxy( "type", "host", 80, null ); Proxy p2 = p1.setType( null ); assertNotSame( p2, p1 ); assertEquals( "", p2.getType() ); Proxy p3 = p1.setType( "TYPE" ); assertNotSame( p3, p1 ); assertEquals( "TYPE", p3.getType() ); }