Commit ff493449 authored by Johannes Mey's avatar Johannes Mey
Browse files

Merge branch 'mquat2' of git-st.inf.tu-dresden.de:johannes.mey/relast into mquat2

parents 78bb20dd 2b0493c3
Pipeline #3044 passed with stage
in 51 seconds
......@@ -115,7 +115,7 @@ task preprocessRelationTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
//noinspection GroovyAssignabilityCheck
args 'src/test/jastadd/relations/Relations.relast', '--file', '--grammarName=src/test/jastadd/relations/Relations'
args 'src/test/jastadd/relations/Relations.relast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/relations/Relations'
}
task doublePreprocessRelationTest(type: JavaExec, group: 'verification') {
......@@ -127,7 +127,7 @@ task doublePreprocessRelationTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
//noinspection GroovyAssignabilityCheck
args 'src/test/jastadd/relations/Relations.ast', '--file', '--grammarName=src/test/jastadd/relations/Relations2'
args 'src/test/jastadd/relations/Relations.ast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/relations/Relations2'
}
task compileRelationTest(type: JavaExec, group: 'verification') {
......@@ -145,6 +145,59 @@ task compileRelationTest(type: JavaExec, group: 'verification') {
'src/test/jastadd/Utils.jadd'
}
task preprocessDefaultNamesTest(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/jastadd/relations/Relations.ast', 'src/test/jastadd/relations/Relations.jadd'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
args 'src/test/jastadd/relations/Relations.relast', '--file', '--grammarName=src/test/jastadd/relations/Relations'
}
task compileDefaultNamesTest(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/java-gen/relations'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.JastAdd'
args '--o=src/test/java-gen/', '--package=defaultnames.ast', 'src/test/jastadd/relations/Relations.ast', 'src/test/jastadd/relations/Relations.jadd', 'src/test/jastadd/Utils.jadd'
}
task preprocessDefaultNamesResolverTest(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/jastadd/resolver/Resolver.ast', 'src/test/jastadd/resolver/Resolver.jadd', 'src/test/jastadd/resolver/ResolverRefResolver.jadd'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
args 'src/test/jastadd/resolver/Resolver.relast', '--file', '--grammarName=src/test/jastadd/resolver/Resolver', '--resolverHelper'
}
task compileDefaultNamesResolverTest(type: JavaExec, group: 'verification') {
doFirst {
delete 'src/test/java-gen/resolver'
}
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.JastAdd'
//noinspection GroovyAssignabilityCheck
args '--o=src/test/java-gen/',
'--package=defaultnames.resolver.ast',
'src/test/jastadd/resolver/Resolver.ast',
'src/test/jastadd/resolver/Resolver.jadd',
'src/test/jastadd/resolver/ResolverUtils.jadd',
'src/test/jastadd/resolver/ResolverResolverStubs.jrag',
'src/test/jastadd/resolver/ResolverRefResolver.jadd',
'src/test/jastadd/resolver/MyRefResolver.jadd',
'src/test/jastadd/Utils.jadd'
}
task preprocessLowerBoundsTest(type: JavaExec, group: 'verification') {
doFirst {
......@@ -154,7 +207,7 @@ task preprocessLowerBoundsTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
//noinspection GroovyAssignabilityCheck
args 'src/test/jastadd/lowerbounds/LowerBounds.relast', '--file', '--grammarName=src/test/jastadd/lowerbounds/LowerBounds'
args 'src/test/jastadd/lowerbounds/LowerBounds.relast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/lowerbounds/LowerBounds'
}
task compileLowerBoundsTest(type: JavaExec, group: 'verification') {
......@@ -181,7 +234,7 @@ task preprocessMultipleTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
//noinspection GroovyAssignabilityCheck
args 'src/test/jastadd/multiple/Part1.relast', 'src/test/jastadd/multiple/Part2.relast', 'src/test/jastadd/multiple/Part3.relast', '--file', '--grammarName=src/test/jastadd/multiple/Multiple'
args 'src/test/jastadd/multiple/Part1.relast', '--useJastAddNames', 'src/test/jastadd/multiple/Part2.relast', 'src/test/jastadd/multiple/Part3.relast', '--file', '--grammarName=src/test/jastadd/multiple/Multiple'
}
task compileMultipleTest(type: JavaExec, group: 'verification') {
......@@ -208,7 +261,7 @@ task preprocessResolverTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
//noinspection GroovyAssignabilityCheck
args 'src/test/jastadd/resolver/Resolver.relast', '--file', '--grammarName=src/test/jastadd/resolver/Resolver', '--resolverHelper'
args 'src/test/jastadd/resolver/Resolver.relast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/resolver/Resolver', '--resolverHelper'
}
task compileResolverTest(type: JavaExec, group: 'verification') {
......@@ -240,7 +293,7 @@ task preprocessResolver2Test(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
//noinspection GroovyAssignabilityCheck
args 'src/test/jastadd/resolver2/Resolver.relast', '--file', '--grammarName=src/test/jastadd/resolver2/Resolver', '--resolverHelper'
args 'src/test/jastadd/resolver2/Resolver.relast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/resolver2/Resolver', '--resolverHelper'
}
task compileResolver2Test(type: JavaExec, group: 'verification') {
......@@ -271,7 +324,7 @@ task preprocessListNamesTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
//noinspection GroovyAssignabilityCheck
args 'src/test/jastadd/listnames/ListNames.relast', '--file', '--grammarName=src/test/jastadd/listnames/ListNames', '--jastAddList=ListyMcListface'
args 'src/test/jastadd/listnames/ListNames.relast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/listnames/ListNames', '--jastAddList=ListyMcListface'
}
task compileListNamesTest(type: JavaExec, group: 'verification') {
......@@ -303,7 +356,7 @@ task preprocessSerializerTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
//noinspection GroovyAssignabilityCheck
args 'src/test/jastadd/serializer/Serializer.relast', '--file', '--grammarName=src/test/jastadd/serializer/Serializer', '--serializer=jackson'
args 'src/test/jastadd/serializer/Serializer.relast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/serializer/Serializer', '--serializer=jackson'
}
task compileSerializerTest(type: JavaExec, group: 'verification') {
......@@ -334,6 +387,11 @@ test.dependsOn compileRelationTest
compileRelationTest.dependsOn doublePreprocessRelationTest
doublePreprocessRelationTest.dependsOn preprocessRelationTest
test.dependsOn compileDefaultNamesTest
compileDefaultNamesTest.dependsOn preprocessDefaultNamesTest
test.dependsOn compileDefaultNamesResolverTest
compileDefaultNamesResolverTest.dependsOn preprocessDefaultNamesResolverTest
test.dependsOn compileLowerBoundsTest
compileLowerBoundsTest.dependsOn preprocessLowerBoundsTest
......@@ -348,6 +406,5 @@ compileResolver2Test.dependsOn preprocessResolver2Test
test.dependsOn compileListNamesTest
compileListNamesTest.dependsOn preprocessListNamesTest
test.dependsOn compileSerializerTest
compileSerializerTest.dependsOn preprocessSerializerTest
\ No newline at end of file
compileSerializerTest.dependsOn preprocessSerializerTest
......@@ -5,6 +5,7 @@ aspect BackendAbstractGrammar {
public static boolean ASTNode.resolverHelper = false;
public static boolean ASTNode.serializer = false;
public static boolean ASTNode.useJastAddNames = false;
public String Program.generateAbstractGrammar() {
StringBuilder sb = new StringBuilder();
......@@ -191,15 +192,19 @@ aspect BackendDirectedAPI {
public void ManyRelationComponent.generateDirectedAPI(StringBuilder sb) {
// Get
// getXs
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "s() {\n");
sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n");
sb.append(ind(1) + "}\n");
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl() + ".");
if (useJastAddNames) {
// getXs
sb.append("get" + nameCapitalized() + "s() {\n");
sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n");
sb.append(ind(1) + "}\n");
// getXList
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "List() {\n");
// getXList
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "List() {\n");
} else {
sb.append(name() + "() {\n");
}
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> l = get" + getImplAttributeName() + "();\n");
// resolve the entire list
if (resolverHelper | serializer) {
......@@ -223,6 +228,9 @@ aspect BackendDirectedAPI {
// Add
sb.append(ind(1) + "public void " + toTypeDecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
......@@ -234,7 +242,11 @@ aspect BackendDirectedAPI {
sb.append(ind(1) + "}\n");
// Insert / add at specific position
sb.append(ind(1) + "public void " + toTypeDecl() + ".add" + nameCapitalized() + "(int index, " + ofTypeDecl() + " o) {\n");
sb.append(ind(1) + "public void " + toTypeDecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
sb.append(nameCapitalized() + "(int index, " + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
sb.append(ind(2) + "if (list == null) {\n");
......@@ -246,6 +258,9 @@ aspect BackendDirectedAPI {
// Remove
sb.append(ind(1) + "public void " + toTypeDecl() + ".remove");
if (!useJastAddNames) {
sb.append("From");
}
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
......@@ -256,8 +271,13 @@ aspect BackendDirectedAPI {
}
public void RelationComponent.generateGetOne(StringBuilder sb) {
sb.append(ind(1) + "public " + ofTypeDecl() + " " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "() {\n");
sb.append(ind(1) + "public " + ofTypeDecl() + " " + toTypeDecl() + ".");
if (useJastAddNames) {
sb.append("get" + nameCapitalized());
} else {
sb.append(name());
}
sb.append("() {\n");
if (resolverHelper | serializer) {
sb.append(ind(2) + "if (get" + getImplAttributeName() + "() != null && get" + getImplAttributeName() + "().unresolved()) {\n");
sb.append(ind(3) + "if (get" + getImplAttributeName() + "().asUnresolved().get__resolve_opposite()) {\n");
......@@ -275,7 +295,13 @@ aspect BackendDirectedAPI {
// has
sb.append(ind(1) + "public boolean " + toTypeDecl());
sb.append(".has" + nameCapitalized() + "() {\n");
sb.append(ind(2) + "return get" + nameCapitalized() + "() != null;\n");
sb.append(ind(2) + "return ");
if (useJastAddNames) {
sb.append("get" + nameCapitalized());
} else {
sb.append(name());
}
sb.append("() != null;\n");
sb.append(ind(1) + "}\n");
// clear
......@@ -379,15 +405,19 @@ aspect BackendBidirectionalAPI {
public void RelationComponent.generateBiManyMany(StringBuilder sb, RelationComponent opposite) {
// Get
// getXs
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "s() {\n");
sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n");
sb.append(ind(1) + "}\n");
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl() + ".");
if (useJastAddNames) {
// getXs
sb.append("get" + nameCapitalized() + "s() {\n");
sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n");
sb.append(ind(1) + "}\n");
// getXList
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "List() {\n");
// getXList
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "List() {\n");
} else {
sb.append(name() + "() {\n");
}
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> l = get" + getImplAttributeName() + "();\n");
// resolve the entire list
if (resolverHelper | serializer) {
......@@ -419,6 +449,9 @@ aspect BackendBidirectionalAPI {
// Add
sb.append(ind(1) + "public void " + toTypeDecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
......@@ -437,7 +470,11 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n");
// Insert / add at specific position
sb.append(ind(1) + "public void " + toTypeDecl() + ".add" + nameCapitalized() + "(int index, " + ofTypeDecl() + " o) {\n");
sb.append(ind(1) + "public void " + toTypeDecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
sb.append(nameCapitalized() + "(int index, " + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
sb.append(ind(2) + "if (list == null) {\n");
......@@ -456,6 +493,9 @@ aspect BackendBidirectionalAPI {
// Remove
sb.append(ind(1) + "public void " + toTypeDecl() + ".remove");
if (!useJastAddNames) {
sb.append("From");
}
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
......@@ -472,15 +512,19 @@ aspect BackendBidirectionalAPI {
public void RelationComponent.generateBiManyOne(StringBuilder sb, RelationComponent opposite) {
// Get
// getXs
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "s() {\n");
sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n");
sb.append(ind(1) + "}\n");
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl() + ".");
if (useJastAddNames) {
// getXs
sb.append("get" + nameCapitalized() + "s() {\n");
sb.append(ind(2) + "return get" + nameCapitalized() + "List();\n");
sb.append(ind(1) + "}\n");
// getXList
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "List() {\n");
// getXList
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append(".get" + nameCapitalized() + "List() {\n");
} else {
sb.append(name() + "() {\n");
}
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> l = get" + getImplAttributeName() + "();\n");
// resolve the entire list
if (resolverHelper | serializer) {
......@@ -518,6 +562,9 @@ aspect BackendBidirectionalAPI {
// Add
sb.append(ind(1) + "public void " + toTypeDecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + "if (o != null && o.get" + otherSide().getImplAttributeName() + "() != null) {\n");
......@@ -537,7 +584,11 @@ aspect BackendBidirectionalAPI {
sb.append(ind(1) + "}\n");
// Insert / add at specific position
sb.append(ind(1) + "public void " + toTypeDecl() + ".add" + nameCapitalized() + "(int index, " + ofTypeDecl() + " o) {\n");
sb.append(ind(1) + "public void " + toTypeDecl() + ".add");
if (!useJastAddNames) {
sb.append("To");
}
sb.append(nameCapitalized() + "(int index, " + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + "if (o != null && o.get" + otherSide().getImplAttributeName() + "() != null) {\n");
sb.append(ind(3) + ASTNode.listClass + "<" + ofTypeDecl() + "> list2 = o.get" + otherSide().getImplAttributeName() + "().get" + getImplAttributeName() + "();\n");
......@@ -555,6 +606,9 @@ aspect BackendBidirectionalAPI {
// Remove
sb.append(ind(1) + "public void " + toTypeDecl() + ".remove");
if (!useJastAddNames) {
sb.append("From");
}
sb.append(nameCapitalized() + "(" + ofTypeDecl() + " o) {\n");
sb.append(ind(2) + "assertNotNull(o);\n");
sb.append(ind(2) + ASTNode.listClass + "<" + ofTypeDecl() + "> list = get" + getImplAttributeName() + "();\n");
......@@ -649,7 +703,13 @@ aspect LowerBoundCheck {
}
public void OneRelationComponent.generateLowerBoundCheck(StringBuilder sb) {
sb.append(ind(2) + "if (get" + nameCapitalized() + "() == null) {\n");
sb.append(ind(2) + "if (");
if (useJastAddNames) {
sb.append("get" + nameCapitalized());
} else {
sb.append(name());
}
sb.append("() == null) {\n");
sb.append(ind(3) + "list.add(new Pair<>(this, \"" + name() + "\"));\n");
sb.append(ind(2) + "}\n");
}
......@@ -880,7 +940,13 @@ aspect NameResolutionHelper {
sb.append(ind(1) + "// enforce resolving of all non-containment relations of the current non-terminal\n");
sb.append(ind(1) + "public void " + getID() + ".resolveAll() {\n");
for (RelationComponent relationComponent : relationComponents()) {
sb.append(ind(2) + "get" + relationComponent.nameCapitalized() + (relationComponent.isMany()?"List":"") + "();\n");
sb.append(ind(2));
if (useJastAddNames) {
sb.append("get" + relationComponent.nameCapitalized());
} else {
sb.append(relationComponent.name());
}
sb.append(relationComponent.isMany() && useJastAddNames ? "List" : "").append("();\n");
}
sb.append(ind(2) + "super.resolveAll();\n");
sb.append(ind(1) + "}\n");
......
......@@ -21,6 +21,7 @@ public class Compiler {
private StringOption optionGrammarName;
private EnumOption optionSerializer;
private FlagOption optionResolverHelper;
private FlagOption optionUseJastaddNames;
private CommandLine commandLine;
public Compiler(String[] args) throws CommandLineException {
......@@ -80,6 +81,11 @@ public class Compiler {
ASTNode.listClass = optionListClass.getValue();
}
if (optionUseJastaddNames.isSet()) {
System.out.println("Using JastAdd names");
ASTNode.useJastAddNames = true;
}
String grammarName = "Grammar";
if (optionGrammarName.isSet()) {
grammarName = optionGrammarName.getValue();
......@@ -143,6 +149,7 @@ public class Compiler {
optionGrammarName = addOption(new StringOption("grammarName", "name of the generated grammar and aspect (without file extension)"));
optionResolverHelper = addOption(new FlagOption("resolverHelper", "create a subtype for each type containing a string that can be used to resolve the type later"));
optionJastAddList = addOption(new StringOption("jastAddList", "set the name of the List type in JastAdd (has to match the option '--List' or its default List)"));
optionUseJastaddNames = addOption(new FlagOption("useJastAddNames", "generate names in the form of addX, removeX and setX. If omitted, the default, original naming scheme resulting in addToX, removeFromX and setX will be used."));
optionSerializer = addOption(new EnumOption("serializer", "generate a (de-)serializer", Arrays.asList("jackson"), "jackson"));
}
......
package org.jastadd.relast.tests;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import defaultnames.ast.A;
import defaultnames.ast.B;
import defaultnames.ast.Root;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import static org.jastadd.relast.tests.TestHelpers.readFile;
import static org.junit.jupiter.api.Assertions.*;
@SuppressWarnings({"ArraysAsListWithZeroOrOneArgument", "Duplicates"})
class DefaultNames {
private Root r;
private A a1;
private A a2;
private A a3;
private B b1;
private B b2;
private B b3;
@Test
void doubleRelastRun() throws IOException {
String firstRun = "./src/test/jastadd/relations/Relations.ast";
String secondRun = "./src/test/jastadd/relations/Relations2.ast";
String first = readFile(firstRun, Charset.defaultCharset());
String second = readFile(secondRun, Charset.defaultCharset());
Assertions.assertEquals(first, second);
}
/**
* rel A.Di1 -> B;
*/
@Test
void testDi1() {
setup();
a1.setDi1(b2);
a2.setDi1(b1);
assertSame(a1.Di1(), b2);
assertSame(a2.Di1(), b1);
a2.setDi1(b2);
assertSame(a1.Di1(), b2);
assertSame(a2.Di1(), b2);
try {
a3.setDi1(null);
fail("should throw an exception");
} catch (Exception e) {
// OK
}
}
/**
* rel A.Di2? -> B;
*/
@Test
void testDi2() {
setup();
a1.setDi2(b2);
a2.setDi2(b1);
assertSame(a1.Di2(), b2);
assertSame(a2.Di2(), b1);
a2.setDi2(b2);
assertSame(a1.Di2(), b2);
assertSame(a2.Di2(), b2);
a2.clearDi2();
assertSame(a1.Di2(), b2);
assertNull(a2.Di2());
assertTrue(a1.hasDi2());
assertFalse(a2.hasDi2());
assertFalse(a3.hasDi2());
}
/**
* rel A.Di3* -> B;
*/
@Test
void testDi3() {
setup();
a1.addToDi3(b1);
a1.addToDi3(b2);
a1.addToDi3(b3);
a2.addToDi3(b2);
assertEquals(a1.Di3(), Arrays.asList(b1, b2, b3));
assertEquals(a2.Di3(), Arrays.asList(b2));
assertEquals(a3.Di3(), Arrays.asList());
a1.addToDi3(b1);
a2.addToDi3(b1);
a2.addToDi3(b2);
assertEquals(a1.Di3(), Arrays.asList(b1, b2, b3, b1));
assertEquals(a2.Di3(), Arrays.asList(b2, b1, b2));
assertEquals(a3.Di3(), Arrays.asList());
a1.removeFromDi3(b1);
a2.removeFromDi3(b2);
assertEquals(a1.Di3(), Arrays.asList(b2, b3, b1));
assertEquals(a2.Di3(), Arrays.asList(b1, b2));
assertEquals(a3.Di3(), Arrays.asList());
}
/**
* rel A.Bi1 <-> B.Bi1;
*/
@Test
void testBi11() {
// Init
setup();
a1.setBi1(b1);
a2.setBi1(b2);
// Change
a2.setBi1(b1);
assertNull(a1.Bi1());
assertSame(a2.Bi1(), b1);
assertSame(b1.Bi1(), a2);
assertNull(b2.Bi1());
}
@Test
void testBi12() {
// Init
setup();
a1.setBi1(b2);
// Change
a2.setBi1(b2);
assertNull(a1.Bi1());
assertSame(a2.Bi1(), b2);
assertNull(b1.Bi1());
assertSame(b2.Bi1(), a2);
}
/**
* rel A.Bi2 <-> B.Bi2?;
*/
@Test
void testBi21() {
// Init
setup();
a1.setBi2(b1);
a2.setBi2(b2);
// Change
a2.setBi2(b1);
assertNull(a1.Bi2());
assertSame(a2.Bi2(), b1);
assertSame(b1.Bi2(), a2);
assertNull(b2.Bi2());
}
@Test
void testBi22() {
// Init
setup();
a1.setBi2(b2);
// Change
a2.setBi2(b2);
assertNull(a1.Bi2());
assertSame(a2.Bi2(), b2);
assertNull(b1.Bi2());
assertSame(b2.Bi2(), a2);
}
/**
* rel A.Bi3 <-> B.Bi3*;
*/
@Test
void testBi3() {
setup();
a2.setBi3(b2);
assertNull(a1.Bi3());