@@ -49,11 +49,14 @@ public void emptyContextInEmptyMap()
4949 @ Test
5050 public void uriWithoutQueryIsParsedToEmptyContext ()
5151 {
52- URI uri = URI .create ( "bolt+routing://localhost:7687/" );
53- RoutingContext context = new RoutingContext ( uri );
52+ testEmptyRoutingContext ( URI .create ( "bolt+routing://localhost:7687/" ) );
53+ }
5454
55- assertFalse ( context .isDefined () );
56- assertTrue ( context .asMap ().isEmpty () );
55+ @ Test
56+ public void uriWithEmptyQueryIsParsedToEmptyContext ()
57+ {
58+ testEmptyRoutingContext ( URI .create ( "bolt+routing://localhost:7687?" ) );
59+ testEmptyRoutingContext ( URI .create ( "bolt+routing://localhost:7687/?" ) );
5760 }
5861
5962 @ Test
@@ -73,33 +76,25 @@ public void uriWithQueryIsParsed()
7376 @ Test
7477 public void throwsForInvalidUriQuery ()
7578 {
76- URI uri = URI .create ( "bolt+routing://localhost:7687/?justKey" );
79+ testIllegalUri ( URI .create ( "bolt+routing://localhost:7687/?justKey" ) );
80+ }
7781
78- try
79- {
80- new RoutingContext ( uri );
81- fail ( "Exception expected" );
82- }
83- catch ( Exception e )
84- {
85- assertThat ( e , instanceOf ( IllegalArgumentException .class ) );
86- }
82+ @ Test
83+ public void throwsForInvalidUriQueryKey ()
84+ {
85+ testIllegalUri ( URI .create ( "bolt+routing://localhost:7687/?=value1&key2=value2" ) );
8786 }
8887
8988 @ Test
90- public void throwsForDuplicatedUriQueryParameters ()
89+ public void throwsForInvalidUriQueryValue ()
9190 {
92- URI uri = URI .create ( "bolt+routing://localhost:7687/?key1=value1&key2=value2&key1=value2" );
91+ testIllegalUri ( URI .create ( "bolt+routing://localhost:7687/key1?=value1&key2=" ) );
92+ }
9393
94- try
95- {
96- new RoutingContext ( uri );
97- fail ( "Exception expected" );
98- }
99- catch ( Exception e )
100- {
101- assertThat ( e , instanceOf ( IllegalArgumentException .class ) );
102- }
94+ @ Test
95+ public void throwsForDuplicatedUriQueryParameters ()
96+ {
97+ testIllegalUri ( URI .create ( "bolt+routing://localhost:7687/?key1=value1&key2=value2&key1=value2" ) );
10398 }
10499
105100 @ Test
@@ -122,4 +117,25 @@ public void mapRepresentationIsUnmodifiable()
122117
123118 assertEquals ( singletonMap ( "key1" , "value1" ), context .asMap () );
124119 }
120+
121+ private static void testIllegalUri ( URI uri )
122+ {
123+ try
124+ {
125+ new RoutingContext ( uri );
126+ fail ( "Exception expected" );
127+ }
128+ catch ( Exception e )
129+ {
130+ assertThat ( e , instanceOf ( IllegalArgumentException .class ) );
131+ }
132+ }
133+
134+ private static void testEmptyRoutingContext ( URI uri )
135+ {
136+ RoutingContext context = new RoutingContext ( uri );
137+
138+ assertFalse ( context .isDefined () );
139+ assertTrue ( context .asMap ().isEmpty () );
140+ }
125141}
0 commit comments