Skip to content

Commit

Permalink
#392 added new test case
Browse files Browse the repository at this point in the history
  • Loading branch information
siom79 committed Apr 22, 2024
1 parent 70e68e5 commit 97c4d68
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package japicmp.test.annotation;

@TestAnnotation(name = "test-name", list = {"a", "b"}, type = @TestAnnotation.Type(label = "test-label"))
public class AnnotationChanged {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package japicmp.test.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE})
public @interface TestAnnotation {

@Retention(RetentionPolicy.RUNTIME)
@Target({})
@interface Type {
String label();
}

String name() default "default-name";
String[] list();
Type type();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package japicmp.test.annotation;

@TestAnnotation(name = "test-name-changed", list = {"a", "c"}, type = @TestAnnotation.Type(label = "test-label-changed"))
public class AnnotationChanged {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package japicmp.test.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE})
public @interface TestAnnotation {

@Retention(RetentionPolicy.RUNTIME)
@Target({})
@interface Type {
String label();
}

String name() default "default-name";
String[] list();
Type type();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import japicmp.cmp.JarArchiveComparator;
import japicmp.cmp.JarArchiveComparatorOptions;
import japicmp.model.*;
import japicmp.test.annotation.AnnotationChanged;
import japicmp.test.annotation.TestAnnotation;
import org.junit.BeforeClass;
import org.junit.Test;

Expand Down Expand Up @@ -96,4 +98,16 @@ public void testNewAnnotation() {
assertThat(jApiClass.isBinaryCompatible(), is(true));
assertThat(jApiClass.getCompatibilityChanges(), not(hasItem(new JApiCompatibilityChange(JApiCompatibilityChangeType.METHOD_DEFAULT_ADDED_IN_IMPLEMENTED_INTERFACE))));
}

@Test
public void testAnnotationValuesChanged() {
JApiClass jApiClass = getJApiClass(jApiClasses, AnnotationChanged.class.getName());
JApiAnnotation testAnnotation = getJApiAnnotation(jApiClass.getAnnotations(), TestAnnotation.class.getName());
assertThat(testAnnotation.getChangeStatus(), is(JApiChangeStatus.MODIFIED));
JApiAnnotationElement nameElement = getJApiAnnotationElement(testAnnotation.getElements(), "name");
assertThat(nameElement.getChangeStatus(), is(JApiChangeStatus.MODIFIED));
assertThat(nameElement.getOldValue().get().toString(), is("\"test-name\""));
assertThat(nameElement.getNewValue().get().toString(), is("\"test-name-changed\""));
assertThat(jApiClass.getCompatibilityChanges(), hasItem(new JApiCompatibilityChange(JApiCompatibilityChangeType.ANNOTATION_MODIFIED)));
}
}

0 comments on commit 97c4d68

Please sign in to comment.