Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6c44b85243bc3f28974788b18b87a2fd5635518d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
/**********************************************************************
 * This file is part of "Object Teams Development Tooling"-Software
 * 
 * Copyright 2004, 2015 IT Service Omikron GmbH and others.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * $Id$
 * 
 * Please visit http://www.eclipse.org/objectteams for updates and contact.
 * 
 * Contributors:
 * 	  Thomas Dudziak - Initial API and implementation
 * 	  Stephan Herrmann - Initial API and implementation
 **********************************************************************/
package org.eclipse.objectteams.otdt.tests.otjld.rolesandteams;

import org.eclipse.objectteams.otdt.tests.otjld.AbstractOTJLDTest;

import junit.framework.Test;

/**
 * Former jacks tests from section implicit-hierarchy-of-teams (1.2.*)
 * @author stephan 
 */
public class InheritanceHierarchyOfTeams extends AbstractOTJLDTest {

	public InheritanceHierarchyOfTeams(String name) {
		super(name);
	}
	
	// Static initializer to specify tests subset using TESTS_* static variables
	// All specified tests which does not belong to the class are skipped...
	static {
//		TESTS_NAMES = new String[] { "test127_nonTeamSuperclass1" };
//		TESTS_NUMBERS = new int[] { 1459 };
//		TESTS_RANGE = new int[] { 1097, -1 };
	}
	
	public static Test suite() {
		return buildComparableTestSuite(testClass());
	}

	public static Class testClass() {
		return InheritanceHierarchyOfTeams.class;
	}

    // a team has an explicit org.objectteams.Team superclass
    // 1.2.1-otjld-explicit-team-superclass
    public void test121_explicitTeamSuperclass() {
        runConformTest(
            new String[] {
		"Team121ets.java",
			    "\n" +
			    "public team class Team121ets extends org.objectteams.Team {}\n" +
			    "    \n"
            });
    }

    // a class that is not a team has an explicit org.objectteams.Team superclass
    // 1.2.2-otjld-team-superclass-not-allowed
    public void test122_teamSuperclassNotAllowed() {
        runNegativeTest(
            new String[] {
		"Team122tsna.java",
			    "\n" +
			    "public class Team122tsna extends org.objectteams.Team {}\n" +
			    "    \n"
            },
            null);
    }

    // a team class without super team implements multiple interfaces
    // 1.2.3-otjld-multiple-interfaces-1
    public void test123_multipleInterfaces1() {
        runConformTest(
            new String[] {
		"T123mi1Main.java",
			    "\n" +
			    "public class T123mi1Main {\n" +
			    "    public static void main(String[] args) {\n" +
			    "        Team123mi1 t  = new Team123mi1();\n" +
			    "        T123mi1_1  i1 = t;\n" +
			    "        T123mi1_2  i2 = (T123mi1_2)i1;\n" +
			    "\n" +
			    "        System.out.print(i2.getValue());\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"T123mi1_1.java",
			    "\n" +
			    "public interface T123mi1_1 {\n" +
			    "    void doSomething();\n" +
			    "}\n" +
			    "    \n",
		"T123mi1_2.java",
			    "\n" +
			    "public interface T123mi1_2 {\n" +
			    "    String getValue();\n" +
			    "}\n" +
			    "    \n",
		"Team123mi1.java",
			    "\n" +
			    "public team class Team123mi1 implements T123mi1_1, T123mi1_2 {\n" +
			    "    public void doSomething()\n" +
			    "    {}\n" +
			    "    public String getValue()\n" +
			    "    {\n" +
			    "        return \"OK\";\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n"
            },
            "OK");
    }

