Skip to content

Commit

Permalink
fixed further tests
Browse files Browse the repository at this point in the history
  • Loading branch information
siom79 committed Mar 4, 2024
1 parent 37e7bed commit 975fd4c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 65 deletions.
6 changes: 2 additions & 4 deletions japicmp-testbase/japicmp-test-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@
<onlyModified>true</onlyModified>
<accessModifier>public</accessModifier>
<breakBuildOnModifications>false</breakBuildOnModifications>
<breakBuildOnBinaryIncompatibleModifications>false
</breakBuildOnBinaryIncompatibleModifications>
<breakBuildOnBinaryIncompatibleModifications>false</breakBuildOnBinaryIncompatibleModifications>
<includeSynthetic>true</includeSynthetic>
<htmlStylesheet>${project.basedir}/src/main/resources/css/stylesheet.css
</htmlStylesheet>
<htmlStylesheet>${project.basedir}/src/main/resources/css/stylesheet.css</htmlStylesheet>
<htmlTitle>Test-Title</htmlTitle>
</parameter>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,31 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import static japicmp.test.util.Helper.replaceLastDotWith$;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class XmlOutputGeneratorAccessModifierTest {
private static Document documentPublic;
private static Document documentPrivate;

@BeforeClass
public static void beforeClass() throws IOException {
Path diffPublicXmlFilePath = Paths.get(System.getProperty("user.dir"), "target", "diff_public.xml");
Path diffPublicHtmlFilePath = Paths.get(System.getProperty("user.dir"), "target", "diff_public.html");
Path diffPrivateXmlFilePath = Paths.get(System.getProperty("user.dir"), "target", "diff_private.xml");
Path diffPrivateHtmlFilePath = Paths.get(System.getProperty("user.dir"), "target", "diff_private.html");
List<JApiClass> jApiClasses = Helper.compareTestV1WithTestV2(AccessModifier.PUBLIC);
Helper.generateHtmlOutput(jApiClasses, diffPublicXmlFilePath.toString(), diffPublicHtmlFilePath.toString(), true, AccessModifier.PUBLIC);
Helper.generateHtmlOutput(jApiClasses, diffPublicHtmlFilePath.toString(), true, AccessModifier.PUBLIC);
jApiClasses = Helper.compareTestV1WithTestV2(AccessModifier.PRIVATE);
Helper.generateHtmlOutput(jApiClasses, diffPrivateXmlFilePath.toString(), diffPrivateHtmlFilePath.toString(), true, AccessModifier.PRIVATE);
Helper.generateHtmlOutput(jApiClasses, diffPrivateHtmlFilePath.toString(), true, AccessModifier.PRIVATE);
File htmlFilePublic = diffPublicHtmlFilePath.toFile();
File htmlFilePrivate = diffPrivateHtmlFilePath.toFile();
documentPublic = Jsoup.parse(htmlFilePublic, Charset.forName("UTF-8").toString());
documentPrivate = Jsoup.parse(htmlFilePrivate, Charset.forName("UTF-8").toString());
documentPublic = Jsoup.parse(htmlFilePublic, StandardCharsets.UTF_8.toString());
documentPrivate = Jsoup.parse(htmlFilePrivate, StandardCharsets.UTF_8.toString());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
Expand All @@ -31,9 +31,9 @@ public static void beforeClass() throws IOException {
Path diffPublicXmlPath = Paths.get(System.getProperty("user.dir"), "target", "diff_public.xml");
Path diffPublicHtmlPath = Paths.get(System.getProperty("user.dir"), "target", "diff_public.html");
List<JApiClass> jApiClasses = Helper.compareTestV1WithTestV2(AccessModifier.PUBLIC);
Helper.generateHtmlOutput(jApiClasses, diffPublicXmlPath.toString(), diffPublicHtmlPath.toString(), false, AccessModifier.PUBLIC);
Helper.generateHtmlOutput(jApiClasses, diffPublicHtmlPath.toString(), false, AccessModifier.PUBLIC);
File htmlFilePublic = Paths.get(System.getProperty("user.dir"), "target", "diff_public.html").toFile();
documentPublic = Jsoup.parse(htmlFilePublic, Charset.forName("UTF-8").toString());
documentPublic = Jsoup.parse(htmlFilePublic, StandardCharsets.UTF_8.toString());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package japicmp.test.output.xml;

import com.google.common.io.Files;
import japicmp.cmp.JarArchiveComparator;
import japicmp.cmp.JarArchiveComparatorOptions;
import japicmp.config.Options;
import japicmp.filter.JavadocLikePackageFilter;
import japicmp.model.JApiClass;
import japicmp.output.xml.XmlOutput;
import japicmp.output.xml.XmlOutputGenerator;
import japicmp.output.xml.XmlOutputGeneratorOptions;
import japicmp.output.html.HtmlOutput;
import japicmp.output.html.HtmlOutputGenerator;
import japicmp.output.html.HtmlOutputGeneratorOptions;
import japicmp.util.Optional;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
Expand All @@ -18,15 +17,16 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import static japicmp.test.output.xml.XmlHelper.getDivForClass;
import static japicmp.test.util.Helper.getArchive;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class XmlOutputGeneratorTest {
private static final String JAPICMP_TEST_SEMVER001 = "japicmp.test.semver001";
Expand All @@ -38,42 +38,39 @@ public class XmlOutputGeneratorTest {

@BeforeClass
public static void beforeClass() throws IOException {
Path diffXmlFilePath = Paths.get(System.getProperty("user.dir"), "target", "diff.xml");
Path diffHtmlFilePath = Paths.get(System.getProperty("user.dir"), "target", "diff.html");
Path diffOnlyModificationsXmlFilePath = Paths.get(System.getProperty("user.dir"), "target", "diff_onlyModifications.xml");
Path diffOnlyModificationsHtmlFilePath = Paths.get(System.getProperty("user.dir"), "target", "diff_onlyModifications.html");
JarArchiveComparatorOptions options = new JarArchiveComparatorOptions();
options.getFilters().getExcludes().add(new JavadocLikePackageFilter(JAPICMP_TEST_SEMVER001, false));
JarArchiveComparator jarArchiveComparator = new JarArchiveComparator(options);
jApiClasses = jarArchiveComparator.compare(getArchive("japicmp-test-v1.jar"), getArchive("japicmp-test-v2.jar"));
generateHtmlOutput(diffXmlFilePath.toString(), diffHtmlFilePath.toString(), false);
generateHtmlOutput(diffOnlyModificationsXmlFilePath.toString(), diffOnlyModificationsHtmlFilePath.toString(), true);
generateHtmlOutput(diffHtmlFilePath.toString(), false);
generateHtmlOutput(diffOnlyModificationsHtmlFilePath.toString(), true);
htmlFile = Paths.get(System.getProperty("user.dir"), "target", "diff.html").toFile();
document = Jsoup.parse(htmlFile, Charset.forName("UTF-8").toString());
documentOnlyModifications = Jsoup.parse(diffOnlyModificationsHtmlFilePath.toFile(), Charset.forName("UTF-8").toString());
document = Jsoup.parse(htmlFile, StandardCharsets.UTF_8.toString());
documentOnlyModifications = Jsoup.parse(diffOnlyModificationsHtmlFilePath.toFile(), StandardCharsets.UTF_8.toString());
}

private static void generateHtmlOutput(String xmlOutpuFile, String htmlOutputFile, boolean outputOnlyModifications) {
private static void generateHtmlOutput( String htmlOutputFile, boolean outputOnlyModifications) throws IOException {
Options options = Options.newDefault();
options.setXmlOutputFile(Optional.of(xmlOutpuFile));
options.setHtmlOutputFile(Optional.of(htmlOutputFile));
options.setOutputOnlyModifications(outputOnlyModifications);
XmlOutputGeneratorOptions xmlOutputGeneratorOptions = new XmlOutputGeneratorOptions();
xmlOutputGeneratorOptions.setTitle(TITLE);
XmlOutputGenerator generator = new XmlOutputGenerator(jApiClasses, options, xmlOutputGeneratorOptions);
XmlOutput xmlOutput = generator.generate();
XmlOutputGenerator.writeToFiles(options, xmlOutput);
HtmlOutputGeneratorOptions htmlOutputGeneratorOptions = new HtmlOutputGeneratorOptions();
htmlOutputGeneratorOptions.setTitle(TITLE);
HtmlOutputGenerator generator = new HtmlOutputGenerator(jApiClasses, options, htmlOutputGeneratorOptions);
HtmlOutput htmlOutput = generator.generate();
Files.write(Paths.get(htmlOutputFile), htmlOutput.getHtml().getBytes(StandardCharsets.UTF_8));
}

@Test
public void testMetaInformationTable() throws IOException {
public void testMetaInformationTable() {
assertThat(document.select("div.meta-information > table").isEmpty(), is(false));
assertThat(document.select("div.meta-information > table > tbody > tr").size(), is(10));
}

@Test
public void htmlFileNotContainsPackageSemver001() throws IOException {
List<String> lines = Files.readLines(htmlFile, Charset.forName("UTF-8"));
List<String> lines = Files.readAllLines(htmlFile.toPath(), StandardCharsets.UTF_8);
boolean containsPackageName = false;
for (String line : lines) {
if (line.contains(JAPICMP_TEST_SEMVER001)) {
Expand All @@ -85,13 +82,13 @@ public void htmlFileNotContainsPackageSemver001() throws IOException {
}

@Test
public void superclassAllChangesAddedWithSuperclass() throws IOException {
public void superclassAllChangesAddedWithSuperclass() {
Elements divSuperClass = getSuperClassDiv(document, "japicmp.test.Superclasses$AddedWithSuperclass");
assertThat(divSuperClass.select("table").isEmpty(), is(false));
}

@Test
public void superclassOnlyModificationsAddedWithSuperclass() throws IOException {
public void superclassOnlyModificationsAddedWithSuperclass() {
Elements divSuperClass = getSuperClassDiv(documentOnlyModifications, "japicmp.test.Superclasses$AddedWithSuperclass");
assertThat(divSuperClass.select("table").isEmpty(), is(false));
}
Expand All @@ -104,49 +101,49 @@ private Elements getSuperClassDiv(Document document, String className) {
}

@Test
public void superclassAllChangesAdded() throws IOException {
Elements divSuperClass = getSuperClassDiv(document, "japicmp.test.Added");
public void superclassAllChangesAdded() {
Elements divSuperClass = getSuperClassDiv(document, "japicmp.test.Superclasses$AddedWithSuperclass");
assertThat(divSuperClass.select("table").isEmpty(), is(false));
}

@Test
public void superclassOnlyModificationsAdded() throws IOException {
public void superclassOnlyModificationsAdded() {
Elements divSuperClass = getSuperClassDiv(documentOnlyModifications, "japicmp.test.Added");
assertThat(divSuperClass.select("table").isEmpty(), is(true));
}

@Test
public void superclassAddedWithSuperclass() throws IOException {
public void superclassAddedWithSuperclass() {
Elements divSuperClass = getSuperClassDiv(document, "japicmp.test.Superclasses$AddedWithSuperclass");
assertThat(divSuperClass.select("table").isEmpty(), is(false));
}

@Test
public void superclassAddedWithSuperclassOnlyModifications() throws IOException {
public void superclassAddedWithSuperclassOnlyModifications() {
Elements divSuperClass = getSuperClassDiv(documentOnlyModifications, "japicmp.test.Superclasses$AddedWithSuperclass");
assertThat(divSuperClass.select("table").isEmpty(), is(false));
}

@Test
public void superclassRemovedWithSuperclass() throws IOException {
public void superclassRemovedWithSuperclass() {
Elements divSuperClass = getSuperClassDiv(document, "japicmp.test.Superclasses$RemovedWithSuperclass");
assertThat(divSuperClass.select("table").isEmpty(), is(false));
}

@Test
public void superclassRemovedWithSuperclassOnlyModifications() throws IOException {
public void superclassRemovedWithSuperclassOnlyModifications() {
Elements divSuperClass = getSuperClassDiv(documentOnlyModifications, "japicmp.test.Superclasses$RemovedWithSuperclass");
assertThat(divSuperClass.select("table").isEmpty(), is(false));
}

@Test
public void superclassNoSuperclassToSuperclass() throws IOException {
public void superclassNoSuperclassToSuperclass() {
Elements divSuperClass = getSuperClassDiv(document, "japicmp.test.Superclasses$NoSuperclassToSuperclass");
assertThat(divSuperClass.select("table").isEmpty(), is(false));
}

@Test
public void superclassNoSuperclassToSuperclassOnlyModifications() throws IOException {
public void superclassNoSuperclassToSuperclassOnlyModifications() {
Elements divSuperClass = getSuperClassDiv(documentOnlyModifications, "japicmp.test.Superclasses$NoSuperclassToSuperclass");
assertThat(divSuperClass.select("table").isEmpty(), is(false));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package japicmp.test.util;

import japicmp.util.Optional;
import japicmp.cmp.JApiCmpArchive;
import japicmp.cmp.JarArchiveComparator;
import japicmp.cmp.JarArchiveComparatorOptions;
import japicmp.config.Options;
import japicmp.model.AccessModifier;
import japicmp.model.JApiAnnotation;
import japicmp.model.JApiAnnotationElement;
import japicmp.model.JApiClass;
import japicmp.model.JApiField;
import japicmp.model.JApiImplementedInterface;
import japicmp.model.JApiMethod;
import japicmp.output.xml.XmlOutput;
import japicmp.output.xml.XmlOutputGenerator;
import japicmp.output.xml.XmlOutputGeneratorOptions;
import japicmp.model.*;
import japicmp.output.html.HtmlOutput;
import japicmp.output.html.HtmlOutputGenerator;
import japicmp.output.html.HtmlOutputGeneratorOptions;
import japicmp.util.Optional;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Assert;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

public class Helper {
Expand Down Expand Up @@ -164,17 +162,15 @@ public static List<JApiClass> compareTestV1WithTestV2(AccessModifier accessModif
return jarArchiveComparator.compare(getArchive("japicmp-test-v1.jar"), getArchive("japicmp-test-v2.jar"));
}

public static void generateHtmlOutput(List<JApiClass> jApiClasses, String xmlOutputFile, String htmlOutputFile, boolean outputOnlyModifications, AccessModifier accessModifier) {
public static void generateHtmlOutput(List<JApiClass> jApiClasses, String htmlOutputFile, boolean outputOnlyModifications, AccessModifier accessModifier) throws IOException {
Options options = Options.newDefault();
options.setXmlOutputFile(Optional.of(xmlOutputFile));
options.setHtmlOutputFile(Optional.of(htmlOutputFile));
options.setOutputOnlyModifications(outputOnlyModifications);
options.setAccessModifier(Optional.of(accessModifier));
XmlOutputGeneratorOptions xmlOutputGeneratorOptions = new XmlOutputGeneratorOptions();
xmlOutputGeneratorOptions.setCreateSchemaFile(true);
XmlOutputGenerator generator = new XmlOutputGenerator(jApiClasses, options, xmlOutputGeneratorOptions);
XmlOutput xmlOutput = generator.generate();
XmlOutputGenerator.writeToFiles(options, xmlOutput);
HtmlOutputGeneratorOptions htmlOutputGeneratorOptions = new HtmlOutputGeneratorOptions();
HtmlOutputGenerator generator = new HtmlOutputGenerator(jApiClasses, options, htmlOutputGeneratorOptions);
HtmlOutput htmlOutput = generator.generate();
Files.write(Paths.get(htmlOutputFile), htmlOutput.getHtml().getBytes(StandardCharsets.UTF_8));
}

public interface SimpleExceptionVerifier {
Expand Down

0 comments on commit 975fd4c

Please sign in to comment.