Dependency { public Dependency setExclusions( Collection<Exclusion> exclusions ) { if ( hasEquivalentExclusions( exclusions ) ) { return this; } return new Dependency( artifact, scope, optional, exclusions ); } Dependency( Artifact artifact, String scope );  Dependency( Artifact artifact, String scope, boolean optional );  Dependency( Artifact artifact, String scope, boolean optional, Collection<Exclusion> exclusions ); private  Dependency( Artifact artifact, String scope, Set<Exclusion> exclusions, boolean optional ); Artifact getArtifact(); Dependency setArtifact( Artifact artifact ); String getScope(); Dependency setScope( String scope ); boolean isOptional(); Dependency setOptional( boolean optional ); Collection<Exclusion> getExclusions(); Dependency setExclusions( Collection<Exclusion> exclusions ); @Override String toString(); @Override boolean equals( Object obj ); @Override int hashCode();  }
@Test public void testSetExclusions() { Dependency d1 = new Dependency( new StubArtifact( "gid:aid:ver" ), "compile", false, Collections.singleton( new Exclusion( "g", "a", "c", "e" ) ) ); Dependency d2 = d1.setExclusions( null ); assertNotSame( d2, d1 ); assertEquals( 0, d2.getExclusions().size() ); assertSame( d2, d2.setExclusions( null ) ); assertSame( d2, d2.setExclusions( Collections.<Exclusion> emptyList() ) ); assertSame( d2, d2.setExclusions( Collections.<Exclusion> emptySet() ) ); assertSame( d1, d1.setExclusions( Arrays.asList( new Exclusion( "g", "a", "c", "e" ) ) ) ); Dependency d3 = d1.setExclusions( Arrays.asList( new Exclusion( "g", "a", "c", "e" ), new Exclusion( "g", "a", "c", "f" ) ) ); assertNotSame( d3, d1 ); assertEquals( 2, d3.getExclusions().size() ); }