@@ -49,11 +49,14 @@ public void emptyContextInEmptyMap()
49
49
@ Test
50
50
public void uriWithoutQueryIsParsedToEmptyContext ()
51
51
{
52
- URI uri = URI .create ( "bolt+routing://localhost:7687/" );
53
- RoutingContext context = new RoutingContext ( uri );
52
+ testEmptyRoutingContext ( URI .create ( "bolt+routing://localhost:7687/" ) );
53
+ }
54
54
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/?" ) );
57
60
}
58
61
59
62
@ Test
@@ -73,33 +76,25 @@ public void uriWithQueryIsParsed()
73
76
@ Test
74
77
public void throwsForInvalidUriQuery ()
75
78
{
76
- URI uri = URI .create ( "bolt+routing://localhost:7687/?justKey" );
79
+ testIllegalUri ( URI .create ( "bolt+routing://localhost:7687/?justKey" ) );
80
+ }
77
81
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" ) );
87
86
}
88
87
89
88
@ Test
90
- public void throwsForDuplicatedUriQueryParameters ()
89
+ public void throwsForInvalidUriQueryValue ()
91
90
{
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
+ }
93
93
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" ) );
103
98
}
104
99
105
100
@ Test
@@ -122,4 +117,25 @@ public void mapRepresentationIsUnmodifiable()
122
117
123
118
assertEquals ( singletonMap ( "key1" , "value1" ), context .asMap () );
124
119
}
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
+ }
125
141
}
0 commit comments