    // a team class with super team implements multiple interfaces
    // 1.2.3-otjld-multiple-interfaces-2
    public void test123_multipleInterfaces2() {
        runConformTest(
            new String[] {
		"T123mi2Main.java",
			    "\n" +
			    "public class T123mi2Main {\n" +
			    "    public static void main(String[] args) {\n" +
			    "        Team123mi2_2 t = new Team123mi2_2();\n" +
			    "\n" +
			    "        System.out.print(t.test());\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"T123mi2_1.java",
			    "\n" +
			    "public interface T123mi2_1 {\n" +
			    "    String getValue1();\n" +
			    "}\n" +
			    "    \n",
		"T123mi2_2.java",
			    "\n" +
			    "public interface T123mi2_2 {\n" +
			    "    String getValue2(T123mi2_1 obj);\n" +
			    "}\n" +
			    "    \n",
		"Team123mi2_1.java",
			    "\n" +
			    "public team class Team123mi2_1 implements T123mi2_2 {\n" +
			    "    public String getValue2(T123mi2_1 obj)\n" +
			    "    {\n" +
			    "        return obj.getValue1();\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"Team123mi2_2.java",
			    "\n" +
			    "public team class Team123mi2_2 extends Team123mi2_1 implements T123mi2_1 {\n" +
			    "    public String getValue1()\n" +
			    "    {\n" +
			    "        return \"OK\";\n" +
			    "    }\n" +
			    "    public String test()\n" +
			    "    {\n" +
			    "        return getValue2(this);\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n"
            },
            "OK");
    }

    // a team class without super team is cast to org.objectteams.Team
    // 1.2.4-otjld-cast-to-Team-1
    public void test124_castToTeam1() {
        runConformTest(
            new String[] {
		"T124ctT1Main.java",
			    "\n" +
			    "public class T124ctT1Main {\n" +
			    "    public static void main(String[] args) {\n" +
			    "        org.objectteams.Team t = new Team124ctT1();\n" +
			    "\n" +
			    "        t.activate();\n" +
			    "        t.deactivate();\n" +
			    "        System.out.print(\"OK\");\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"Team124ctT1.java",
			    "\n" +
			    "public team class Team124ctT1 {}\n" +
			    "    \n"
            },
            "OK");
    }

    // a team class with super team is cast to org.objectteams.Team
    // 1.2.4-otjld-cast-to-Team-2
    public void test124_castToTeam2() {
        runConformTest(
            new String[] {
		"T124ctT2Main.java",
			    "\n" +
			    "public class T124ctT2Main {\n" +
			    "    public static void main(String[] args) {\n" +
			    "        org.objectteams.Team t = new Team124ctT2_2();\n" +
			    "\n" +
			    "        t.activate();\n" +
			    "        t.deactivate();\n" +
			    "        System.out.print(\"OK\");\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"Team124ctT2_1.java",
			    "\n" +
			    "public team class Team124ctT2_1 {}\n" +
			    "    \n",
		"Team124ctT2_2.java",
			    "\n" +
			    "public team class Team124ctT2_2 extends Team124ctT2_1 {}\n" +
			    "    \n"
            },
            "OK");
    }

    // a team class is casted to its direct super team
    // 1.2.5-otjld-cast-to-supertam-1
    public void test125_castToSupertam1() {
        runConformTest(
            new String[] {
		"T125cts1Main.java",
			    "\n" +
			    "public class T125cts1Main {\n" +
			    "    public static void main(String[] args) {\n" +
			    "        Team125cts1_1 t1 = new Team125cts1_2();\n" +
			    "        Team125cts1_2 t2 = (Team125cts1_2)t1;\n" +
			    "\n" +
			    "        t2.activate();\n" +
			    "        t2.deactivate();\n" +
			    "        System.out.print(\"OK\");\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"Team125cts1_1.java",
			    "\n" +
			    "public team class Team125cts1_1 {}\n" +
			    "    \n",
		"Team125cts1_2.java",
			    "\n" +
			    "public team class Team125cts1_2 extends Team125cts1_1 {}\n" +
			    "    \n"
            },
            "OK");
    }

