Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encapsulate attributes for ExtensionContext #82

Closed
jlink opened this issue Dec 29, 2015 · 12 comments
Closed

Encapsulate attributes for ExtensionContext #82

jlink opened this issue Dec 29, 2015 · 12 comments
Assignees
Milestone

Comments

@jlink
Copy link
Contributor

jlink commented Dec 29, 2015

Encapsulate attributes for Test|ContainerExtensionContext:

  • do not expose map
  • delegate attribute retrieval to parent
@jlink jlink added this to the Alpha 1 milestone Dec 29, 2015
@jlink jlink mentioned this issue Dec 29, 2015
13 tasks
@jlink
Copy link
Contributor Author

jlink commented Dec 29, 2015

Implemented encapsulating methods in cf91ce4

@jlink
Copy link
Contributor Author

jlink commented Dec 29, 2015

Alternative suggestion

Extend ExtensionContext with

interface ExtensionContext {
  Object get(Object key);
  void store(Object key, Object value, Visibility visibility);
  default   void store(Object key, Object value) {
    store(key, value, Visibility.DEFAULT);
  }
}

and

enum Visibility {
  DEFAULT, //visible only in this extension but inherited from ancestor extension contexts
  EXTENSION, //visible only in this extension but in the full tree of extension contexts
  LOCAL, //only visible in this extension and this extension context
  GLOBAL //visible in all extensions and in the full tree of extension contexts
}

This would then replace ContextScope and get|setAttribute.

@jlink
Copy link
Contributor Author

jlink commented Jan 15, 2016

Team decision for the time being:
Implement the following:

 interface ExtensionContext...

    default Object get(Object key) {
        return get(key, "");
    }

    Object get(Object key, String namespace);

    default void put(Object key, Object value) {
        put(key, value, "");
    }

    void put(Object key, Object value, String namespace);

    Object getOrComputeIfAbsent(Object key, Function<Object, Object> defaultProvider, String namespace) {
        Object value = get(key);
        if (value == null) {
            value = defaultProvider.apply(key);
            put(key, value, visibility);
        }
        return value;
    }

    default Object getOrComputeIfAbsent(Object key, Function<Object, Object> defaultProvider) {
        return getOrComputeIfAbsent(key, defaultProvider, "");
    }

Choose a suitable value for default namespace, e.g. have an object internally but only allow Strings from outside.

@jlink jlink self-assigned this Jan 15, 2016
@jlink
Copy link
Contributor Author

jlink commented Jan 15, 2016

I'm working on it.

@jlink
Copy link
Contributor Author

jlink commented Jan 16, 2016

I suggest other changes in addition to the ones above:

  • extract put/get/etc into an interface Store
  • make the store available via ExtensionContext.getStore()
  • Alternative 1: Remove overloaded methods and provide ExtensionContext.getStore(String namespace)
  • Alternative 2: Make store available as a separate parameter in all extension points to communicate clearly: That's the way to persist state
  • Encapsulate namespace in a Namespace value object with static utility methods like Namespace.DEFAULT, Namespace.localFor(anObject1, anObject2), Namespace.forClass() etc.

Feedback?

@jlink
Copy link
Contributor Author

jlink commented Jan 16, 2016

What I'm planning to do is implement it in master but leave the old attributes in place. Thus you can all see how it looks but no existing functionality must be touched.

Any objections?

@bechte
Copy link
Contributor

bechte commented Jan 16, 2016

For any new features, for which we do not yet know in which direction we should go, I would strongly recommend not to work in master. That's exactly what I am doing with the discovery mechanism.

@jlink
Copy link
Contributor Author

jlink commented Jan 16, 2016

Ok. I'll only do in master on what we agreed yesterday.

Am 16.01.2016 um 12:36 schrieb Stefan Bechtold notifications@github.com:

For anything new features, for which we do not yet know in which direction we should go, I would strongly recommend not to work in master. That's exactly what I am doing with the discovery mechanism.


Reply to this email directly or view it on GitHub.

@jlink
Copy link
Contributor Author

jlink commented Jan 17, 2016

Agreed changes are done in master. Suggestions from above must still be discussed.

sbrannen added a commit that referenced this issue Jan 17, 2016
This commit refactors ExtensionContext and related classes so that the
recently introduced remove() methods return the previous value stored
under the associated key/namespace, analogous to the current behavior of
removeAttribute().

Issue: #82
@jlink
Copy link
Contributor Author

jlink commented Jan 18, 2016

Implemented suggestion in https://github.com/junit-team/junit5/tree/issue82-store for review

@jlink
Copy link
Contributor Author

jlink commented Jan 19, 2016

Merged suggestion after team decision in #128.

Missing:

  • Remove all usages of ExtensionContext.put/get/removeAttribute
  • Remove implementation of ExtensionContext.put/get/removeAttribute

@jlink
Copy link
Contributor Author

jlink commented Jan 19, 2016

Resolved in e103a16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants