Skip to content

Commit

Permalink
#365: correct name of package_protected in documentation, added new t…
Browse files Browse the repository at this point in the history
…est case for this issue
  • Loading branch information
siom79 committed Oct 18, 2023
1 parent 2536bc2 commit fa5f391
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 45 deletions.
6 changes: 0 additions & 6 deletions japicmp/src/main/java/japicmp/compat/Test.java

This file was deleted.

28 changes: 28 additions & 0 deletions japicmp/src/test/java/japicmp/compat/CompatibilityChangesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2196,4 +2196,32 @@ public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
jApiMethod = getJApiMethod(jApiClass.getMethods(), "method");
assertThat(jApiMethod.getChangeStatus(), is(JApiChangeStatus.REMOVED));
}

@Test
public void testPackagePrivateClassChangesToPublicClassWithMethodReturnTypeChangeIssue365() throws Exception {
JarArchiveComparatorOptions jarArchiveComparatorOptions = new JarArchiveComparatorOptions();
jarArchiveComparatorOptions.setAccessModifier(AccessModifier.PRIVATE);
List<JApiClass> jApiClasses = ClassesHelper.compareClasses(jarArchiveComparatorOptions, new ClassesHelper.ClassesGenerator() {
@Override
public List<CtClass> createOldClasses(ClassPool classPool) throws Exception {
CtClass ctInterfaceF = CtInterfaceBuilder.create().name("F").addToClassPool(classPool);
CtClass ctClassC = CtClassBuilder.create().name("C").protectedModifier().addToClassPool(classPool);
CtMethodBuilder.create().publicAccess().staticAccess().name("M").returnType(ctInterfaceF).addToClass(ctClassC);
return Arrays.asList(ctInterfaceF, ctClassC);
}

@Override
public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
CtClass ctInterfaceF = CtInterfaceBuilder.create().name("F").addToClassPool(classPool);
CtClass ctClassFImpl = CtClassBuilder.create().name("FImpl").implementsInterface(ctInterfaceF).addToClassPool(classPool);
CtClass ctClassC = CtClassBuilder.create().name("C").protectedModifier().addToClassPool(classPool);
CtMethodBuilder.create().publicAccess().staticAccess().name("M").returnType(ctClassFImpl).addToClass(ctClassC);
return Arrays.asList(ctInterfaceF, ctClassC);
}
});
JApiClass jApiClass = getJApiClass(jApiClasses, "C");
JApiMethod jApiMethod = getJApiMethod(jApiClass.getMethods(), "M");
assertThat(jApiMethod.getChangeStatus(), is(JApiChangeStatus.MODIFIED));
assertThat(jApiMethod.getCompatibilityChanges(), hasItem(JApiCompatibilityChange.METHOD_RETURN_TYPE_CHANGED));
}
}
7 changes: 7 additions & 0 deletions japicmp/src/test/java/japicmp/util/CtClassBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public CtClassBuilder privateModifier() {
return this;
}

public CtClassBuilder protectedModifier() {
this.modifier = this.modifier & ~Modifier.PUBLIC;
this.modifier = this.modifier & ~Modifier.PRIVATE;
this.modifier |= Modifier.PROTECTED;
return this;
}

public CtClassBuilder enumModifier() {
this.modifier = this.modifier | Modifier.ENUM;
return this;
Expand Down
Loading

0 comments on commit fa5f391

Please sign in to comment.