Skip to content

Commit

Permalink
fixed test UndocumentedModelElementInconsistencyTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Laxraa committed Sep 28, 2023
1 parent c64c157 commit c228589
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public String toString() {
typePositions.addAll(typeMapping.getMappingSentenceNo().castToCollection());
}
return "InstanceMapping [ uid=" + entity.getId() + ", name=" + entity.getName() + //
", as=" + String.join(", ", entity.getClass().getName()) + ", probability=" + getConfidence() + ", FOUND: " + //
", as=" + String.join(", ", entity.getClass().getSimpleName()) + ", probability=" + getConfidence() + ", FOUND: " + //
textualInstance.getName() + " : " + textualInstance.getType() + ", occurrences= " + //
"NameVariants: " + names.size() + ": " + names + " sentences{" + Arrays.toString(namePositions.toArray()) + "}" + //
", TypeVariants: " + types.size() + ": " + types + "sentences{" + Arrays.toString(typePositions.toArray()) + "}" + "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static boolean isRecommendedInstanceSimilarToEntity(RecommendedInstance r
* @return true, if the {@link Word} and the type of the {@link Entity} are similar.
*/
public static boolean isWordSimilarToModelInstanceType(Word word, Entity entity) {
var type = entity.getClass().getName();
var type = entity.getClass().getSimpleName();
return areWordsSimilar(type, word.getText());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private static ImmutableList<String[]> getInstancesFromModelState(ModelExtractio
dataLines.add(new String[] { "UID", "Name", "Type" });

for (Entity entity : modelState.getEntities()) {
dataLines.add(new String[] { entity.getId(), entity.getName(), entity.getClass().getName()});
dataLines.add(new String[] { entity.getId(), entity.getName(), entity.getClass().getSimpleName()});
}

return dataLines.toImmutable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ImmutableList<InstanceLink> getInstanceLinksByName(String name) {
*/
@Override
public ImmutableList<InstanceLink> getInstanceLinksByType(String type) {
return Lists.immutable.fromStream(instanceLinks.stream().filter(ilink -> ilink.getEntity().getClass().getName().equals(type)));
return Lists.immutable.fromStream(instanceLinks.stream().filter(ilink -> ilink.getEntity().getClass().getSimpleName().equals(type)));
}

@Override
Expand All @@ -79,7 +79,7 @@ public ImmutableList<InstanceLink> getInstanceLinksByRecommendedInstance(Recomme
public ImmutableList<InstanceLink> getInstanceLinks(String name, String type) {
return Lists.immutable.fromStream(instanceLinks.stream()
.filter(imapping -> imapping.getEntity().getNameParts().contains(name))//
.filter(imapping -> Arrays.stream(imapping.getEntity().getClass().getName().split(" ")).toList().contains(type)));
.filter(imapping -> Arrays.stream(imapping.getEntity().getClass().getSimpleName().split(" ")).toList().contains(type)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public MissingTextForModelElementInconsistency(Entity entity) {

@Override
public String getReason() {
return String.format(Locale.US, "Model contains an Instance \"%s\" (type: \"%s\") that seems to be undocumented.", entity.getName(), entity.getClass().getName());
return String.format(Locale.US, "Model contains an Instance \"%s\" (type: \"%s\") that seems to be undocumented.", entity.getName(), entity.getClass().getSimpleName());
}

@Override
Expand Down Expand Up @@ -53,7 +53,7 @@ public boolean equals(Object obj) {

@Override
public ImmutableCollection<String[]> toFileOutput() {
String[] entry = { getType(), entity.getName(), entity.getClass().getName() };
String[] entry = { getType(), entity.getName(), entity.getClass().getSimpleName() };
var list = Lists.mutable.<String[]>empty();
list.add(entry);
return list.toImmutable();
Expand All @@ -66,7 +66,7 @@ public String getEntityName() {

@Override
public String getEntityType() {
return entity.getClass().getName();
return entity.getClass().getSimpleName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,19 @@ void filterWithWhitelistTest() {

@Test
void modelInstanceHasTargetedTypeTest() {
MutableList<String> exactTypes = Lists.mutable.of("BasicComponent", "CompositeComponent");
MutableList<String> shortenedType = Lists.mutable.of("Component");
MutableList<String> exactTypes = Lists.mutable.of("ArchitectureComponent");

Assertions.assertAll(//
() -> Assertions.assertTrue(UndocumentedModelElementInconsistencyInformant.modelInstanceHasTargetedType(modelInstances.get(0), exactTypes),
"Instance 0 with 'exactTypes'"), () -> Assertions.assertTrue(UndocumentedModelElementInconsistencyInformant
.modelInstanceHasTargetedType(modelInstances.get(1), exactTypes), "Instance 1 with 'exactTypes'"), () -> Assertions.assertFalse(
UndocumentedModelElementInconsistencyInformant.modelInstanceHasTargetedType(modelInstances.get(2), exactTypes),
"Instance 0 with 'exactTypes'"),
() -> Assertions.assertTrue(UndocumentedModelElementInconsistencyInformant
.modelInstanceHasTargetedType(modelInstances.get(1), exactTypes), "Instance 1 with 'exactTypes'"),
() -> Assertions.assertFalse(UndocumentedModelElementInconsistencyInformant.modelInstanceHasTargetedType(modelInstances.get(2), exactTypes),
"Instance 2 with 'exactTypes'"), () -> Assertions.assertTrue(UndocumentedModelElementInconsistencyInformant
.modelInstanceHasTargetedType(modelInstances.get(3), exactTypes), "Instance 3 with 'exactTypes'"),
() -> Assertions.assertFalse(UndocumentedModelElementInconsistencyInformant.modelInstanceHasTargetedType(modelInstances.get(4), exactTypes),
"Instance 4 with 'types'"), () -> Assertions.assertTrue(UndocumentedModelElementInconsistencyInformant.modelInstanceHasTargetedType(
modelInstances.get(0), shortenedType), "Instance 0 with 'shortenedType'"), () -> Assertions.assertTrue(
UndocumentedModelElementInconsistencyInformant.modelInstanceHasTargetedType(modelInstances.get(1), shortenedType),
"Instance 1 with 'shortenedType'"), () -> Assertions.assertFalse(UndocumentedModelElementInconsistencyInformant
.modelInstanceHasTargetedType(modelInstances.get(2), shortenedType), "Instance 2 with 'shortenedType'"),
() -> Assertions.assertTrue(UndocumentedModelElementInconsistencyInformant.modelInstanceHasTargetedType(modelInstances.get(3), shortenedType),
"Instance 3 with 'shortenedType'"), () -> Assertions.assertTrue(UndocumentedModelElementInconsistencyInformant
.modelInstanceHasTargetedType(modelInstances.get(4), shortenedType), "Instance 4 with 'shortenedType'"));
() -> Assertions.assertTrue(UndocumentedModelElementInconsistencyInformant.modelInstanceHasTargetedType(modelInstances.get(4), exactTypes),
"Instance 4 with 'types'")
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ModelExtractionStateImpl(String modelId, Metamodel metamodelType, Immutab
*/
private void collectTypesAndNames() {
for (Entity i : entities) {
entityTypes.add(i.getClass().getName());
entityTypes.add(i.getClass().getSimpleName());
names.addAll(Arrays.stream(i.getName().split(" ")).toList());
}
}
Expand All @@ -82,7 +82,7 @@ public Metamodel getMetamodel() {
*/
@Override
public ImmutableList<Entity> getEntitiesOfType(String type) {
return entities.select(i -> i.getClass().getName().equals(type));
return entities.select(i -> i.getClass().getSimpleName().equals(type));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void write(Path targetFile, ArDoCoResult arDoCoResult, String mode
builder.append(VALUE_SEPARATOR);
builder.append(entity.getName());
builder.append(VALUE_SEPARATOR);
builder.append(entity.getClass().getName());
builder.append(entity.getClass().getSimpleName());
builder.append(VALUE_SEPARATOR);

builder.append(df.format(instanceLink.getConfidence()));
Expand Down Expand Up @@ -142,7 +142,7 @@ public static boolean writeDiff(Path sourceFile, Path targetFile, Path diffFile,

String uid = currentModelInstance.getId();
String modelName = currentModelInstance.getName();
String modelType = currentModelInstance.getClass().getName();
String modelType = currentModelInstance.getClass().getSimpleName();
String linkProbability = df.format(currentLink.getConfidence());
ImmutableList<String> sentences = currentTextInstance.getSentenceNumbers().toSortedList().collect(no -> Integer.toString(no)).toImmutable();
String name = currentTextInstance.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void save(Path targetFile, Map<Project, ArDoCoResult> dataMap) thr
.append("]: \"")
.append(model.getName())
.append("\" (")
.append(model.getClass().getName())
.append(model.getClass().getSimpleName())
.append(") (")
.append(String.join(", ", model.getNameParts()))
.append(")")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ private static String createFalseLinkOutput(ArDoCoResult data, Text text, TestLi
}

static String format(TestLink link, Text text, ModelExtractionState modelState) {
var model = modelState.getInstances().stream().filter(m -> m.getUid().equals(link.modelId())).findAny().orElse(null);
var model = modelState.getEntities().stream().filter(m -> m.getId().equals(link.modelId())).findAny().orElse(null);
var sentence = text.getSentences().stream().filter(s -> s.getSentenceNumber() == link.sentenceNr()).findAny().orElse(null);

if (model == null && sentence == null) {
return null;
}

var modelStr = model == null ? link.modelId() : "\"" + model.getFullName() + "\"";
var modelStr = model == null ? link.modelId() : "\"" + model.getName() + "\"";
var sentenceStr = sentence == null ? String.valueOf(link.sentenceNr()) : "\"" + sentence.getText() + "\"";

return String.format("%s ⇔ %s [%s,%s]", modelStr, sentenceStr, link.modelId(), link.sentenceNr());
Expand Down

0 comments on commit c228589

Please sign in to comment.