Skip to content

Commit

Permalink
comment addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
lbownik authored and lbownik committed Nov 28, 2024
1 parent b3f86a8 commit 7c93c95
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,7 @@ public List<DatasetVersion> getVersions() {
}

public Dataverse getRoot() {
Dataverse owner = getOwner();
while (owner.isNotRoot()) {
owner = owner.getOwner();
}
return owner;
return getOwner().getRoot();
}

public void setVersions(List<DatasetVersion> versions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,10 @@ public List<Dataverse> getOwners() {
}
return owners;
}

public Dataverse getRoot() {
return isRoot() ? this : getOwner().getRoot();
}

@Override
public boolean equals(Object object) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package edu.harvard.iq.dataverse.persistence.dataset;

import com.google.common.collect.Lists;
import edu.harvard.iq.dataverse.persistence.MocksFactory;
import edu.harvard.iq.dataverse.persistence.dataset.DatasetVersion.VersionState;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.sql.Timestamp;
import java.time.Instant;
import java.util.List;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import com.google.common.collect.Lists;

import edu.harvard.iq.dataverse.persistence.MocksFactory;
import edu.harvard.iq.dataverse.persistence.dataset.DatasetVersion.VersionState;
import edu.harvard.iq.dataverse.persistence.dataverse.Dataverse;


/**
Expand Down Expand Up @@ -115,6 +119,28 @@ public void testLocksManagement() {
assertFalse(sut.isLocked());

}

@Test
public void testGetRoot() {

Dataverse root = new Dataverse();
Dataverse child = new Dataverse();
child.setOwner(root);
Dataset grandChild = new Dataset();
grandChild.setOwner(child);

assertThat(root.getOwner()).isNull();
assertThat(root.isRoot()).isTrue();
assertThat(root.isNotRoot()).isFalse();

assertThat(child.getOwner()).isSameAs(root);
assertThat(child.isRoot()).isFalse();
assertThat(child.isNotRoot()).isTrue();
assertThat(child.getRoot()).isSameAs(root);

assertThat(grandChild.getOwner()).isSameAs(child);
assertThat(grandChild.getRoot()).isSameAs(root);
}

// -------------------- PRIVATE --------------------

Expand Down

0 comments on commit 7c93c95

Please sign in to comment.