1 /*
   2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * Test Data used for testing default/static method
  26  *
  27  * @author Yong Lu
  28  */
  29 
  30 import java.util.Arrays;
  31 import java.util.List;
  32 
  33 import org.testng.annotations.DataProvider;
  34 import org.testng.collections.Lists;
  35 
  36 import static helper.Mod.*;
  37 import static helper.Declared.*;
  38 import helper.Mod;
  39 import helper.Declared;
  40 import java.lang.annotation.Repeatable;
  41 import java.lang.annotation.Retention;
  42 import java.lang.annotation.RetentionPolicy;
  43 
  44 @MethodDesc(name = "defaultMethod", retval = "TestIF1.defaultMethod", mod = DEFAULT, declared = YES)
  45 interface TestIF1 {
  46 
  47     default String defaultMethod() {
  48         return "TestIF1.defaultMethod";
  49     }
  50 }
  51 
  52 @MethodDesc(name = "defaultMethod", retval = "TestIF1.defaultMethod", mod = DEFAULT, declared = NO)
  53 class TestClass1 implements TestIF1 {
  54 }
  55 
  56 @MethodDesc(name = "staticMethod", retval = "TestIF2.staticMethod", mod = STATIC, declared = YES)
  57 interface TestIF2 {
  58 
  59     static String staticMethod() {
  60         return "TestIF2.staticMethod";
  61     }
  62 }
  63 
  64 @MethodDesc(name = "method", retval = "TestIF2.staticMethod", mod = REGULAR, declared = YES)
  65 class TestClass2 implements TestIF2 {
  66 
  67     public String method() {
  68         return TestIF2.staticMethod();
  69     }
  70 }
  71 
  72 @MethodDesc(name = "defaultMethod", retval = "TestIF3.defaultMethod", mod = DEFAULT, declared = YES)
  73 @MethodDesc(name = "method", retval = "", mod = ABSTRACT, declared = YES)
  74 interface TestIF3 {
  75 
  76     String method();
  77 
  78     default String defaultMethod() {
  79         return "TestIF3.defaultMethod";
  80     }
  81 }
  82 
  83 @MethodDesc(name = "defaultMethod", retval = "TestIF3.defaultMethod", mod = DEFAULT, declared = NO)
  84 @MethodDesc(name = "method", retval = "TestClass3.method", mod = REGULAR, declared = YES)
  85 class TestClass3 implements TestIF3 {
  86 
  87     public String method() {
  88         return "TestClass3.method";
  89     }
  90 }
  91 
  92 @MethodDesc(name = "staticMethod", retval = "TestIF4.staticMethod", mod = STATIC, declared = YES)
  93 @MethodDesc(name = "method", retval = "", mod = ABSTRACT, declared = YES)
  94 interface TestIF4 {
  95 
  96     String method();
  97 
  98     static String staticMethod() {
  99         return "TestIF4.staticMethod";
 100     }
 101 }
 102 
 103 @MethodDesc(name = "method", retval = "TestClass4.method", mod = REGULAR, declared = YES)
 104 class TestClass4 implements TestIF4 {
 105 
 106     public String method() {
 107         return "TestClass4.method";
 108     }
 109 }
 110 
 111 @MethodDesc(name = "defaultMethod", retval = "TestIF5.defaultMethod", mod = DEFAULT, declared = YES)
 112 @MethodDesc(name = "staticMethod", retval = "TestIF5.staticMethod", mod = STATIC, declared = YES)
 113 interface TestIF5 {
 114 
 115     default String defaultMethod() {
 116         return "TestIF5.defaultMethod";
 117     }
 118 
 119     static String staticMethod() {
 120         return "TestIF5.staticMethod";
 121     }
 122 }
 123 
 124 @MethodDesc(name = "defaultMethod", retval = "TestIF5.defaultMethod", mod = DEFAULT, declared = NO)
 125 class TestClass5 implements TestIF5 {
 126 }
 127 
 128 @MethodDesc(name = "defaultMethod", retval = "TestIF6.defaultMethod", mod = DEFAULT, declared = YES)
 129 @MethodDesc(name = "staticMethod", retval = "TestIF6.staticMethod", mod = STATIC, declared = YES)
 130 @MethodDesc(name = "method", retval = "", mod = ABSTRACT, declared = YES)
 131 interface TestIF6 {
 132 
 133     String method();
 134 
 135     default String defaultMethod() {
 136         return "TestIF6.defaultMethod";
 137     }
 138 
 139     static String staticMethod() {
 140         return "TestIF6.staticMethod";
 141     }
 142 }
 143 
 144 @MethodDesc(name = "defaultMethod", retval = "TestIF6.defaultMethod", mod = DEFAULT, declared = NO)
 145 @MethodDesc(name = "method", retval = "TestClass6.method", mod = REGULAR, declared = YES)
 146 class TestClass6 implements TestIF6 {
 147 
 148     public String method() {
 149         return "TestClass6.method";
 150     }
 151 }
 152 
 153 @MethodDesc(name = "defaultMethod", retval = "TestIF7.TestClass7", mod = DEFAULT, declared = YES)
 154 interface TestIF7<T> {
 155 
 156     default T defaultMethod(T t) {
 157         return t;
 158     }
 159 }
 160 
 161 @MethodDesc(name = "defaultMethod", retval = "TestIF7.TestClass7", mod = DEFAULT, declared = NO)
 162 class TestClass7<T> implements TestIF7<T> {
 163 }
 164 
 165 @MethodDesc(name = "defaultMethod", retval = "TestIF8.TestClass8", mod = DEFAULT, declared = YES)
 166 interface TestIF8<E> {
 167 
 168     default <E> E defaultMethod(E e) {
 169         return e;
 170     }
 171 }
 172 
 173 @MethodDesc(name = "defaultMethod", retval = "TestIF8.TestClass8", mod = DEFAULT, declared = NO)
 174 class TestClass8<T> implements TestIF8<T> {
 175 }
 176 
 177 @MethodDesc(name = "defaultMethod", retval = "TestIF9.defaultMethod", mod = DEFAULT, declared = YES)
 178 interface TestIF9 extends TestIF1 {
 179 
 180     default String defaultMethod() {
 181         return "TestIF9.defaultMethod";
 182     }
 183 }
 184 
 185 @MethodDesc(name = "defaultMethod", retval = "TestIF9.defaultMethod", mod = DEFAULT, declared = NO)
 186 class TestClass9 implements TestIF9 {
 187 }
 188 
 189 @MethodDesc(name = "defaultMethod", retval = "TestIF9.defaultMethod", mod = DEFAULT, declared = NO)
 190 @MethodDesc(name = "method", retval = "TestIF9.defaultMethod", mod = REGULAR, declared = YES)
 191 class TestClass91 implements TestIF9, TestIF1 {
 192 
 193     public String method() {
 194         return defaultMethod();
 195     }
 196 }
 197 
 198 @MethodDesc(name = "staticMethod", retval = "TestIF10.staticMethod", mod = STATIC, declared = YES)
 199 interface TestIF10 extends TestIF2 {
 200 
 201     static String staticMethod() {
 202 
 203         return "TestIF10.staticMethod";
 204     }
 205 }
 206 
 207 @MethodDesc(name = "staticMethod", retval = "TestIF11.staticMethod", mod = STATIC, declared = YES)
 208 @MethodDesc(name = "defaultMethod", retval = "TestIF1.defaultMethod", mod = DEFAULT, declared = NO)
 209 interface TestIF11 extends TestIF1 {
 210 
 211     static String staticMethod() {
 212         return "TestIF11.staticMethod";
 213     }
 214 }
 215 
 216 @MethodDesc(name = "defaultMethod", retval = "TestIF1.defaultMethod", mod = DEFAULT, declared = NO)
 217 class TestClass11 implements TestIF11 {
 218 }
 219 
 220 @MethodDesc(name = "defaultMethod", retval = "TestIF12.defaultMethod", mod = DEFAULT, declared = YES)
 221 interface TestIF12 extends TestIF2 {
 222 
 223     default String defaultMethod() {
 224         return "TestIF12.defaultMethod";
 225     }
 226 }
 227 
 228 @MethodDesc(name = "defaultMethod", retval = "TestIF12.defaultMethod", mod = DEFAULT, declared = NO)
 229 class TestClass12 implements TestIF12 {
 230 }
 231 
 232 //Diamond Case
 233 @MethodDesc(name = "defaultMethod", retval = "TestIF1.defaultMethod", mod = DEFAULT, declared = NO)
 234 interface TestIF1A extends TestIF1 {
 235 }
 236 
 237 @MethodDesc(name = "defaultMethod", retval = "TestIF1.defaultMethod", mod = DEFAULT, declared = NO)
 238 interface TestIF1B extends TestIF1 {
 239 }
 240 
 241 @MethodDesc(name = "defaultMethod", retval = "TestIF1.defaultMethod", mod = DEFAULT, declared = NO)
 242 class TestClass13 implements TestIF1A, TestIF1B {
 243 }
 244 
 245 //Diamond Override Case
 246 @MethodDesc(name = "defaultMethod", retval = "TestIF1C.defaultMethod", mod = DEFAULT, declared = YES)
 247 interface TestIF1C extends TestIF1 {
 248 
 249     default String defaultMethod() {
 250         return "TestIF1C.defaultMethod";
 251     }
 252 }
 253 
 254 @MethodDesc(name = "defaultMethod", retval = "TestIF1D.defaultMethod", mod = DEFAULT, declared = YES)
 255 interface TestIF1D extends TestIF1 {
 256 
 257     default String defaultMethod() {
 258         return "TestIF1D.defaultMethod";
 259     }
 260 }
 261 
 262 @MethodDesc(name = "defaultMethod", retval = "TestClass14.defaultMethod", mod = REGULAR, declared = YES)
 263 class TestClass14 implements TestIF1C, TestIF1D {
 264 
 265     public String defaultMethod() {
 266         return "TestClass14.defaultMethod";
 267     }
 268 }
 269 
 270 @MethodDesc(name = "defaultMethod", retval = "", mod = ABSTRACT, declared = YES)
 271 interface TestIF15 extends TestIF1 {
 272 
 273     String defaultMethod();
 274 }
 275 
 276 @MethodDesc(name = "defaultMethod", retval = "TestClass15.defaultMethod", mod = REGULAR, declared = YES)
 277 class TestClass15 implements TestIF15 {
 278 
 279     public String defaultMethod() {
 280         return "TestClass15.defaultMethod";
 281     }
 282 }
 283 
 284 interface FuncInterface<T> {
 285 
 286     String test(T t);
 287 }
 288 
 289 @MethodDesc(name = "defaultMethod", retval = "TestIF16.defaultMethod", mod = DEFAULT, declared = YES)
 290 interface TestIF16 {
 291 
 292     default String defaultMethod() {
 293         FuncInterface<Object> fi = o -> o.toString();
 294         Object o = "TestIF16.defaultMethod";
 295         return fi.test(o);
 296     }
 297 }
 298 
 299 @MethodDesc(name = "defaultMethod", retval = "TestIF16.defaultMethod", mod = DEFAULT, declared = NO)
 300 class TestClass16 implements TestIF16 {
 301 }
 302 
 303 @MethodDesc(name = "defaultMethod", retval = "TestIF17.defaultMethod", mod = DEFAULT, declared = YES)
 304 @MethodDesc(name = "staticMethod", retval = "TestIF17.staticMethod", mod = STATIC, declared = YES)
 305 interface TestIF17 {
 306 
 307     default String defaultMethod() {
 308         return staticMethod().replace("staticMethod", "defaultMethod");
 309     }
 310 
 311     public static String staticMethod() {
 312         return "TestIF17.staticMethod";
 313     }
 314 }
 315 
 316 @MethodDesc(name = "defaultMethod", retval = "TestIF17.defaultMethod", mod = DEFAULT, declared = NO)
 317 class TestClass17 implements TestIF17 {
 318 }
 319 
 320 
 321 @MethodDesc(name = "defaultMethod", retval = "TestIF17.defaultMethod", mod = DEFAULT, declared = NO)
 322 class TestClass18 extends TestClass17 {
 323 }
 324 
 325 
 326 @Retention(RetentionPolicy.RUNTIME)
 327 @Repeatable(MethodDescs.class)
 328 @interface MethodDesc {
 329     String name();
 330     String retval();
 331     Mod mod();
 332     Declared declared();
 333 }
 334 
 335 @Retention(RetentionPolicy.RUNTIME)
 336 @interface MethodDescs {
 337     MethodDesc[] value();
 338 }
 339 
 340 //Diamond Case for static method
 341 @MethodDesc(name = "staticMethod", retval = "TestIF2A.staticMethod", mod = STATIC, declared = YES)
 342 interface TestIF2A extends TestIF2 {
 343     static String staticMethod() {
 344         return "TestIF2A.staticMethod";
 345     }
 346 }
 347 
 348 @MethodDesc(name = "method", retval = "", mod = ABSTRACT, declared = YES)
 349 interface TestIF2B extends TestIF2 {
 350     String method();
 351 }
 352 
 353 @MethodDesc(name = "method", retval = "", mod = ABSTRACT, declared = YES)
 354 interface TestIF18 extends TestIF10, TestIF2A {
 355     String method();
 356 }
 357 
 358 @MethodDesc(name = "method", retval = "", mod = ABSTRACT, declared = NO)
 359 @MethodDesc(name = "defaultMethod", retval = "TestIF12.defaultMethod", mod = DEFAULT, declared = NO)
 360 interface TestIF19 extends TestIF12, TestIF2B {
 361 }
 362 
 363 @MethodDesc(name = "staticMethod", retval = "TestIF20.staticMethod", mod = STATIC, declared = YES)
 364 @MethodDesc(name = "defaultMethod", retval = "TestIF12.defaultMethod", mod = DEFAULT, declared = NO)
 365 interface TestIF20 extends TestIF12, TestIF2A {
 366     static String staticMethod() {
 367         return "TestIF20.staticMethod";
 368     }
 369 }
 370 
 371 @MethodDesc(name = "method", retval = "", mod = ABSTRACT, declared = NO)
 372 interface TestIF21 extends TestIF2A, TestIF2B {
 373 }
 374 
 375 public class DefaultStaticTestData {
 376 
 377     /**
 378      * Test data for DefaultStaticInvokeTest The format of inner array is: First
 379      * data is the name of the class under test Second data used in test as the
 380      * arguments used for the method call.
 381      */
 382     @DataProvider
 383     static Object[][] testClasses() {
 384         return new Object[][]{
 385             {"TestClass1", null},
 386             {"TestClass2", null},
 387             {"TestClass3", null},
 388             {"TestClass4", null},
 389             {"TestClass5", null},
 390             {"TestClass6", null},
 391             {"TestClass7", "TestIF7.TestClass7"},
 392             {"TestClass8", "TestIF8.TestClass8"},
 393             {"TestClass9", null},
 394             {"TestClass91", null},
 395             {"TestClass11", null},
 396             {"TestClass12", null},
 397             {"TestClass13", null},
 398             {"TestClass14", null},
 399             {"TestClass15", null},
 400             {"TestClass16", null},
 401             {"TestClass17", null},
 402             {"TestClass18", null},
 403         };
 404     }
 405 
 406     /**
 407      * Test data for DefaultStaticInvokeTest The format of inner array is: First
 408      * data is the name of the interface under test Second data used in test as
 409      * the arguments used for the method call.
 410      */
 411     @DataProvider
 412     static Object[][] testInterfaces() {
 413         return new Object[][]{
 414             {"TestIF1", null},
 415             {"TestIF2", null},
 416             {"TestIF2A", null},
 417             {"TestIF2B", null},
 418             {"TestIF3", null},
 419             {"TestIF4", null},
 420             {"TestIF5", null},
 421             {"TestIF6", null},
 422             {"TestIF7", "TestIF7.TestClass7"},
 423             {"TestIF8", "TestIF8.TestClass8"},
 424             {"TestIF9", null},
 425             {"TestIF10", null},
 426             {"TestIF11", null},
 427             {"TestIF12", null},
 428             {"TestIF1A", null},
 429             {"TestIF1B", null},
 430             {"TestIF1C", null},
 431             {"TestIF1D", null},
 432             {"TestIF15", null},
 433             {"TestIF16", null},
 434             {"TestIF17", null},
 435             {"TestIF18", null},
 436             {"TestIF19", null},
 437             {"TestIF20", null},
 438             {"TestIF21", null},
 439         };
 440     }
 441 
 442     @DataProvider
 443     static Object[][] testCasesAll() {
 444         List<Object[]> result = Lists.newArrayList();
 445         result.addAll(Arrays.asList(testClasses()));
 446         result.addAll(Arrays.asList(testInterfaces()));
 447         return result.toArray(new Object[result.size()][]);
 448     }
 449 }