    // a team class is casted to an indirect super team
    // 1.2.5-otjld-cast-to-supertam-2
    public void test125_castToSupertam2() {
        runConformTest(
            new String[] {
		"T125cts2Main.java",
			    "\n" +
			    "public class T125cts2Main {\n" +
			    "    public static void main(String[] args) {\n" +
			    "        Team125cts2_1 t1 = new Team125cts2_4();\n" +
			    "        Team125cts2_3 t2 = (Team125cts2_3)t1;\n" +
			    "\n" +
			    "        t2.activate();\n" +
			    "        t2.deactivate();\n" +
			    "        System.out.print(\"OK\");\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"Team125cts2_1.java",
			    "\n" +
			    "public team class Team125cts2_1 {}\n" +
			    "    \n",
		"Team125cts2_2.java",
			    "\n" +
			    "public team class Team125cts2_2 extends Team125cts2_1 {}\n" +
			    "    \n",
		"Team125cts2_3.java",
			    "\n" +
			    "public team class Team125cts2_3 extends Team125cts2_2 {}\n" +
			    "    \n",
		"Team125cts2_4.java",
			    "\n" +
			    "public team class Team125cts2_4 extends Team125cts2_3 {}\n" +
			    "    \n"
            },
            "OK");
    }

    // a variable of a non-team type containg a team instance is cast to the team type
    // 1.2.6-otjld-cast-to-teamtype-1
    public void test126_castToTeamtype1() {
        runConformTest(
            new String[] {
		"T126ctt1Main.java",
			    "\n" +
			    "public class T126ctt1Main {\n" +
			    "    public static void main(String[] args) {\n" +
			    "        Object      o = new Team126ctt1();\n" +
			    "        Team126ctt1 t = (Team126ctt1)o;\n" +
			    "\n" +
			    "        t.activate();\n" +
			    "        t.deactivate();\n" +
			    "        System.out.print(\"OK\");\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"Team126ctt1.java",
			    "\n" +
			    "public team class Team126ctt1 {}\n" +
			    "    \n"
            },
            "OK");
    }

    // a variable of a non-team type containg a team instance is cast to org.objectteams.Team
    // 1.2.6-otjld-cast-to-teamtype-2
    public void test126_castToTeamtype2() {
        runConformTest(
            new String[] {
		"T126ctt2Main.java",
			    "\n" +
			    "public class T126ctt2Main {\n" +
			    "    public static void main(String[] args) {\n" +
			    "        Cloneable            c = new Team126ctt2();\n" +
			    "        org.objectteams.Team t = (org.objectteams.Team)c;\n" +
			    "\n" +
			    "        t.activate();\n" +
			    "        t.deactivate();\n" +
			    "        System.out.print(\"OK\");\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"Team126ctt2.java",
			    "\n" +
			    "public team class Team126ctt2 implements Cloneable {}\n" +
			    "    \n"
            },
            "OK");
    }

    // a team class has a regular class as its explicit superclass - this class is also bound as a role's base class - two level team hierarchy
    // 1.2.7-otjld-non-team-superclass-1
    public void test127_nonTeamSuperclass1a() {
        runConformTest(
            new String[] {
		"Team127nts1a_2.java",
			    "\n" +
			    "public team class Team127nts1a_2 extends Team127nts1a_1 {\n" +
			    "    public void hello() {\n" +
			    "        System.out.print(\"hello\");\n" +
			    "    }\n" +
			    "    public void world() {\n" +
			    "        System.out.print(\"world\");\n" +
			    "    }\n" +
			    "    public static void main(String[] args) {\n" +
			    "        Team127nts1a_2 t = new Team127nts1a_2();\n" +
			    "        t.activate();\n" +
			    "        t.hello();\n" +
			    "        t.world();\n" +
			    "        System.out.print(t.getAllRoles().length);\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"T127nts1a.java",
			    "\n" +
			    "public class T127nts1a {\n" +
			    "    public void hello() {\n" +
			    "        System.out.print(\"wrong\");\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"Team127nts1a_1.java",
			    "\n" +
			    "public team class Team127nts1a_1 extends T127nts1a {\n" +
			    "    protected class R playedBy T127nts1a {\n" +
			    "        void blank() {\n" +
			    "            System.out.print(\" \");\n" +
			    "        }\n" +
			    "        blank <- after hello;\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n"
            },
            "hello world1");
    }

