Skip to content

Commit

Permalink
Polish test
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed May 16, 2024
1 parent 4056f66 commit 85a300c
Showing 1 changed file with 9 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
import static org.junit.platform.commons.util.SerializationUtils.deserialize;
import static org.junit.platform.commons.util.SerializationUtils.serialize;

import java.util.Optional;
import java.util.Set;

import org.junit.jupiter.api.Test;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.TestSource;
import org.junit.platform.engine.TestTag;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.support.descriptor.AbstractTestDescriptor;
Expand Down Expand Up @@ -76,70 +74,17 @@ void initialVersionCanBeDeserialized() throws Exception {

@Test
void identifierWithNoParentCanBeSerializedAndDeserialized() throws Exception {
TestIdentifier ti = TestIdentifier.from(new TestDescriptor() {
@Override
public UniqueId getUniqueId() {
return UniqueId.root("example", "id");
}

@Override
public String getDisplayName() {
return "displayName";
}

@Override
public Set<TestTag> getTags() {
return Set.of();
}

@Override
public Optional<TestSource> getSource() {
return Optional.empty();
}

@Override
public Optional<TestDescriptor> getParent() {
return Optional.empty();
}

@Override
public void setParent(TestDescriptor parent) {
// ignore
}

@Override
public Set<? extends TestDescriptor> getChildren() {
return Set.of();
}

@Override
public void addChild(TestDescriptor descriptor) {
// ignore
}
TestIdentifier originalIdentifier = TestIdentifier.from(
new AbstractTestDescriptor(UniqueId.root("example", "id"), "Example") {
@Override
public Type getType() {
return Type.CONTAINER;
}
});

@Override
public void removeChild(TestDescriptor descriptor) {
// ignore
}

@Override
public void removeFromHierarchy() {
// ignore
}

@Override
public Type getType() {
return Type.TEST;
}
var deserializedIdentifier = (TestIdentifier) deserialize(serialize(originalIdentifier));

@Override
public Optional<? extends TestDescriptor> findByUniqueId(UniqueId uniqueId) {
return Optional.empty();
}
});
byte[] bytes = serialize(ti);
TestIdentifier dti = (TestIdentifier) deserialize(bytes);
assertEquals(ti, dti);
assertDeepEquals(originalIdentifier, deserializedIdentifier);
}

private static void assertDeepEquals(TestIdentifier first, TestIdentifier second) {
Expand Down

0 comments on commit 85a300c

Please sign in to comment.