@@ -143,12 +143,31 @@ void detectsContainedLinks() {
143143 assertThat (Links .of (first , second ).containsSameLinksAs (Links .of (first , second ))).isTrue ();
144144 }
145145
146- @ Test // #1322
147- void conditionallyAddsLink () {
146+ @ TestFactory // #1322, #1341
147+ Stream <DynamicTest > conditionallyAddsLink () {
148+
149+ Links links = Links .NONE ;
150+ Link link = Link .of ("/foo" );
148151
149- Links links = Links .NONE .andIf (true , () -> Link .of ("/foo" ));
152+ List <NamedLinks > adders = Arrays .asList (//
153+ NamedLinks .of ("adds via varargs" , links .andIf (true , link )), //
154+ NamedLinks .of ("adds via Supplier" , links .andIf (true , () -> link )), //
155+ NamedLinks .of ("adds via Stream" , links .andIf (true , Stream .of (link ))));
150156
151- assertThat (links .getRequiredLink (IanaLinkRelations .SELF ).getHref ()).isEqualTo ("/foo" );
157+ Stream <DynamicTest > adderTests = DynamicTest .stream (adders .iterator (), NamedLinks ::getName , it -> {
158+ assertThat (it .links .getRequiredLink (IanaLinkRelations .SELF ).getHref ()).isEqualTo ("/foo" );
159+ });
160+
161+ List <NamedLinks > nonAdders = Arrays .asList (//
162+ NamedLinks .of ("does not add via varargs" , links .andIf (false , link )), //
163+ NamedLinks .of ("does not add via Supplier" , links .andIf (false , () -> link )), //
164+ NamedLinks .of ("does not add via Stream" , links .andIf (false , Stream .of (link ))));
165+
166+ Stream <DynamicTest > nonAdderTests = DynamicTest .stream (nonAdders .iterator (), NamedLinks ::getName , it -> {
167+ assertThat (it .links ).isEmpty ();
168+ });
169+
170+ return Stream .concat (adderTests , nonAdderTests );
152171 }
153172
154173 @ Test // #1322
@@ -192,6 +211,52 @@ Stream<DynamicTest> mergesStreamOfLinks() {
192211 .element (0 ).extracting (Link ::getHref ).isEqualTo ("/foo" ));
193212 }
194213
214+ @ TestFactory // #1340
215+ Stream <DynamicTest > replacesLinksViaMerge () {
216+
217+ Links links = Links .of (Link .of ("/foo" ));
218+ Link sameRel = Link .of ("/bar" );
219+
220+ List <NamedLinks > sources = Arrays .asList (//
221+ NamedLinks .of ("replace same rel via varargs" , links .merge (MergeMode .REPLACE_BY_REL , sameRel )),
222+ NamedLinks .of ("replace same rel via Stream" , links .merge (MergeMode .REPLACE_BY_REL , Stream .of (sameRel ))));
223+
224+ return DynamicTest .stream (sources .iterator (), NamedLinks ::getName ,
225+ it -> assertThat (it .links ).hasSize (1 ) //
226+ .element (0 ).extracting (Link ::getHref ).isEqualTo ("/bar" ));
227+ }
228+
229+ @ Test
230+ void removesLinkByRel () {
231+ assertThat (Links .of (Link .of ("/foo" )).without (IanaLinkRelations .SELF )).isEmpty ();
232+ }
233+
234+ @ Test
235+ void basics () {
236+
237+ Links none = Links .NONE ;
238+
239+ assertThat (none .isEmpty ()).isTrue ();
240+ assertThat (none .stream ()).isEmpty ();
241+ assertThat (none .hasSingleLink ()).isFalse ();
242+ assertThat (none .hasSize (0 )).isTrue ();
243+ assertThat (none .hasLink ("self" )).isFalse ();
244+
245+ Links one = none .and (Link .of ("/foo" ));
246+
247+ assertThat (one .isEmpty ()).isFalse ();
248+ assertThat (one .stream ()).isNotEmpty ();
249+ assertThat (one .hasSingleLink ()).isTrue ();
250+ assertThat (one .hasSize (1 )).isTrue ();
251+ assertThat (one .hasLink ("self" )).isTrue ();
252+
253+ Links anotherOne = none .and (Link .of ("/foo" ));
254+
255+ assertThat (anotherOne ).isEqualTo (one );
256+ assertThat (one ).isEqualTo (anotherOne );
257+ assertThat (one .hashCode ()).isEqualTo (anotherOne .hashCode ());
258+ }
259+
195260 @ Value (staticConstructor = "of" )
196261 static class NamedLinks {
197262 String name ;
0 commit comments