| /******************************************************************************* |
| * Copyright (c) 2014, 2016 IBM Corporation 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 |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.pde.api.tools.comparator.tests; |
| |
| import org.eclipse.pde.api.tools.internal.provisional.VisibilityModifiers; |
| import org.eclipse.pde.api.tools.internal.provisional.comparator.ApiComparator; |
| import org.eclipse.pde.api.tools.internal.provisional.comparator.DeltaProcessor; |
| import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta; |
| import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline; |
| import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent; |
| |
| import junit.framework.Test; |
| import junit.framework.TestSuite; |
| |
| /** |
| * Delta tests for java 8 |
| */ |
| |
| public class Java8DeltaTests extends DeltaTestSetup { |
| public static Test suite() { |
| return new TestSuite(Java8DeltaTests.class); |
| |
| } |
| |
| public Java8DeltaTests(String name) { |
| super(name); |
| } |
| |
| @Override |
| public String getTestRoot() { |
| return "java8"; //$NON-NLS-1$ |
| } |
| |
| /** |
| * Check change Anonymous class gets turned into a lambda expression |
| */ |
| public void test1() { |
| deployBundles("test1"); //$NON-NLS-1$ |
| IApiBaseline before = getBeforeState(); |
| IApiBaseline after = getAfterState(); |
| IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); |
| assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ |
| IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); |
| assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ |
| IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, VisibilityModifiers.ALL_VISIBILITIES, null); |
| assertNotNull("No delta", delta); //$NON-NLS-1$ |
| assertTrue("Should be NO_DELTA", delta == ApiComparator.NO_DELTA); //$NON-NLS-1$ |
| |
| } |
| |
| /** |
| * Check delta in Method call -> method reference |
| */ |
| public void test2() { |
| deployBundles("test2"); //$NON-NLS-1$ |
| IApiBaseline before = getBeforeState(); |
| IApiBaseline after = getAfterState(); |
| IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); |
| assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ |
| IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); |
| assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ |
| IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, VisibilityModifiers.ALL_VISIBILITIES, null); |
| assertNotNull("No delta", delta); //$NON-NLS-1$ |
| assertTrue("Should be NO_DELTA", delta == ApiComparator.NO_DELTA); //$NON-NLS-1$ |
| } |
| |
| /** |
| * Check Interface method becomes a default method |
| */ |
| public void test3() { |
| deployBundles("test3"); //$NON-NLS-1$ |
| IApiBaseline before = getBeforeState(); |
| IApiBaseline after = getAfterState(); |
| IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); |
| assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ |
| IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); |
| assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ |
| IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, VisibilityModifiers.ALL_VISIBILITIES, null); |
| assertNotNull("No delta", delta); //$NON-NLS-1$ |
| IDelta[] allLeavesDeltas = collectLeaves(delta); |
| assertEquals("Wrong size", 2, allLeavesDeltas.length); //$NON-NLS-1$ |
| IDelta child = allLeavesDeltas[0]; |
| assertEquals("Wrong kind", IDelta.CHANGED, child.getKind()); //$NON-NLS-1$ |
| assertEquals("Wrong flag", IDelta.ABSTRACT_TO_NON_ABSTRACT, child.getFlags()); //$NON-NLS-1$ |
| assertEquals("Wrong element type", IDelta.METHOD_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ |
| assertTrue("Is compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ |
| child = allLeavesDeltas[1]; |
| assertEquals("Wrong kind", IDelta.REMOVED, child.getKind()); //$NON-NLS-1$ |
| assertEquals("Wrong flag", IDelta.METHOD, child.getFlags()); //$NON-NLS-1$ |
| assertEquals("Wrong element type", IDelta.CLASS_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ |
| assertFalse("Is compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ |
| } |
| |
| /** |
| * Check if default method addition in an interface is compatible |
| */ |
| public void test4() { |
| deployBundles("test4"); //$NON-NLS-1$ |
| IApiBaseline before = getBeforeState(); |
| IApiBaseline after = getAfterState(); |
| IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); |
| assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ |
| IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); |
| assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ |
| IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, |
| VisibilityModifiers.ALL_VISIBILITIES, null); |
| assertNotNull("No delta", delta); //$NON-NLS-1$ |
| assertTrue("Not compatible", !DeltaProcessor.isCompatible(delta)); //$NON-NLS-1$ |
| } |
| |
| /** |
| * Check if non-default method addition in an interface is non-compatible |
| */ |
| public void test5() { |
| deployBundles("test5"); //$NON-NLS-1$ |
| IApiBaseline before = getBeforeState(); |
| IApiBaseline after = getAfterState(); |
| IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); |
| assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ |
| IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); |
| assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ |
| IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, |
| VisibilityModifiers.ALL_VISIBILITIES, null); |
| assertNotNull("No delta", delta); //$NON-NLS-1$ |
| assertFalse("Is compatible", DeltaProcessor.isCompatible(delta)); //$NON-NLS-1$ |
| } |
| |
| } |