Skip to content

Commit

Permalink
#275 fixed failing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
siom79 committed Dec 30, 2020
1 parent b9d20fb commit 79c58b4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public List<CtClass> createOldClasses(ClassPool classPool) throws Exception {
@Override
public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
CtClass typeCtClass = CtClassBuilder.create().name("japicmp.SuperType").addToClassPool(classPool);
CtClass ctClass = CtClassBuilder.create().name("japicmp.Test").withSuperclass(classPool.get("java.lang.String")).addToClassPool(classPool);
CtClass ctClass = CtClassBuilder.create().name("japicmp.Test").withSuperclass(classPool.get("java.text.SimpleDateFormat")).addToClassPool(classPool);
return Arrays.asList(typeCtClass, ctClass);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ public JApiSuperclass callback(JApiClass clazz, Map<String, JApiClass> classMap,
checkIfMethodsHaveChangedIncompatible(interfaceClass, classMap);
checkIfFieldsHaveChangedIncompatible(interfaceClass, classMap);
} else if (implementedInterface.getChangeStatus() == JApiChangeStatus.NEW) {
addCompatibilityChange(jApiClass, JApiCompatibilityChange.INTERFACE_ADDED);
if (interfaceClass.getMethods().size() > 0) { //no marker interface
boolean allInterfaceMethodsImplemented = true;
for (JApiMethod interfaceMethod : interfaceClass.getMethods()) {
Expand All @@ -714,7 +715,7 @@ public JApiSuperclass callback(JApiClass clazz, Map<String, JApiClass> classMap,
}
}
if (!allInterfaceMethodsImplemented) {
addCompatibilityChange(jApiClass, JApiCompatibilityChange.INTERFACE_ADDED);
addCompatibilityChange(jApiClass, JApiCompatibilityChange.METHOD_ABSTRACT_ADDED_IN_IMPLEMENTED_INTERFACE);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions japicmp/src/main/java/japicmp/compat/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package japicmp.compat;

import java.text.SimpleDateFormat;

public class Test extends SimpleDateFormat {
}
6 changes: 4 additions & 2 deletions japicmp/src/test/java/japicmp/cmp/InterfacesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,18 @@ public void testInterfaceAdded() throws Exception {
@Override
public List<CtClass> createOldClasses(ClassPool classPool) throws Exception {
CtClass superInterface = CtInterfaceBuilder.create().name("Interface").addToClassPool(classPool);
CtMethodBuilder.create().publicAccess().abstractMethod().name("method").addToClass(superInterface);
CtMethodBuilder.create().publicAccess().abstractMethod().returnType(CtClass.voidType).name("method").addToClass(superInterface);
CtClass ctClass = CtClassBuilder.create().name("Test").addToClassPool(classPool);
CtMethodBuilder.create().publicAccess().returnType(CtClass.voidType).name("method").addToClass(ctClass);
return Arrays.asList(superInterface, ctClass);
}

@Override
public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
CtClass superInterface = CtInterfaceBuilder.create().name("Interface").addToClassPool(classPool);
CtMethodBuilder.create().publicAccess().abstractMethod().name("method").addToClass(superInterface);
CtMethodBuilder.create().publicAccess().abstractMethod().returnType(CtClass.voidType).name("method").addToClass(superInterface);
CtClass ctClass = CtClassBuilder.create().name("Test").implementsInterface(superInterface).addToClassPool(classPool);
CtMethodBuilder.create().publicAccess().returnType(CtClass.voidType).name("method").addToClass(ctClass);
return Arrays.asList(superInterface, ctClass);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
assertThat(method.isSourceCompatible(), is(false));
assertThat(method.getCompatibilityChanges(), hasItem(JApiCompatibilityChange.METHOD_NOW_THROWS_CHECKED_EXCEPTION));
}

@Test
public void testMethodNoLongerThrowsNewCheckedException() throws Exception {
JarArchiveComparatorOptions options = new JarArchiveComparatorOptions();
Expand All @@ -1256,7 +1256,7 @@ public List<CtClass> createOldClasses(ClassPool classPool) throws Exception {
CtMethodBuilder.create().publicAccess().name("method").exceptions(new CtClass[] {classPool.get("java.lang.Exception")}).addToClass(ctClass);
return Collections.singletonList(ctClass);
}

@Override
public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
CtClass ctClass = CtClassBuilder.create().name("japicmp.Test").addToClassPool(classPool);
Expand Down Expand Up @@ -1651,7 +1651,7 @@ public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
assertThat(jApiClass.isBinaryCompatible(), is(true));
assertThat(jApiClass.getCompatibilityChanges(), not(hasItem(JApiCompatibilityChange.FIELD_REMOVED_IN_SUPERCLASS)));
}

@Test
public void testAddDefaultMethodToInterface() throws Exception {
JarArchiveComparatorOptions options = new JarArchiveComparatorOptions();
Expand All @@ -1662,7 +1662,7 @@ public List<CtClass> createOldClasses(ClassPool classPool) throws Exception {
CtClass aClass = CtClassBuilder.create().name("japicmp.C").implementsInterface(aInterface).addToClassPool(classPool);
return Arrays.asList(aInterface, aClass);
}

@Override
public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
CtClass aInterface = CtInterfaceBuilder.create().name("japicmp.I").addToClassPool(classPool);
Expand All @@ -1676,7 +1676,7 @@ public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
assertThat(jApiClass.isSourceCompatible(), is(true));
assertThat(jApiClass.getCompatibilityChanges(), hasItem(JApiCompatibilityChange.METHOD_DEFAULT_ADDED_IN_IMPLEMENTED_INTERFACE));
}

@Test
public void testAddAbstractMethodToInterface() throws Exception {
JarArchiveComparatorOptions options = new JarArchiveComparatorOptions();
Expand All @@ -1687,11 +1687,11 @@ public List<CtClass> createOldClasses(ClassPool classPool) throws Exception {
CtClass aClass = CtClassBuilder.create().name("japicmp.C").implementsInterface(aInterface).addToClassPool(classPool);
return Arrays.asList(aInterface, aClass);
}

@Override
public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
CtClass aInterface = CtInterfaceBuilder.create().name("japicmp.I").addToClassPool(classPool);
CtMethodBuilder.create().abstractMethod().name("defaultMethod").returnType(CtClass.booleanType).addToClass(aInterface);
CtMethodBuilder.create().abstractMethod().name("method").returnType(CtClass.booleanType).addToClass(aInterface);
CtClass aClass = CtClassBuilder.create().name("japicmp.C").implementsInterface(aInterface).addToClassPool(classPool);
return Arrays.asList(aInterface, aClass);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public List<CtClass> createOldClasses(ClassPool classPool) throws Exception {
@Override
public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
CtClass typeCtClass = CtClassBuilder.create().name("japicmp.SuperType").addToClassPool(classPool);
CtClass ctClass = CtClassBuilder.create().name("japicmp.Test").withSuperclass(classPool.get("java.lang.String")).addToClassPool(classPool);
CtClass ctClass = CtClassBuilder.create().name("japicmp.Test").withSuperclass(classPool.get("java.text.SimpleDateFormat")).addToClassPool(classPool);
return Arrays.asList(typeCtClass, ctClass);
}
});
Expand Down

0 comments on commit 79c58b4

Please sign in to comment.