Skip to content

Commit

Permalink
Change Namespace equality to consider parts order.
Browse files Browse the repository at this point in the history
Not taking into account the order of parts made namespace behavior
non-intuitive.

Closes: junit-team#646
  • Loading branch information
gaganis committed Feb 27, 2017
1 parent 36ef92c commit fc2f15d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
2 changes: 2 additions & 0 deletions documentation/src/docs/asciidoc/release-notes-5.0.0-M4.adoc
Expand Up @@ -34,6 +34,8 @@ on GitHub.
* `--hide-details` option of the `ConsoleLauncher` is deprecated, use `--details none` instead.
* The ZIP distribution containing the console launcher is no longer provided. It is replaced
by an executable standalone JAR distribution. For details, see "New Features" section below.
* ExtensionContext composite Namespaces with the same parts but in different order will
not be considered equal.

===== New Features

Expand Down
Expand Up @@ -14,9 +14,10 @@

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -307,9 +308,9 @@ class Namespace {

/**
* Create a namespace which restricts access to data to all extensions
* which use the same {@code parts} for creating a namespace.
* which use the same sequence of {@code parts} for creating a namespace.
*
* <p>The order of the {@code parts} is not significant.
* <p>The order of the {@code parts} is significant.
*
* <p>Internally the {@code parts} are compared using {@link Object#equals(Object)}.
*/
Expand All @@ -319,10 +320,10 @@ public static Namespace create(Object... parts) {
return new Namespace(parts);
}

private final Set<?> parts;
private final List<?> parts;

private Namespace(Object... parts) {
this.parts = new HashSet<>(Arrays.asList(parts));
this.parts = new ArrayList<>(Arrays.asList(parts));
}

@Override
Expand Down
Expand Up @@ -11,6 +11,7 @@
package org.junit.jupiter.engine.execution;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

Expand Down Expand Up @@ -312,6 +313,22 @@ void valueFromParentCanBeOverriddenInChild() {
@Nested
class CompositeNamespaceTests {

@Test
void namespacesEqualForSamePartsSequence() {
Namespace ns1 = Namespace.create("part1", "part2");
Namespace ns2 = Namespace.create("part1", "part2");

assertEquals(ns1, ns2);
}

@Test
void orderOfNamespacePartsDoesMatter() {
Namespace ns1 = Namespace.create("part1", "part2");
Namespace ns2 = Namespace.create("part2", "part1");

assertNotEquals(ns1, ns2);
}

@Test
void additionNamespacePartMakesADifferenc() {

Expand All @@ -329,18 +346,6 @@ void additionNamespacePartMakesADifferenc() {
assertEquals(value2, store.get(ns2, key));
}

@Test
void orderOfNamespacePartsDoesNotMatter() {

Namespace ns1 = Namespace.create("part1", "part2");
Namespace ns2 = Namespace.create("part2", "part1");

parentStore.put(ns1, key, value);

assertEquals(value, store.get(ns1, key));
assertEquals(value, store.get(ns2, key));
}

}

private Object createObject(final String display) {
Expand Down

0 comments on commit fc2f15d

Please sign in to comment.