    // replace callin:
    public void test127_nonTeamSuperclass1b() {
        runConformTest(
            new String[] {
		"Team127nts1b_2.java",
			    "\n" +
			    "public team class Team127nts1b_2 extends Team127nts1b_1 {\n" +
			    "    public void hello() {\n" +
			    "        System.out.print(\"hello\");\n" +
			    "    }\n" +
			    "    public void world() {\n" +
			    "        System.out.print(\"world\");\n" +
			    "    }\n" +
			    "    public static void main(String[] args) {\n" +
			    "        Team127nts1b_2 t = new Team127nts1b_2();\n" +
			    "        t.activate();\n" +
			    "        t.hello();\n" +
			    "        t.world();\n" +
			    "        System.out.print(t.getAllRoles().length);\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"T127nts1b.java",
			    "\n" +
			    "public class T127nts1b {\n" +
			    "    public void hello() {\n" +
			    "        System.out.print(\"wrong\");\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"Team127nts1b_1.java",
			    "\n" +
			    "public team class Team127nts1b_1 extends T127nts1b {\n" +
			    "    protected class R playedBy T127nts1b {\n" +
			    "        callin void blank() {\n" +
			    "            base.blank();\n" +
			    "            System.out.print(\" \");\n" +
			    "        }\n" +
			    "        blank <- replace hello;\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n"
            },
            "hello world1");
    }

    // before static
    public void test127_nonTeamSuperclass1c() {
        runConformTest(
            new String[] {
		"Team127nts1c_2.java",
			    "\n" +
			    "public team class Team127nts1c_2 extends Team127nts1c_1 {\n" +
			    "    public void hello() {\n" +
			    "        System.out.print(\"hello\");\n" +
			    "    }\n" +
			    "    public static void world() {\n" +
			    "        System.out.print(\"wrong\");\n" +
			    "    }\n" +
			    "    public static void main(String[] args) {\n" +
			    "        Team127nts1c_2 t = new Team127nts1c_2();\n" +
			    "        t.activate();\n" +
			    "        t.hello();\n" +
			    "        T127nts1c.world();\n" +
			    "        System.out.print(t.getAllRoles().length);\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"T127nts1c.java",
			    "\n" +
			    "public class T127nts1c {\n" +
			    "    public static void world() {\n" +
			    "        System.out.print(\"world\");\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n",
		"Team127nts1c_1.java",
			    "\n" +
			    "public team class Team127nts1c_1 extends T127nts1c {\n" +
			    "    protected class R playedBy T127nts1c {\n" +
			    "        static void blank() {\n" +
			    "            System.out.print(\" \");\n" +
			    "        }\n" +
			    "        blank <- before world;\n" +
			    "    }\n" +
			    "}\n" +
			    "    \n"
            },
            "hello world0");
    }

    // a team class has a superclass that is not a team
    // 1.2.7-otjld-non-team-superclass-2
    public void test127_nonTeamSuperclass2() {
        runConformTest(
            new String[] {
		"T127nts2.java",
			    "\n" +
			    "public class T127nts2 {}\n" +
			    "    \n",
		"Team127nts2.java",
			    "\n" +
			    "public team class Team127nts2 extends T127nts2 {}\n" +
			    "    \n"
            });
    }
    
    // a nested team has a non-team superclass
    public void test127_nonTeamSuperclass3() {
    	runConformTest(
    		new String[] {
    	"Team127nts3.java",
    			"public team class Team127nts3 {\n" +
    			"	protected team class Inner extends T127nts3 {}\n" +
    			"	void test() {\n" +
    			"		new Inner().test();\n" +
    			"	}\n" +
    			"	public static void main(String... args) {\n" +
    			"		new Team127nts3().test();\n" +
    			"	}\n" +
    			"}\n",
    	"T127nts3.java",
    			"public class T127nts3 {\n" +
    			"	public void test() {\n" +
    			"		System.out.println(\"OK\");\n" +
    			"	}\n" +
    			"}\n"
    		},
    		"OK");
    }

