2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 import gov.nasa.jpf.annotation.MJI;
21 import gov.nasa.jpf.util.test.TestJPF;
22 import gov.nasa.jpf.vm.MJIEnv;
23 import gov.nasa.jpf.vm.NativePeer;
24 import gov.nasa.jpf.vm.Verify;
25 import org.junit.Test;
28 * regression test for Java 8 default methods
30 public class DefaultMethodTest extends TestJPF {
32 //------------------------------------------ non-ambiguous recursive lookup
35 default int getValue(){
40 interface B1 extends A1 {
44 static class C1 implements A1 {
48 static class D1 extends C1 {
53 public void testSingleMethod (){
54 if (verifyNoPropertyViolation()){
56 int result = o.getValue();
57 System.out.println(result);
58 assertTrue (result == 42);
62 //------------------------------------------ ambiguity resolution
65 default int getValue(){
70 static class D2 implements A1, B2 {
72 public int getValue(){
73 return A1.super.getValue() + B2.super.getValue();
78 public void testExplicitDelegation (){
79 if (verifyNoPropertyViolation()){
81 int result = o.getValue();
82 System.out.println(result);
83 assertTrue (result == 45);
87 //------------------------------------------- overloaded methods
90 default int foo (String s1, String s2){
91 System.out.println("this is E1.foo(String,String)");
95 default int foo (Object o1, Object o2){
96 System.out.println("this is E1.foo(Object,Object)");
101 static class F implements E1 {
107 int r = foo("blah", getId());
113 public void testOverloadedDefaults(){
114 if (verifyNoPropertyViolation()){
120 //----------------------------------------------- native peer for interface
123 default int foo (){ // should be intercepted by peer
124 System.out.println("this is bytecode G1.foo()");
129 static class H implements G1 {
132 //assertTrue(r == 42);
137 public void testInterfacePeer(){
138 if (verifyNoPropertyViolation()){
143 // -- most specific implementations
145 public static interface Intf1 {
146 default int getInt() {
151 public static interface Intf2 extends Intf1 {
153 default int getInt() {
157 public static abstract class A implements Intf1 {
161 public static class B extends A implements Intf2 {
165 public void testMostSpecificImplementationResolution() {
166 if(verifyNoPropertyViolation()) {
173 // --- inherited default methods
175 interface SuperIntf {
176 default String getString() {
177 return "Hello World";
181 interface SubIntf extends SuperIntf {
182 default int getZero() {
187 public class ConcreteClass implements SubIntf {
192 public void testInheritedDefaultMethod() {
193 if(verifyNoPropertyViolation()) {
194 ConcreteClass cls = new ConcreteClass();
195 assertEquals(cls.getString(), "Hello World");
199 // <2do> how to test IncompatibleClassChangeError without explicit classfile restore?