1 package de.fhdw.wtf.parser.test;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
5 import static org.junit.Assert.fail;
6
7 import org.junit.Before;
8 import org.junit.Test;
9
10 import de.fhdw.wtf.common.exception.parser.NoArrowException;
11 import de.fhdw.wtf.common.exception.parser.NoBracketCloseException;
12 import de.fhdw.wtf.common.exception.parser.NoBracketOpenException;
13 import de.fhdw.wtf.common.exception.parser.NoColonException;
14 import de.fhdw.wtf.common.exception.parser.NoCurlyBracketCloseException;
15 import de.fhdw.wtf.common.exception.parser.NoCurlyBracketOpenException;
16 import de.fhdw.wtf.common.exception.parser.NoDoubleSquareBracketCloseException;
17 import de.fhdw.wtf.common.exception.parser.NoEqualException;
18 import de.fhdw.wtf.common.exception.parser.NoGroupElementException;
19 import de.fhdw.wtf.common.exception.parser.NoPlusSymbolException;
20 import de.fhdw.wtf.common.exception.parser.NoSemicolonException;
21 import de.fhdw.wtf.common.exception.parser.NoSquareBracketCloseException;
22 import de.fhdw.wtf.common.exception.parser.NoSquareBracketOpenException;
23 import de.fhdw.wtf.common.exception.parser.NoTypeException;
24 import de.fhdw.wtf.common.exception.parser.NoValidTokenStreamException;
25 import de.fhdw.wtf.common.exception.parser.OperationModifierAlreadyAddedException;
26 import de.fhdw.wtf.common.stream.SimpleTokenStream;
27 import de.fhdw.wtf.common.stream.TokenStream;
28 import de.fhdw.wtf.common.token.EndToken;
29 import de.fhdw.wtf.common.token.IdentifierToken;
30 import de.fhdw.wtf.common.token.Position;
31 import de.fhdw.wtf.common.token.keywords.AbstractToken;
32 import de.fhdw.wtf.common.token.keywords.ClassToken;
33 import de.fhdw.wtf.common.token.keywords.GroupToken;
34 import de.fhdw.wtf.common.token.symbols.ArrowToken;
35 import de.fhdw.wtf.common.token.symbols.BracketCloseToken;
36 import de.fhdw.wtf.common.token.symbols.BracketOpenToken;
37 import de.fhdw.wtf.common.token.symbols.ColonToken;
38 import de.fhdw.wtf.common.token.symbols.CommaToken;
39 import de.fhdw.wtf.common.token.symbols.CurlyBracketCloseToken;
40 import de.fhdw.wtf.common.token.symbols.CurlyBracketOpenToken;
41 import de.fhdw.wtf.common.token.symbols.DoubleSquareBracketCloseToken;
42 import de.fhdw.wtf.common.token.symbols.DoubleSquareBracketOpenToken;
43 import de.fhdw.wtf.common.token.symbols.EqualToken;
44 import de.fhdw.wtf.common.token.symbols.HyphenToken;
45 import de.fhdw.wtf.common.token.symbols.SemicolonToken;
46 import de.fhdw.wtf.common.token.symbols.SquareBracketCloseToken;
47 import de.fhdw.wtf.common.token.symbols.SquareBracketOpenToken;
48 import de.fhdw.wtf.parser.Parser;
49
50
51
52
53 public class TestExceptions {
54
55
56
57
58 private TokenStream stream;
59
60
61
62
63
64 private Parser parser;
65
66
67
68
69 private ColonToken colonToken;
70
71
72
73
74 private GroupToken groupToken;
75
76
77
78
79 private EqualToken equalToken;
80
81
82
83
84 private SquareBracketOpenToken squareBracketOpenToken;
85
86
87
88
89 private SquareBracketCloseToken squareBracketCloseToken;
90
91
92
93
94 private SemicolonToken semicolonToken;
95
96
97
98
99 private ClassToken classToken;
100
101
102
103
104 private CurlyBracketOpenToken curlyBracketOpenToken;
105
106
107
108
109 private CurlyBracketCloseToken curlyBracketCloseToken;
110
111
112
113
114 private BracketOpenToken bracketOpenToken;
115
116
117
118
119 private BracketCloseToken bracketCloseToken;
120
121
122
123
124 private EndToken endToken;
125
126
127
128
129 private ArrowToken arrowToken;
130
131
132
133
134 private CommaToken commaToken;
135
136
137
138
139 private AbstractToken abstractToken;
140
141
142
143
144 private DoubleSquareBracketOpenToken doubleSquareBracketOpenToken;
145
146
147
148
149 private DoubleSquareBracketCloseToken doubleSquareBracketCloseToken;
150
151
152
153
154 @Before
155 public void setUp() {
156 this.colonToken = ColonToken.create(Position.create("", 1, 1, 0));
157 this.groupToken = GroupToken.create(Position.create("", 1, 1, 0));
158 this.equalToken = EqualToken.create(Position.create("", 1, 1, 0));
159 this.squareBracketOpenToken = SquareBracketOpenToken.create(Position.create("", 1, 1, 0));
160 this.squareBracketCloseToken = SquareBracketCloseToken.create(Position.create("", 1, 1, 0));
161 this.bracketOpenToken = BracketOpenToken.create(Position.create("", 1, 1, 0));
162 this.bracketCloseToken = BracketCloseToken.create(Position.create("", 1, 1, 0));
163 this.semicolonToken = SemicolonToken.create(Position.create("", 1, 1, 0));
164 this.classToken = ClassToken.create(Position.create("", 1, 1, 0));
165 this.curlyBracketOpenToken = CurlyBracketOpenToken.create(Position.create("", 1, 1, 0));
166 this.curlyBracketCloseToken = CurlyBracketCloseToken.create(Position.create("", 1, 1, 0));
167 this.endToken = EndToken.create(Position.create("", 1, 1, 0));
168 this.abstractToken = AbstractToken.create(Position.create("", 1, 1, 0));
169 this.commaToken = CommaToken.create(Position.create("", 1, 1, 0));
170 this.doubleSquareBracketCloseToken = DoubleSquareBracketCloseToken.create(Position.create("", 1, 1, 0));
171 this.doubleSquareBracketOpenToken = DoubleSquareBracketOpenToken.create(Position.create("", 1, 1, 0));
172 this.arrowToken = ArrowToken.create(Position.create("", 1, 1, 0));
173 }
174
175
176
177
178 @Test
179 public void testNoArrowException() {
180 this.stream = SimpleTokenStream.create();
181 this.parser = Parser.create(this.stream);
182 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
183 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
184 final IdentifierToken myOperation = IdentifierToken.create("MyOperation", Position.create("", 1, 1, 0));
185 final IdentifierToken myParameter = IdentifierToken.create("MyParameter", Position.create("", 1, 1, 0));
186 final IdentifierToken string = IdentifierToken.create("String", Position.create("", 1, 1, 0));
187 this.stream.add(myGroup);
188 this.stream.add(this.colonToken);
189 this.stream.add(this.groupToken);
190 this.stream.add(this.equalToken);
191 this.stream.add(this.squareBracketOpenToken);
192 this.stream.add(myClass);
193 this.stream.add(this.colonToken);
194 this.stream.add(this.classToken);
195 this.stream.add(this.equalToken);
196 this.stream.add(this.curlyBracketOpenToken);
197 this.stream.add(myOperation);
198 this.stream.add(this.colonToken);
199 this.stream.add(this.doubleSquareBracketOpenToken);
200 this.stream.add(this.bracketOpenToken);
201 this.stream.add(myParameter);
202 this.stream.add(this.colonToken);
203 this.stream.add(string);
204 this.stream.add(this.bracketCloseToken);
205 this.stream.add(HyphenToken.create(Position.createDummyPosition()));
206 this.stream.add(this.curlyBracketOpenToken);
207 this.stream.add(this.curlyBracketCloseToken);
208 this.stream.add(this.doubleSquareBracketCloseToken);
209 this.stream.add(this.semicolonToken);
210 this.stream.add(this.curlyBracketCloseToken);
211 this.stream.add(this.semicolonToken);
212 this.stream.add(this.squareBracketCloseToken);
213 this.stream.add(this.semicolonToken);
214 this.stream.add(this.endToken);
215
216 try {
217 this.parser.parse();
218 fail();
219 } catch (final NoValidTokenStreamException e) {
220 boolean noArrowException = false;
221 assertEquals(1, this.parser.getExceptions().size());
222 for (final Exception ex : this.parser.getExceptions()) {
223 if (ex instanceof NoArrowException) {
224 noArrowException = true;
225 }
226 }
227 assertTrue(noArrowException);
228 }
229 }
230
231
232
233
234 @Test
235 public void testNoTypeExceptionProduct() {
236 this.stream = SimpleTokenStream.create();
237 this.parser = Parser.create(this.stream);
238 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
239 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
240 final IdentifierToken myAttribute = IdentifierToken.create("MyAttribute", Position.create("", 1, 1, 0));
241 final IdentifierToken name = IdentifierToken.create("name", Position.create("", 1, 1, 0));
242 this.stream.add(myGroup);
243 this.stream.add(this.colonToken);
244 this.stream.add(this.groupToken);
245 this.stream.add(this.equalToken);
246 this.stream.add(this.squareBracketOpenToken);
247 this.stream.add(myClass);
248 this.stream.add(this.colonToken);
249 this.stream.add(this.classToken);
250 this.stream.add(this.equalToken);
251 this.stream.add(this.curlyBracketOpenToken);
252 this.stream.add(myAttribute);
253 this.stream.add(this.colonToken);
254 this.stream.add(this.bracketOpenToken);
255 this.stream.add(name);
256 this.stream.add(this.colonToken);
257 this.stream.add(this.bracketCloseToken);
258 this.stream.add(this.semicolonToken);
259 this.stream.add(this.curlyBracketCloseToken);
260 this.stream.add(this.semicolonToken);
261 this.stream.add(this.squareBracketCloseToken);
262 this.stream.add(this.semicolonToken);
263 this.stream.add(this.endToken);
264
265 try {
266 this.parser.parse();
267 fail();
268 } catch (final NoValidTokenStreamException e) {
269 boolean noType = false;
270 assertEquals(1, this.parser.getExceptions().size());
271 for (final Exception ex : this.parser.getExceptions()) {
272 if (ex instanceof NoTypeException) {
273 noType = true;
274 }
275 }
276 assertTrue(noType);
277 }
278 }
279
280
281
282
283 @Test
284 public void testNoTypeExceptionSum() {
285 this.stream = SimpleTokenStream.create();
286 this.parser = Parser.create(this.stream);
287 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
288 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
289 final IdentifierToken myAttribute = IdentifierToken.create("MyAttribute", Position.create("", 1, 1, 0));
290 final IdentifierToken string = IdentifierToken.create("String", Position.create("", 1, 1, 0));
291 this.stream.add(myGroup);
292 this.stream.add(this.colonToken);
293 this.stream.add(this.groupToken);
294 this.stream.add(this.equalToken);
295 this.stream.add(this.squareBracketOpenToken);
296 this.stream.add(myClass);
297 this.stream.add(this.colonToken);
298 this.stream.add(this.classToken);
299 this.stream.add(this.equalToken);
300 this.stream.add(this.curlyBracketOpenToken);
301 this.stream.add(myAttribute);
302 this.stream.add(this.colonToken);
303 this.stream.add(this.curlyBracketOpenToken);
304 this.stream.add(string);
305 this.stream.add(this.commaToken);
306 this.stream.add(this.curlyBracketCloseToken);
307 this.stream.add(this.semicolonToken);
308 this.stream.add(this.curlyBracketCloseToken);
309 this.stream.add(this.semicolonToken);
310 this.stream.add(this.squareBracketCloseToken);
311 this.stream.add(this.semicolonToken);
312 this.stream.add(this.endToken);
313
314 try {
315 this.parser.parse();
316 fail();
317 } catch (final NoValidTokenStreamException e) {
318 boolean noType = false;
319 assertEquals(1, this.parser.getExceptions().size());
320 for (final Exception ex : this.parser.getExceptions()) {
321 if (ex instanceof NoTypeException) {
322 noType = true;
323 }
324 }
325 assertTrue(noType);
326 }
327 }
328
329
330
331
332 @Test
333 public void testOperationModifierAlreadyAddedException() {
334 this.stream = SimpleTokenStream.create();
335 this.parser = Parser.create(this.stream);
336 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
337 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
338 final IdentifierToken myOperation = IdentifierToken.create("MyOperation", Position.create("", 1, 1, 0));
339 final IdentifierToken myParameter = IdentifierToken.create("MyParameter", Position.create("", 1, 1, 0));
340 final IdentifierToken string = IdentifierToken.create("String", Position.create("", 1, 1, 0));
341 this.stream.add(myGroup);
342 this.stream.add(this.colonToken);
343 this.stream.add(this.groupToken);
344 this.stream.add(this.equalToken);
345 this.stream.add(this.squareBracketOpenToken);
346 this.stream.add(myClass);
347 this.stream.add(this.colonToken);
348 this.stream.add(this.classToken);
349 this.stream.add(this.equalToken);
350 this.stream.add(this.curlyBracketOpenToken);
351 this.stream.add(myOperation);
352 this.stream.add(this.colonToken);
353 this.stream.add(this.doubleSquareBracketOpenToken);
354 this.stream.add(this.bracketOpenToken);
355 this.stream.add(myParameter);
356 this.stream.add(this.colonToken);
357 this.stream.add(string);
358 this.stream.add(this.bracketCloseToken);
359 this.stream.add(this.arrowToken);
360 this.stream.add(this.curlyBracketOpenToken);
361 this.stream.add(this.curlyBracketCloseToken);
362 this.stream.add(this.doubleSquareBracketCloseToken);
363 this.stream.add(this.abstractToken);
364 this.stream.add(this.abstractToken);
365 this.stream.add(this.semicolonToken);
366 this.stream.add(this.curlyBracketCloseToken);
367 this.stream.add(this.semicolonToken);
368 this.stream.add(this.squareBracketCloseToken);
369 this.stream.add(this.semicolonToken);
370 this.stream.add(this.endToken);
371
372 try {
373 this.parser.parse();
374 fail();
375 } catch (final NoValidTokenStreamException e) {
376 boolean doubleOperationModifier = false;
377 assertEquals(1, this.parser.getExceptions().size());
378 for (final Exception ex : this.parser.getExceptions()) {
379 if (ex instanceof OperationModifierAlreadyAddedException) {
380 doubleOperationModifier = true;
381 }
382 }
383 assertTrue(doubleOperationModifier);
384 }
385 }
386
387
388
389
390 @Test
391 public void testNoBracketCloseException() {
392 this.stream = SimpleTokenStream.create();
393 this.parser = Parser.create(this.stream);
394 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
395 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
396 final IdentifierToken myOperation = IdentifierToken.create("MyOperation", Position.create("", 1, 1, 0));
397 final IdentifierToken myParameter = IdentifierToken.create("MyParameter", Position.create("", 1, 1, 0));
398 final IdentifierToken string = IdentifierToken.create("String", Position.create("", 1, 1, 0));
399 this.stream.add(myGroup);
400 this.stream.add(this.colonToken);
401 this.stream.add(this.groupToken);
402 this.stream.add(this.equalToken);
403 this.stream.add(this.squareBracketOpenToken);
404 this.stream.add(myClass);
405 this.stream.add(this.colonToken);
406 this.stream.add(this.classToken);
407 this.stream.add(this.equalToken);
408 this.stream.add(this.curlyBracketOpenToken);
409 this.stream.add(myOperation);
410 this.stream.add(this.colonToken);
411 this.stream.add(this.doubleSquareBracketOpenToken);
412 this.stream.add(this.bracketOpenToken);
413 this.stream.add(myParameter);
414 this.stream.add(this.colonToken);
415 this.stream.add(string);
416 this.stream.add(this.arrowToken);
417 this.stream.add(this.curlyBracketOpenToken);
418 this.stream.add(this.curlyBracketCloseToken);
419 this.stream.add(this.doubleSquareBracketCloseToken);
420 this.stream.add(this.semicolonToken);
421 this.stream.add(this.curlyBracketCloseToken);
422 this.stream.add(this.semicolonToken);
423 this.stream.add(this.squareBracketCloseToken);
424 this.stream.add(this.semicolonToken);
425 this.stream.add(this.endToken);
426
427 try {
428 this.parser.parse();
429 fail();
430 } catch (final NoValidTokenStreamException e) {
431 assertEquals(1, this.parser.getExceptions().size());
432 boolean noBracketClose = false;
433 for (final Exception ex : this.parser.getExceptions()) {
434 if (ex instanceof NoBracketCloseException) {
435 noBracketClose = true;
436 }
437 }
438 assertTrue(noBracketClose);
439 }
440 }
441
442
443
444
445 @Test
446 public void testNoSemicolonExceptionOperation() {
447 this.stream = SimpleTokenStream.create();
448 this.parser = Parser.create(this.stream);
449 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
450 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
451 final IdentifierToken myOperation = IdentifierToken.create("MyOperation", Position.create("", 1, 1, 0));
452 final IdentifierToken myParameter = IdentifierToken.create("MyParameter", Position.create("", 1, 1, 0));
453 final IdentifierToken string = IdentifierToken.create("String", Position.create("", 1, 1, 0));
454 this.stream.add(myGroup);
455 this.stream.add(this.colonToken);
456 this.stream.add(this.groupToken);
457 this.stream.add(this.equalToken);
458 this.stream.add(this.squareBracketOpenToken);
459 this.stream.add(myClass);
460 this.stream.add(this.colonToken);
461 this.stream.add(this.classToken);
462 this.stream.add(this.equalToken);
463 this.stream.add(this.curlyBracketOpenToken);
464 this.stream.add(myOperation);
465 this.stream.add(this.colonToken);
466 this.stream.add(this.doubleSquareBracketOpenToken);
467 this.stream.add(this.bracketOpenToken);
468 this.stream.add(myParameter);
469 this.stream.add(this.colonToken);
470 this.stream.add(string);
471 this.stream.add(this.bracketCloseToken);
472 this.stream.add(this.arrowToken);
473 this.stream.add(this.curlyBracketOpenToken);
474 this.stream.add(this.curlyBracketCloseToken);
475 this.stream.add(this.doubleSquareBracketCloseToken);
476 this.stream.add(this.curlyBracketCloseToken);
477 this.stream.add(this.semicolonToken);
478 this.stream.add(this.squareBracketCloseToken);
479 this.stream.add(this.semicolonToken);
480 this.stream.add(this.endToken);
481
482 try {
483 this.parser.parse();
484 fail();
485 } catch (final NoValidTokenStreamException e) {
486 assertEquals(1, this.parser.getExceptions().size());
487 boolean noSemicolon = false;
488 for (final Exception ex : this.parser.getExceptions()) {
489 if (ex instanceof NoSemicolonException) {
490 noSemicolon = true;
491 }
492 }
493 assertTrue(noSemicolon);
494 }
495 }
496
497
498
499
500 @Test
501 public void testNoBracketCloseExceptionAttribute() {
502 this.stream = SimpleTokenStream.create();
503 this.parser = Parser.create(this.stream);
504 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
505 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
506 final IdentifierToken myAttribute = IdentifierToken.create("MyAttribute", Position.create("", 1, 1, 0));
507 final IdentifierToken name = IdentifierToken.create("name", Position.create("", 1, 1, 0));
508 final IdentifierToken string = IdentifierToken.create("String", Position.create("", 1, 1, 0));
509 this.stream.add(myGroup);
510 this.stream.add(this.colonToken);
511 this.stream.add(this.groupToken);
512 this.stream.add(this.equalToken);
513 this.stream.add(this.squareBracketOpenToken);
514 this.stream.add(myClass);
515 this.stream.add(this.colonToken);
516 this.stream.add(this.classToken);
517 this.stream.add(this.equalToken);
518 this.stream.add(this.curlyBracketOpenToken);
519 this.stream.add(myAttribute);
520 this.stream.add(this.colonToken);
521 this.stream.add(this.bracketOpenToken);
522 this.stream.add(name);
523 this.stream.add(this.colonToken);
524 this.stream.add(string);
525 this.stream.add(this.semicolonToken);
526 this.stream.add(this.curlyBracketCloseToken);
527 this.stream.add(this.semicolonToken);
528 this.stream.add(this.squareBracketCloseToken);
529 this.stream.add(this.semicolonToken);
530 this.stream.add(this.endToken);
531
532 try {
533 this.parser.parse();
534 fail();
535 } catch (final NoValidTokenStreamException e) {
536 assertEquals(1, this.parser.getExceptions().size());
537 boolean noBracketClose = false;
538 for (final Exception ex : this.parser.getExceptions()) {
539 if (ex instanceof NoBracketCloseException) {
540 noBracketClose = true;
541 }
542 }
543 assertTrue(noBracketClose);
544 }
545 }
546
547
548
549
550 @Test
551 public void testNoSemicolonExceptionAttribute() {
552 this.stream = SimpleTokenStream.create();
553 this.parser = Parser.create(this.stream);
554 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
555 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
556 final IdentifierToken myAttribute = IdentifierToken.create("MyAttribute", Position.create("", 1, 1, 0));
557 final IdentifierToken name = IdentifierToken.create("name", Position.create("", 1, 1, 0));
558 final IdentifierToken string = IdentifierToken.create("String", Position.create("", 1, 1, 0));
559 this.stream.add(myGroup);
560 this.stream.add(this.colonToken);
561 this.stream.add(this.groupToken);
562 this.stream.add(this.equalToken);
563 this.stream.add(this.squareBracketOpenToken);
564 this.stream.add(myClass);
565 this.stream.add(this.colonToken);
566 this.stream.add(this.classToken);
567 this.stream.add(this.equalToken);
568 this.stream.add(this.curlyBracketOpenToken);
569 this.stream.add(myAttribute);
570 this.stream.add(this.colonToken);
571 this.stream.add(this.bracketOpenToken);
572 this.stream.add(name);
573 this.stream.add(this.colonToken);
574 this.stream.add(string);
575 this.stream.add(this.bracketCloseToken);
576 this.stream.add(this.curlyBracketCloseToken);
577 this.stream.add(this.semicolonToken);
578 this.stream.add(this.squareBracketCloseToken);
579 this.stream.add(this.semicolonToken);
580 this.stream.add(this.endToken);
581
582 try {
583 this.parser.parse();
584 fail();
585 } catch (final NoValidTokenStreamException e) {
586 assertEquals(1, this.parser.getExceptions().size());
587 boolean noSemicolon = false;
588 for (final Exception ex : this.parser.getExceptions()) {
589 if (ex instanceof NoSemicolonException) {
590 noSemicolon = true;
591 }
592 }
593 assertTrue(noSemicolon);
594 }
595 }
596
597
598
599
600 @Test
601 public void testNoSemicolonExceptionClass() {
602 this.stream = SimpleTokenStream.create();
603 this.parser = Parser.create(this.stream);
604 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
605 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
606 final IdentifierToken myClass2 = IdentifierToken.create("MyClass2", Position.create("", 1, 1, 0));
607 final IdentifierToken myAttribute = IdentifierToken.create("MyAttribute", Position.create("", 1, 1, 0));
608 final IdentifierToken name = IdentifierToken.create("name", Position.create("", 1, 1, 0));
609 final IdentifierToken string = IdentifierToken.create("String", Position.create("", 1, 1, 0));
610 this.stream.add(myGroup);
611 this.stream.add(this.colonToken);
612 this.stream.add(this.groupToken);
613 this.stream.add(this.equalToken);
614 this.stream.add(this.squareBracketOpenToken);
615 this.stream.add(myClass);
616 this.stream.add(this.colonToken);
617 this.stream.add(this.classToken);
618 this.stream.add(this.equalToken);
619 this.stream.add(this.curlyBracketOpenToken);
620 this.stream.add(myAttribute);
621 this.stream.add(this.colonToken);
622 this.stream.add(this.bracketOpenToken);
623 this.stream.add(name);
624 this.stream.add(this.colonToken);
625 this.stream.add(string);
626 this.stream.add(this.bracketCloseToken);
627 this.stream.add(this.semicolonToken);
628 this.stream.add(this.curlyBracketCloseToken);
629 this.stream.add(myClass2);
630 this.stream.add(this.colonToken);
631 this.stream.add(this.classToken);
632 this.stream.add(this.equalToken);
633 this.stream.add(this.curlyBracketOpenToken);
634 this.stream.add(this.curlyBracketCloseToken);
635 this.stream.add(this.semicolonToken);
636 this.stream.add(this.squareBracketCloseToken);
637 this.stream.add(this.semicolonToken);
638 this.stream.add(this.endToken);
639
640 try {
641 this.parser.parse();
642 fail();
643 } catch (final NoValidTokenStreamException e) {
644 assertEquals(1, this.parser.getExceptions().size());
645 boolean noSemicolon = false;
646 for (final Exception ex : this.parser.getExceptions()) {
647 if (ex instanceof NoSemicolonException) {
648 noSemicolon = true;
649 }
650 }
651 assertTrue(noSemicolon);
652 }
653 }
654
655
656
657
658 @Test
659 public void testNoBracketOpenException() {
660 this.stream = SimpleTokenStream.create();
661 this.parser = Parser.create(this.stream);
662 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
663 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
664 final IdentifierToken myOperation = IdentifierToken.create("MyOperation", Position.create("", 1, 1, 0));
665 final IdentifierToken myParameter = IdentifierToken.create("MyParameter", Position.create("", 1, 1, 0));
666 final IdentifierToken string = IdentifierToken.create("String", Position.create("", 1, 1, 0));
667 this.stream.add(myGroup);
668 this.stream.add(this.colonToken);
669 this.stream.add(this.groupToken);
670 this.stream.add(this.equalToken);
671 this.stream.add(this.squareBracketOpenToken);
672 this.stream.add(myClass);
673 this.stream.add(this.colonToken);
674 this.stream.add(this.classToken);
675 this.stream.add(this.equalToken);
676 this.stream.add(this.curlyBracketOpenToken);
677 this.stream.add(myOperation);
678 this.stream.add(this.colonToken);
679 this.stream.add(this.doubleSquareBracketOpenToken);
680 this.stream.add(myParameter);
681 this.stream.add(this.colonToken);
682 this.stream.add(string);
683 this.stream.add(this.bracketCloseToken);
684 this.stream.add(this.arrowToken);
685 this.stream.add(this.curlyBracketOpenToken);
686 this.stream.add(this.curlyBracketCloseToken);
687 this.stream.add(this.doubleSquareBracketCloseToken);
688 this.stream.add(this.semicolonToken);
689 this.stream.add(this.curlyBracketCloseToken);
690 this.stream.add(this.semicolonToken);
691 this.stream.add(this.squareBracketCloseToken);
692 this.stream.add(this.semicolonToken);
693 this.stream.add(this.endToken);
694
695 try {
696 this.parser.parse();
697 fail();
698 } catch (final NoValidTokenStreamException e) {
699 boolean noBracketOpen = false;
700 assertEquals(1, this.parser.getExceptions().size());
701 for (final Exception ex : this.parser.getExceptions()) {
702 if (ex instanceof NoBracketOpenException) {
703 noBracketOpen = true;
704 }
705 }
706 assertTrue(noBracketOpen);
707 }
708 }
709
710
711
712
713 @Test
714 public void testNoColonException() {
715 this.stream = SimpleTokenStream.create();
716 this.parser = Parser.create(this.stream);
717 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
718 this.stream.add(myGroup);
719 this.stream.add(HyphenToken.create(Position.createDummyPosition()));
720 this.stream.add(this.groupToken);
721 this.stream.add(this.equalToken);
722 this.stream.add(this.squareBracketOpenToken);
723 this.stream.add(this.squareBracketCloseToken);
724 this.stream.add(this.semicolonToken);
725 this.stream.add(this.endToken);
726
727 try {
728 this.parser.parse();
729 fail();
730 } catch (final NoValidTokenStreamException e) {
731 boolean noColon = false;
732 assertEquals(1, this.parser.getExceptions().size());
733 for (final Exception ex : this.parser.getExceptions()) {
734 if (ex instanceof NoColonException) {
735 noColon = true;
736 }
737 }
738 assertTrue(noColon);
739 }
740 }
741
742
743
744
745 @Test
746 public void testNoColonExceptionSemicolon() {
747 this.stream = SimpleTokenStream.create();
748 this.parser = Parser.create(this.stream);
749 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
750 this.stream.add(myGroup);
751 this.stream.add(this.semicolonToken);
752 this.stream.add(this.groupToken);
753 this.stream.add(this.equalToken);
754 this.stream.add(this.squareBracketOpenToken);
755 this.stream.add(this.squareBracketCloseToken);
756 this.stream.add(this.semicolonToken);
757 this.stream.add(this.endToken);
758
759 try {
760 this.parser.parse();
761 fail();
762 } catch (final NoValidTokenStreamException e) {
763 boolean noColon = false;
764 for (final Exception ex : this.parser.getExceptions()) {
765 if (ex instanceof NoColonException) {
766 noColon = true;
767 }
768 }
769 assertTrue(noColon);
770 }
771 }
772
773
774
775
776 @Test
777 public void testNoCurlyBracketCloseExceptionClass() {
778 this.stream = SimpleTokenStream.create();
779 this.parser = Parser.create(this.stream);
780 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
781 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
782 final IdentifierToken myOperation = IdentifierToken.create("MyOperation", Position.create("", 1, 1, 0));
783 final IdentifierToken myParameter = IdentifierToken.create("MyParameter", Position.create("", 1, 1, 0));
784 final IdentifierToken string = IdentifierToken.create("String", Position.create("", 1, 1, 0));
785 this.stream.add(myGroup);
786 this.stream.add(this.colonToken);
787 this.stream.add(this.groupToken);
788 this.stream.add(this.equalToken);
789 this.stream.add(this.squareBracketOpenToken);
790 this.stream.add(myClass);
791 this.stream.add(this.colonToken);
792 this.stream.add(this.classToken);
793 this.stream.add(this.equalToken);
794 this.stream.add(this.curlyBracketOpenToken);
795 this.stream.add(myOperation);
796 this.stream.add(this.colonToken);
797 this.stream.add(this.doubleSquareBracketOpenToken);
798 this.stream.add(this.bracketOpenToken);
799 this.stream.add(myParameter);
800 this.stream.add(this.colonToken);
801 this.stream.add(string);
802 this.stream.add(this.bracketCloseToken);
803 this.stream.add(this.arrowToken);
804 this.stream.add(this.curlyBracketOpenToken);
805 this.stream.add(this.curlyBracketCloseToken);
806 this.stream.add(this.doubleSquareBracketCloseToken);
807 this.stream.add(this.semicolonToken);
808 this.stream.add(this.semicolonToken);
809 this.stream.add(this.squareBracketCloseToken);
810 this.stream.add(this.semicolonToken);
811 this.stream.add(this.endToken);
812
813 try {
814 this.parser.parse();
815 fail();
816 } catch (final NoValidTokenStreamException e) {
817 boolean noCurlyBracketClose = false;
818 assertEquals(1, this.parser.getExceptions().size());
819 for (final Exception ex : this.parser.getExceptions()) {
820 if (ex instanceof NoCurlyBracketCloseException) {
821 noCurlyBracketClose = true;
822 }
823 }
824 assertTrue(noCurlyBracketClose);
825 }
826 }
827
828
829
830
831 @Test
832 public void testNoCurlyBracketCloseExceptionSum() {
833 this.stream = SimpleTokenStream.create();
834 this.parser = Parser.create(this.stream);
835 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
836 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
837 final IdentifierToken myAttribute = IdentifierToken.create("MyAttribute", Position.create("", 1, 1, 0));
838 final IdentifierToken string = IdentifierToken.create("String", Position.create("", 1, 1, 0));
839 final IdentifierToken integer = IdentifierToken.create("Integer", Position.create("", 1, 1, 0));
840 this.stream.add(myGroup);
841 this.stream.add(this.colonToken);
842 this.stream.add(this.groupToken);
843 this.stream.add(this.equalToken);
844 this.stream.add(this.squareBracketOpenToken);
845 this.stream.add(myClass);
846 this.stream.add(this.colonToken);
847 this.stream.add(this.classToken);
848 this.stream.add(this.equalToken);
849 this.stream.add(this.curlyBracketOpenToken);
850 this.stream.add(myAttribute);
851 this.stream.add(this.colonToken);
852 this.stream.add(this.curlyBracketOpenToken);
853 this.stream.add(string);
854 this.stream.add(this.commaToken);
855 this.stream.add(integer);
856 this.stream.add(this.semicolonToken);
857 this.stream.add(this.curlyBracketCloseToken);
858 this.stream.add(this.semicolonToken);
859 this.stream.add(this.squareBracketCloseToken);
860 this.stream.add(this.semicolonToken);
861 this.stream.add(this.endToken);
862
863 try {
864 this.parser.parse();
865 fail();
866 } catch (final NoValidTokenStreamException e) {
867 boolean noCurlyBracketClose = false;
868 assertEquals(1, this.parser.getExceptions().size());
869 for (final Exception ex : this.parser.getExceptions()) {
870 if (ex instanceof NoCurlyBracketCloseException) {
871 noCurlyBracketClose = true;
872 }
873 }
874 assertTrue(noCurlyBracketClose);
875 }
876 }
877
878
879
880
881 @Test
882 public void testNoCurlyBracketOpenException1() {
883 this.stream = SimpleTokenStream.create();
884 this.parser = Parser.create(this.stream);
885 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
886 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
887 final IdentifierToken myOperation = IdentifierToken.create("MyOperation", Position.create("", 1, 1, 0));
888 final IdentifierToken myParameter = IdentifierToken.create("MyParameter", Position.create("", 1, 1, 0));
889 final IdentifierToken string = IdentifierToken.create("String", Position.create("", 1, 1, 0));
890 this.stream.add(myGroup);
891 this.stream.add(this.colonToken);
892 this.stream.add(this.groupToken);
893 this.stream.add(this.equalToken);
894 this.stream.add(this.squareBracketOpenToken);
895 this.stream.add(myClass);
896 this.stream.add(this.colonToken);
897 this.stream.add(this.classToken);
898 this.stream.add(this.equalToken);
899 this.stream.add(myOperation);
900 this.stream.add(this.colonToken);
901 this.stream.add(this.doubleSquareBracketOpenToken);
902 this.stream.add(this.bracketOpenToken);
903 this.stream.add(myParameter);
904 this.stream.add(this.colonToken);
905 this.stream.add(string);
906 this.stream.add(this.bracketCloseToken);
907 this.stream.add(this.arrowToken);
908 this.stream.add(this.curlyBracketOpenToken);
909 this.stream.add(this.curlyBracketCloseToken);
910 this.stream.add(this.doubleSquareBracketCloseToken);
911 this.stream.add(this.semicolonToken);
912 this.stream.add(this.curlyBracketCloseToken);
913 this.stream.add(this.semicolonToken);
914 this.stream.add(this.squareBracketCloseToken);
915 this.stream.add(this.semicolonToken);
916 this.stream.add(this.endToken);
917
918 try {
919 this.parser.parse();
920 fail();
921 } catch (final NoValidTokenStreamException e) {
922 assertEquals(1, this.parser.getExceptions().size());
923 boolean noCurlyBracketOpen = false;
924 for (final Exception ex : this.parser.getExceptions()) {
925 if (ex instanceof NoCurlyBracketOpenException) {
926 noCurlyBracketOpen = true;
927 }
928 }
929 assertTrue(noCurlyBracketOpen);
930 }
931 }
932
933
934
935
936 @Test
937 public void testNoCurlyBracketOpenException2() {
938 this.stream = SimpleTokenStream.create();
939 this.parser = Parser.create(this.stream);
940 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
941 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
942 this.stream.add(myGroup);
943 this.stream.add(this.colonToken);
944 this.stream.add(this.groupToken);
945 this.stream.add(this.equalToken);
946 this.stream.add(this.squareBracketOpenToken);
947 this.stream.add(myClass);
948 this.stream.add(this.colonToken);
949 this.stream.add(this.classToken);
950 this.stream.add(this.equalToken);
951 this.stream.add(this.squareBracketOpenToken);
952 this.stream.add(this.squareBracketCloseToken);
953 this.stream.add(this.semicolonToken);
954 this.stream.add(this.squareBracketCloseToken);
955 this.stream.add(this.semicolonToken);
956 this.stream.add(this.endToken);
957
958 try {
959 this.parser.parse();
960 fail();
961 } catch (final NoValidTokenStreamException e) {
962 assertEquals(2, this.parser.getExceptions().size());
963 boolean noCurlyBracketOpen = false;
964 for (final Exception ex : this.parser.getExceptions()) {
965 if (ex instanceof NoCurlyBracketOpenException) {
966 noCurlyBracketOpen = true;
967 }
968 }
969 assertTrue(noCurlyBracketOpen);
970 }
971 }
972
973
974
975
976 @Test
977 public void testNoCurlyBracketOpenException3() {
978 this.stream = SimpleTokenStream.create();
979 this.parser = Parser.create(this.stream);
980 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
981 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
982 this.stream.add(myGroup);
983 this.stream.add(this.colonToken);
984 this.stream.add(this.groupToken);
985 this.stream.add(this.equalToken);
986 this.stream.add(this.squareBracketOpenToken);
987 this.stream.add(myClass);
988 this.stream.add(this.colonToken);
989 this.stream.add(this.classToken);
990 this.stream.add(this.equalToken);
991 this.stream.add(this.curlyBracketCloseToken);
992 this.stream.add(this.semicolonToken);
993 this.stream.add(this.squareBracketCloseToken);
994 this.stream.add(this.semicolonToken);
995 this.stream.add(this.endToken);
996
997 try {
998 this.parser.parse();
999 fail();
1000 } catch (final NoValidTokenStreamException e) {
1001 assertEquals(1, this.parser.getExceptions().size());
1002 boolean noCurlyBracketOpen = false;
1003 for (final Exception ex : this.parser.getExceptions()) {
1004 if (ex instanceof NoCurlyBracketOpenException) {
1005 noCurlyBracketOpen = true;
1006 }
1007 }
1008 assertTrue(noCurlyBracketOpen);
1009 }
1010 }
1011
1012
1013
1014
1015 @Test
1016 public void testNoPlusSymbolException() {
1017 this.stream = SimpleTokenStream.create();
1018 this.parser = Parser.create(this.stream);
1019 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
1020 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
1021 final IdentifierToken mySecondClass = IdentifierToken.create("MySecondClass", Position.create("", 1, 1, 0));
1022 this.stream.add(myGroup);
1023 this.stream.add(this.colonToken);
1024 this.stream.add(this.groupToken);
1025 this.stream.add(this.equalToken);
1026 this.stream.add(this.squareBracketOpenToken);
1027 this.stream.add(myClass);
1028 this.stream.add(this.colonToken);
1029 this.stream.add(this.classToken);
1030 this.stream.add(this.equalToken);
1031 this.stream.add(mySecondClass);
1032 this.stream.add(this.curlyBracketOpenToken);
1033 this.stream.add(this.curlyBracketCloseToken);
1034 this.stream.add(this.semicolonToken);
1035 this.stream.add(this.squareBracketCloseToken);
1036 this.stream.add(this.semicolonToken);
1037 this.stream.add(this.endToken);
1038
1039 try {
1040 this.parser.parse();
1041 fail();
1042 } catch (final NoValidTokenStreamException e) {
1043 assertEquals(1, this.parser.getExceptions().size());
1044 boolean noPlusSymbol = false;
1045 for (final Exception ex : this.parser.getExceptions()) {
1046 if (ex instanceof NoPlusSymbolException) {
1047 noPlusSymbol = true;
1048 }
1049 }
1050 assertTrue(noPlusSymbol);
1051 }
1052 }
1053
1054
1055
1056
1057 @Test
1058 public void testDoubleSquareBracketCloseException() {
1059 this.stream = SimpleTokenStream.create();
1060 this.parser = Parser.create(this.stream);
1061 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
1062 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
1063 final IdentifierToken myOperation = IdentifierToken.create("MyOperation", Position.create("", 1, 1, 0));
1064 final IdentifierToken myParameter = IdentifierToken.create("MyParameter", Position.create("", 1, 1, 0));
1065 final IdentifierToken string = IdentifierToken.create("String", Position.create("", 1, 1, 0));
1066 this.stream.add(myGroup);
1067 this.stream.add(this.colonToken);
1068 this.stream.add(this.groupToken);
1069 this.stream.add(this.equalToken);
1070 this.stream.add(this.squareBracketOpenToken);
1071 this.stream.add(myClass);
1072 this.stream.add(this.colonToken);
1073 this.stream.add(this.classToken);
1074 this.stream.add(this.equalToken);
1075 this.stream.add(this.curlyBracketOpenToken);
1076 this.stream.add(myOperation);
1077 this.stream.add(this.colonToken);
1078 this.stream.add(this.doubleSquareBracketOpenToken);
1079 this.stream.add(this.bracketOpenToken);
1080 this.stream.add(myParameter);
1081 this.stream.add(this.colonToken);
1082 this.stream.add(string);
1083 this.stream.add(this.bracketCloseToken);
1084 this.stream.add(this.arrowToken);
1085 this.stream.add(this.curlyBracketOpenToken);
1086 this.stream.add(this.curlyBracketCloseToken);
1087 this.stream.add(this.semicolonToken);
1088 this.stream.add(this.curlyBracketCloseToken);
1089 this.stream.add(this.semicolonToken);
1090 this.stream.add(this.squareBracketCloseToken);
1091 this.stream.add(this.semicolonToken);
1092 this.stream.add(this.endToken);
1093
1094 try {
1095 this.parser.parse();
1096 fail();
1097 } catch (final NoValidTokenStreamException e) {
1098 boolean noDoubleSquareBracketClose = false;
1099 assertEquals(1, this.parser.getExceptions().size());
1100 for (final Exception ex : this.parser.getExceptions()) {
1101 if (ex instanceof NoDoubleSquareBracketCloseException) {
1102 noDoubleSquareBracketClose = true;
1103 }
1104 }
1105 assertTrue(noDoubleSquareBracketClose);
1106 }
1107 }
1108
1109
1110
1111
1112 @Test
1113 public void testNoEqualsExceptionGroup() {
1114 this.stream = SimpleTokenStream.create();
1115 this.parser = Parser.create(this.stream);
1116 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
1117 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
1118 this.stream.add(myGroup);
1119 this.stream.add(this.colonToken);
1120 this.stream.add(this.groupToken);
1121 this.stream.add(this.squareBracketOpenToken);
1122 this.stream.add(myClass);
1123 this.stream.add(this.colonToken);
1124 this.stream.add(this.classToken);
1125 this.stream.add(this.equalToken);
1126 this.stream.add(this.curlyBracketOpenToken);
1127 this.stream.add(this.curlyBracketCloseToken);
1128 this.stream.add(this.semicolonToken);
1129 this.stream.add(this.squareBracketCloseToken);
1130 this.stream.add(this.semicolonToken);
1131 this.stream.add(this.endToken);
1132
1133 try {
1134 this.parser.parse();
1135 fail();
1136 } catch (final NoValidTokenStreamException e) {
1137 boolean noEqual = false;
1138 assertEquals(1, this.parser.getExceptions().size());
1139 for (final Exception ex : this.parser.getExceptions()) {
1140 if (ex instanceof NoEqualException) {
1141 noEqual = true;
1142 }
1143 }
1144 assertTrue(noEqual);
1145 }
1146 }
1147
1148
1149
1150
1151 @Test
1152 public void testNoEqualsExceptionClass() {
1153 this.stream = SimpleTokenStream.create();
1154 this.parser = Parser.create(this.stream);
1155 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
1156 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
1157 this.stream.add(myGroup);
1158 this.stream.add(this.colonToken);
1159 this.stream.add(this.groupToken);
1160 this.stream.add(this.equalToken);
1161 this.stream.add(this.squareBracketOpenToken);
1162 this.stream.add(myClass);
1163 this.stream.add(this.colonToken);
1164 this.stream.add(this.classToken);
1165 this.stream.add(this.curlyBracketOpenToken);
1166 this.stream.add(this.curlyBracketCloseToken);
1167 this.stream.add(this.semicolonToken);
1168 this.stream.add(this.squareBracketCloseToken);
1169 this.stream.add(this.semicolonToken);
1170 this.stream.add(this.endToken);
1171
1172 try {
1173 this.parser.parse();
1174 fail();
1175 } catch (final NoValidTokenStreamException e) {
1176 boolean noEqual = false;
1177 assertEquals(1, this.parser.getExceptions().size());
1178 for (final Exception ex : this.parser.getExceptions()) {
1179 if (ex instanceof NoEqualException) {
1180 noEqual = true;
1181 }
1182 }
1183 assertTrue(noEqual);
1184 }
1185 }
1186
1187
1188
1189
1190 @Test
1191 public void testNoGroupElementException() {
1192 this.stream = SimpleTokenStream.create();
1193 this.parser = Parser.create(this.stream);
1194 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
1195 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
1196 this.stream.add(myGroup);
1197 this.stream.add(this.colonToken);
1198 this.stream.add(this.groupToken);
1199 this.stream.add(this.equalToken);
1200 this.stream.add(this.squareBracketOpenToken);
1201 this.stream.add(myClass);
1202 this.stream.add(this.colonToken);
1203 this.stream.add(this.equalToken);
1204 this.stream.add(this.curlyBracketOpenToken);
1205 this.stream.add(this.curlyBracketCloseToken);
1206 this.stream.add(this.semicolonToken);
1207 this.stream.add(this.squareBracketCloseToken);
1208 this.stream.add(this.semicolonToken);
1209 this.stream.add(this.endToken);
1210
1211 try {
1212 this.parser.parse();
1213 fail();
1214 } catch (final NoValidTokenStreamException e) {
1215 boolean noGroupElement = false;
1216 assertEquals(1, this.parser.getExceptions().size());
1217 for (final Exception ex : this.parser.getExceptions()) {
1218 if (ex instanceof NoGroupElementException) {
1219 noGroupElement = true;
1220 }
1221 }
1222 assertTrue(noGroupElement);
1223 }
1224 }
1225
1226
1227
1228
1229 @Test
1230 public void testNoSquareBracketCloseException() {
1231 this.stream = SimpleTokenStream.create();
1232 this.parser = Parser.create(this.stream);
1233 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
1234 final IdentifierToken myClass = IdentifierToken.create("MyClass", Position.create("", 1, 1, 0));
1235 final IdentifierToken myAttribute = IdentifierToken.create("MyAttribute", Position.create("", 1, 1, 0));
1236 final IdentifierToken string = IdentifierToken.create("String", Position.create("", 1, 1, 0));
1237 final IdentifierToken integer = IdentifierToken.create("Integer", Position.create("", 1, 1, 0));
1238 this.stream.add(myGroup);
1239 this.stream.add(this.colonToken);
1240 this.stream.add(this.groupToken);
1241 this.stream.add(this.equalToken);
1242 this.stream.add(this.squareBracketOpenToken);
1243 this.stream.add(myClass);
1244 this.stream.add(this.colonToken);
1245 this.stream.add(this.classToken);
1246 this.stream.add(this.equalToken);
1247 this.stream.add(this.curlyBracketOpenToken);
1248 this.stream.add(myAttribute);
1249 this.stream.add(this.colonToken);
1250 this.stream.add(this.squareBracketOpenToken);
1251 this.stream.add(integer);
1252 this.stream.add(this.arrowToken);
1253 this.stream.add(string);
1254 this.stream.add(this.semicolonToken);
1255 this.stream.add(this.curlyBracketCloseToken);
1256 this.stream.add(this.semicolonToken);
1257 this.stream.add(this.squareBracketCloseToken);
1258 this.stream.add(this.semicolonToken);
1259 this.stream.add(this.endToken);
1260
1261 try {
1262 this.parser.parse();
1263 fail();
1264 } catch (final NoValidTokenStreamException e) {
1265 assertEquals(1, this.parser.getExceptions().size());
1266 boolean noSquareBracketClose = false;
1267 for (final Exception ex : this.parser.getExceptions()) {
1268 if (ex instanceof NoSquareBracketCloseException) {
1269 noSquareBracketClose = true;
1270 }
1271 }
1272 assertTrue(noSquareBracketClose);
1273 }
1274 }
1275
1276
1277
1278
1279 @Test
1280 public void testNoSquareBracketOpenException() {
1281 this.stream = SimpleTokenStream.create();
1282 this.parser = Parser.create(this.stream);
1283 final IdentifierToken myGroup = IdentifierToken.create("MyGroup", Position.create("", 1, 1, 0));
1284 this.stream.add(myGroup);
1285 this.stream.add(this.colonToken);
1286 this.stream.add(this.groupToken);
1287 this.stream.add(this.equalToken);
1288 this.stream.add(this.squareBracketCloseToken);
1289 this.stream.add(this.semicolonToken);
1290 this.stream.add(this.endToken);
1291
1292 try {
1293 this.parser.parse();
1294 fail();
1295 } catch (final NoValidTokenStreamException e) {
1296 boolean noSquareBracketOpen = false;
1297 assertEquals(1, this.parser.getExceptions().size());
1298 for (final Exception ex : this.parser.getExceptions()) {
1299 if (ex instanceof NoSquareBracketOpenException) {
1300 noSquareBracketOpen = true;
1301 }
1302 }
1303 assertTrue(noSquareBracketOpen);
1304 }
1305 }
1306 }