/*
* This file is part of the Jikes RVM project (http://jikesrvm.org).
*
* This file is licensed to You under the Eclipse Public License (EPL);
* You may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.opensource.org/licenses/eclipse-1.0.php
*
* See the COPYRIGHT.txt file distributed with this work for information
* regarding copyright ownership.
*/
package jikesRVM.core.bytecode;
import org.junit.Test;
import gov.nasa.jpf.annotation.Conditional;
import gov.nasa.jpf.util.test.TestJPF;
/**
* This class provides a test of Miranda methods.
*/
public class TestMiranda extends TestJPF {
static String[] JPF_CONFIGURATION = new String[] { "+nhandler.delegateUnhandledNative", "+search.class=.search.RandomSearch", "+choice=MapChoice" };
@Conditional
static boolean a = true;
@Test
public void main() {
if (verifyNoPropertyViolation(JPF_CONFIGURATION)) {
if (a) {
main(null);
}
}
}
/**
* A simple interface with a method in it
*/
static interface Interface {
/** A method that can be implemented */
int someMethod(int i, int j);
}
/**
* An abstract class implementing the interface, as it's abstract it doesn't
* need to implement the method thereby creating the abstract Miranda method
* (in this case called someMethod) that all sub-classes must implement
*/
private abstract static class AbstractClass implements Interface {
// NB someMethod isn't implemented!
}
/**
* A genuine implementation of AbstractClass that must implement someMethod
* declared in Interface
*/
private static class ConcreteClass extends AbstractClass {
/** Implementation of the Miranda method our test will call */
public int someMethod(int i, int j) {
return i * j;
}
}
/**
* Stand alone entry point
*/
public static void main(String[] args) {
AbstractClass test = new ConcreteClass();
testSomeClass(test);
}
/**
* Test calling of Miranda method
*
* @param test
* of type AbstractClass, therefore must have implementation of
* Interface
*/
// @NoInline
private static void testSomeClass(AbstractClass test) {
int result = test.someMethod(6, 7);
System.out.println("AbstractClass.someMethod(6,7) Expected: 42 Actual: " + result);
assertEquals(42, result);
}
}