Mercurial > hg > Members > kono > jpf-core
comparison src/tests/java8/DefaultMethodTest.java @ 19:9fea3d8da9aa
!!! NOTE: this marks the beginning of Java 8 dependency for jpf-core compilation.
From now on, we are free to use default methods and lambdas.
added convenience Loggable and PrintStreamable interfaces that mix in the
respective fat interfaces via default methods, so that we don't have to burn
inheritance of respective target classes (they only have to provide getLogger()
and getPrintStream() methods)
added a abstract LoggablePeer so that model classes can implement Loggable with
intercepted/native logging if they provide a respective concrete peer.
added some more default interface method tests
author | Peter Mehlitz <pcmehlitz@gmail.com> |
---|---|
date | Wed, 01 Apr 2015 12:14:15 -0700 |
parents | 61d41facf527 |
children |
comparison
equal
deleted
inserted
replaced
18:a9ada67f1799 | 19:9fea3d8da9aa |
---|---|
15 * See the License for the specific language governing permissions and | 15 * See the License for the specific language governing permissions and |
16 * limitations under the License. | 16 * limitations under the License. |
17 */ | 17 */ |
18 package java8; | 18 package java8; |
19 | 19 |
20 import gov.nasa.jpf.annotation.MJI; | |
20 import gov.nasa.jpf.util.test.TestJPF; | 21 import gov.nasa.jpf.util.test.TestJPF; |
22 import gov.nasa.jpf.vm.MJIEnv; | |
23 import gov.nasa.jpf.vm.NativePeer; | |
21 import gov.nasa.jpf.vm.Verify; | 24 import gov.nasa.jpf.vm.Verify; |
22 import org.junit.Test; | 25 import org.junit.Test; |
23 | 26 |
24 /** | 27 /** |
25 * regression test for Java 8 default methods | 28 * regression test for Java 8 default methods |
78 int result = o.getValue(); | 81 int result = o.getValue(); |
79 System.out.println(result); | 82 System.out.println(result); |
80 assertTrue (result == 45); | 83 assertTrue (result == 45); |
81 } | 84 } |
82 } | 85 } |
83 | 86 |
84 | 87 //------------------------------------------- overloaded methods |
88 | |
89 interface E1 { | |
90 default int foo (String s1, String s2){ | |
91 System.out.println("this is E1.foo(String,String)"); | |
92 return 42; | |
93 } | |
94 | |
95 default int foo (Object o1, Object o2){ | |
96 System.out.println("this is E1.foo(Object,Object)"); | |
97 return 0; | |
98 } | |
99 } | |
100 | |
101 static class F implements E1 { | |
102 String getId() { | |
103 return "whatever"; | |
104 } | |
105 | |
106 void bar (){ | |
107 int r = foo("blah", getId()); | |
108 assertTrue(r == 42); | |
109 } | |
110 } | |
111 | |
112 @Test | |
113 public void testOverloadedDefaults(){ | |
114 if (verifyNoPropertyViolation()){ | |
115 F o = new F(); | |
116 o.bar(); | |
117 } | |
118 } | |
119 | |
120 //----------------------------------------------- native peer for interface | |
121 | |
122 interface G1 { | |
123 default int foo (){ // should be intercepted by peer | |
124 System.out.println("this is bytecode G1.foo()"); | |
125 return -1; | |
126 } | |
127 } | |
128 | |
129 static class H implements G1 { | |
130 void bar (){ | |
131 int r = foo(); | |
132 //assertTrue(r == 42); | |
133 } | |
134 } | |
135 | |
136 @Test | |
137 public void testInterfacePeer(){ | |
138 if (verifyNoPropertyViolation()){ | |
139 H o = new H(); | |
140 o.bar(); | |
141 } | |
142 } | |
143 | |
85 // <2do> how to test IncompatibleClassChangeError without explicit classfile restore? | 144 // <2do> how to test IncompatibleClassChangeError without explicit classfile restore? |
86 } | 145 } |
146 |