-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#110: started tracking of exceptions on methods/constructors
- Loading branch information
Showing
6 changed files
with
202 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package japicmp.model; | ||
|
||
import javax.xml.bind.annotation.XmlAttribute; | ||
|
||
public class JApiException implements JApiHasChangeStatus { | ||
private final String name; | ||
private final JApiChangeStatus changeStatus; | ||
|
||
public JApiException(String name, JApiChangeStatus changeStatus) { | ||
this.name = name; | ||
this.changeStatus = changeStatus; | ||
} | ||
|
||
@XmlAttribute(name = "name") | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@XmlAttribute(name = "changeStatus") | ||
public JApiChangeStatus getChangeStatus() { | ||
return changeStatus; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package japicmp.cmp; | ||
|
||
import japicmp.model.JApiChangeStatus; | ||
import japicmp.model.JApiClass; | ||
import japicmp.model.JApiMethod; | ||
import japicmp.util.CtClassBuilder; | ||
import japicmp.util.CtMethodBuilder; | ||
import javassist.ClassPool; | ||
import javassist.CtClass; | ||
import org.junit.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static japicmp.util.Helper.getJApiClass; | ||
import static japicmp.util.Helper.getJApiMethod; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class ExceptionsTest { | ||
|
||
@Test | ||
public void testMethodThrowsUnchangedExceptions() throws Exception { | ||
JarArchiveComparatorOptions options = new JarArchiveComparatorOptions(); | ||
List<JApiClass> jApiClasses = ClassesHelper.compareClasses(options, new ClassesHelper.ClassesGenerator() { | ||
@Override | ||
public List<CtClass> createOldClasses(ClassPool classPool) throws Exception { | ||
CtClass ctClass = CtClassBuilder.create().name("japicmp.Test").addToClassPool(classPool); | ||
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); | ||
CtMethodBuilder.create().publicAccess().name("method").exceptions(new CtClass[] {classPool.get("java.lang.Exception")}).addToClass(ctClass); | ||
return Collections.singletonList(ctClass); | ||
} | ||
}); | ||
JApiClass jApiClass = getJApiClass(jApiClasses, "japicmp.Test"); | ||
JApiMethod method = getJApiMethod(jApiClass.getMethods(), "method"); | ||
assertThat(method.getExceptions().size(), is(1)); | ||
assertThat(method.getExceptions().get(0).getChangeStatus(), is(JApiChangeStatus.UNCHANGED)); | ||
} | ||
|
||
@Test | ||
public void testMethodThrowsNewExceptions() throws Exception { | ||
JarArchiveComparatorOptions options = new JarArchiveComparatorOptions(); | ||
List<JApiClass> jApiClasses = ClassesHelper.compareClasses(options, new ClassesHelper.ClassesGenerator() { | ||
@Override | ||
public List<CtClass> createOldClasses(ClassPool classPool) throws Exception { | ||
CtClass ctClass = CtClassBuilder.create().name("japicmp.Test").addToClassPool(classPool); | ||
CtMethodBuilder.create().publicAccess().name("method").addToClass(ctClass); | ||
return Collections.singletonList(ctClass); | ||
} | ||
|
||
@Override | ||
public List<CtClass> createNewClasses(ClassPool classPool) throws Exception { | ||
CtClass ctClass = CtClassBuilder.create().name("japicmp.Test").addToClassPool(classPool); | ||
CtMethodBuilder.create().publicAccess().name("method").exceptions(new CtClass[] {classPool.get("java.lang.Exception")}).addToClass(ctClass); | ||
return Collections.singletonList(ctClass); | ||
} | ||
}); | ||
JApiClass jApiClass = getJApiClass(jApiClasses, "japicmp.Test"); | ||
JApiMethod method = getJApiMethod(jApiClass.getMethods(), "method"); | ||
assertThat(method.getExceptions().size(), is(1)); | ||
assertThat(method.getExceptions().get(0).getChangeStatus(), is(JApiChangeStatus.NEW)); | ||
} | ||
|
||
@Test | ||
public void testMethodThrowsRemovedExceptions() throws Exception { | ||
JarArchiveComparatorOptions options = new JarArchiveComparatorOptions(); | ||
List<JApiClass> jApiClasses = ClassesHelper.compareClasses(options, new ClassesHelper.ClassesGenerator() { | ||
@Override | ||
public List<CtClass> createOldClasses(ClassPool classPool) throws Exception { | ||
CtClass ctClass = CtClassBuilder.create().name("japicmp.Test").addToClassPool(classPool); | ||
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); | ||
CtMethodBuilder.create().publicAccess().name("method").addToClass(ctClass); | ||
return Collections.singletonList(ctClass); | ||
} | ||
}); | ||
JApiClass jApiClass = getJApiClass(jApiClasses, "japicmp.Test"); | ||
JApiMethod method = getJApiMethod(jApiClass.getMethods(), "method"); | ||
assertThat(method.getExceptions().size(), is(1)); | ||
assertThat(method.getExceptions().get(0).getChangeStatus(), is(JApiChangeStatus.REMOVED)); | ||
} | ||
} |