Skip to content

Commit

Permalink
Adjust valid links and related test
Browse files Browse the repository at this point in the history
  • Loading branch information
ppouchin committed Nov 15, 2024
1 parent d08bda8 commit 8dac9af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
19 changes: 4 additions & 15 deletions src/main/java/fr/igred/ij/plugin/OMEROMacroExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,6 @@ private boolean isInvalidLink(Map<String, Long> objects,
Map<String, Long> annotations) {
Long projectId = objects.get(PROJECT);
Long imageId = objects.get(IMAGE);
Long screenId = objects.get(SCREEN);
Long plateId = objects.get(PLATE);
Long wellId = objects.get(WELL);

Map<String, Long> tree = new HashMap<>(2);
tree.computeIfAbsent(PROJECT, objects::get);
tree.computeIfAbsent(DATASET, objects::get);

Map<String, Long> hcs = new HashMap<>(3);
hcs.computeIfAbsent(SCREEN, objects::get);
Expand All @@ -303,22 +296,18 @@ private boolean isInvalidLink(Map<String, Long> objects,

int nObjects = objects.values().size();
int nAnnotations = annotations.values().size();
int nTree = tree.values().size();
int nHCS = hcs.values().size();

boolean linkNotTwo = nObjects + nAnnotations != 2;
boolean linkAnnotations = nAnnotations == 2;
boolean linkTreeHCS = nTree == 1 && nHCS == 1;
boolean linkObjectHCS = nHCS >= 1 && nAnnotations == 0;

boolean linkScreenWell = screenId != null && wellId != null;
boolean linkImageBad = imageId != null &&
(projectId != null || screenId != null || plateId != null);
boolean linkProjectImage = imageId != null && projectId != null;

return linkNotTwo ||
linkAnnotations ||
linkImageBad ||
linkScreenWell ||
linkTreeHCS;
linkObjectHCS ||
linkProjectImage;
}


Expand Down
13 changes: 9 additions & 4 deletions src/test/java/fr/igred/ij/plugin/OMEROExtensionErrorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,16 @@ void testLinkUnlinkInvalidType(String function) {


@ParameterizedTest
@ValueSource(strings = {"link", "unlink"})
void testCannotLinkOrUnlink(String function) {
Object[] args = {"hello", 1.0, "world", 1.0};
@CsvSource(delimiter = ';', value = {"link;hello;1.0;world;1.0",
"unlink;hello;1.0;world;1.0",
"link;image;image",
"link;image;project",
"link;image;screen",
"link;tag;kv-pair"})
void testCannotLinkOrUnlink(String function, String type1, String type2) {
Object[] args = {type1, 1.0, type2, 1.0};
ext.handleExtension(function, args);
String expected = String.format("Cannot %s hello and world", function);
String expected = String.format("Cannot %s %s and %s", function, type1, type2);
assertEquals(expected, outContent.toString().trim());
}

Expand Down

0 comments on commit 8dac9af

Please sign in to comment.