    // a non-abstract team class has an interface that is does not implement
    // 1.2.8-otjld-interface-not-implemented
    public void test128_interfaceNotImplemented() {
        runNegativeTest(
            new String[] {
		"T128ini.java",
			    "\n" +
			    "public interface T128ini {\n" +
			    "    void doSomething();\n" +
			    "}\n" +
			    "    \n",
		"Team128ini.java",
			    "\n" +
			    "public team class Team128ini implements T128ini {}\n" +
			    "    \n"
            },
            null);
    }

    // role inheritance from super team and sub team together yields a circle - StackOverflowError reported by jogeb
    // 1.2.9-otjld-circular-role-inheritance-1
    public void test129_circularRoleInheritance1() {
        runNegativeTestMatching(
            new String[] {
		"Team129cri1_1.java",
			    "\n" +
			    "public team class Team129cri1_1 {\n" +
			    "    protected class R1 {}\n" +
			    "    protected class R2 extends R1 {}\n" +
			    "}\n" +
			    "    \n",
		"Team129cri1_2.java",
			    "\n" +
			    "public team class Team129cri1_2 extends Team129cri1_1 {\n" +
			    "    protected class R1 extends R2 {}\n" +
			    "    protected class R2 {}\n" +
			    "}\n" +
			    "    \n"
            },
            "cycle");
    }

    public void testBug506740() {
    	runConformTest(
    		new String[] {
    			"b/Base.java",
    			"package b;\n" +
    			"public class Base {\n" +
    			"	private String f1 = \"f1\";\n" +
    			"	private String f2 = \"f2\";\n" +
    			"	private String f3 = \"f3\";\n" +
    			"	private String f4 = \"f4\";\n" +
    			"	private String f5 = \"f5\";\n" +
    			"}\n",
    			"t/Team1.java",
    			"package t;\n" +
    			"public team class Team1 {\n" +
    			"	@SuppressWarnings(\"decapsulation\")\n" +
    			"	protected class R playedBy b.Base {\n" +
    			"		protected R() { base(); }\n" +
    			"		protected String getF1() -> get String f1;\n" +
    			"		protected String getF2() -> get String f2;\n" +
    			"	}\n" +
    			"}\n"
    		});
    	runConformTest(
    		false, // no flush
    		new String[] {
    			"t/Team2.java",
    			"package t;\n" +
    			"public team class Team2 extends Team1 {\n" +
    			"	@Override\n" +
    			"	@SuppressWarnings(\"decapsulation\")\n" +
    			"	protected class R {\n" +
    			"		protected String getF3() -> get String f3;\n" +
    			"		protected String getF4() -> get String f4;\n" +
    			"	}\n" +
    			"	void test() {\n" +
    			"		R r = new R();\n" +
    			"		System.out.print(r.getF1()+r.getF2()+r.getF3()+r.getF4());\n" +
    			"	}\n" +
    			"	public static void main(String... args) {\n" +
    			"		new Team2().test();\n" +
    			"	}\n" +
    			"}\n"
    		},
    		"",
    		"f1f2f3f4",
    		"",
    		null /* javacOptions */);
    	runConformTest(
    		false, // no flush
    		new String[] {
    			"t/Team3.java",
    			"package t;\n" +
    			"public team class Team3 extends Team2 {\n" +
    			"	@Override\n" +
    			"	@SuppressWarnings(\"decapsulation\")\n" +
    			"	protected class R {\n" +
    			"		protected String getF5() -> get String f5;\n" +
    			"	}\n" +
    			"	void test() {\n" +
    			"		R r = new R();\n" +
    			"		System.out.print(r.getF1()+r.getF2()+r.getF3()+r.getF4()+r.getF5());\n" +
    			"	}\n" +
    			"	public static void main(String... args) {\n" +
    			"		new Team3().test();\n" +
    			"	}\n" +
    			"}\n"
    		},
    		"",
    		"f1f2f3f4f5",
    		"",
    		null /* javacOptions */);
    }
}

Back to the top