{"action":"created","issue":{"url":"https://api.github.com/repos/junit-team/junit5/issues/496","repository_url":"https://api.github.com/repos/junit-team/junit5","labels_url":"https://api.github.com/repos/junit-team/junit5/issues/496/labels{/name}","comments_url":"https://api.github.com/repos/junit-team/junit5/issues/496/comments","events_url":"https://api.github.com/repos/junit-team/junit5/issues/496/events","html_url":"https://github.com/junit-team/junit5/issues/496","id":175330393,"number":496,"title":"Provide consistent Precondition behavior for arrays and collections","user":{"login":"britter","id":1327662,"avatar_url":"https://avatars.githubusercontent.com/u/1327662?v=3","gravatar_id":"","url":"https://api.github.com/users/britter","html_url":"https://github.com/britter","followers_url":"https://api.github.com/users/britter/followers","following_url":"https://api.github.com/users/britter/following{/other_user}","gists_url":"https://api.github.com/users/britter/gists{/gist_id}","starred_url":"https://api.github.com/users/britter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/britter/subscriptions","organizations_url":"https://api.github.com/users/britter/orgs","repos_url":"https://api.github.com/users/britter/repos","events_url":"https://api.github.com/users/britter/events{/privacy}","received_events_url":"https://api.github.com/users/britter/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/junit-team/junit5/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/junit-team/junit5/labels/Platform","name":"Platform","color":"11dd99"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/junit-team/junit5/milestones/6","html_url":"https://github.com/junit-team/junit5/milestones/5.0%20M3","labels_url":"https://api.github.com/repos/junit-team/junit5/milestones/6/labels","id":1885703,"number":6,"title":"5.0 M3","description":"Themes: JUnit 4 interoperability, additional discovery selectors, documentation","creator":{"login":"sbrannen","id":104798,"avatar_url":"https://avatars.githubusercontent.com/u/104798?v=3","gravatar_id":"","url":"https://api.github.com/users/sbrannen","html_url":"https://github.com/sbrannen","followers_url":"https://api.github.com/users/sbrannen/followers","following_url":"https://api.github.com/users/sbrannen/following{/other_user}","gists_url":"https://api.github.com/users/sbrannen/gists{/gist_id}","starred_url":"https://api.github.com/users/sbrannen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbrannen/subscriptions","organizations_url":"https://api.github.com/users/sbrannen/orgs","repos_url":"https://api.github.com/users/sbrannen/repos","events_url":"https://api.github.com/users/sbrannen/events{/privacy}","received_events_url":"https://api.github.com/users/sbrannen/received_events","type":"User","site_admin":false},"open_issues":34,"closed_issues":45,"state":"open","created_at":"2016-07-15T14:13:22Z","updated_at":"2016-09-08T14:56:40Z","due_on":"2016-09-30T04:00:00Z","closed_at":null},"comments":7,"created_at":"2016-09-06T19:29:39Z","updated_at":"2016-09-08T17:23:56Z","closed_at":null,"body":"After reading @sbrannen comment in #493 I had a look at the `Preconditions` class. Currently the implementation of `notNull(Object[])` checks that the array reference is not null and that the array does not contain any null values. The counterpart for Collections is `notEmpty(Collection)`, which checks that the given collection is not null and that it is not empty.\r\n\r\nLooking at for example the`TagsFilter` class and how it checks its input parameters:\r\n\r\n```java\r\npublic static PostDiscoveryFilter excludeTags(String... tags) {\r\n\tPreconditions.notNull(tags, \"tags must not be null\");\r\n\treturn excludeTags(asList(tags));\r\n}\r\n\r\npublic static PostDiscoveryFilter excludeTags(List<String> tags) {\r\n\tPreconditions.notEmpty(tags, \"tags must not be null or empty\");\r\n\treturn descriptor -> FilterResult.includedIf(trimmedTagsOf(descriptor).noneMatch(tags::contains));\r\n}\r\n```\r\n\r\nWe can conclude that:\r\n\r\nMethod call | Result\r\n--------------------|------------\r\n `excludeTags(null)` | Exception \r\n `excludeTags((String[]) null)` | Exception \r\n `excludeTags(new String[0]())` | okay \r\n `excludeTags(Collections.singletonList(null))` | okay \r\n `excludeTags((List<String>) null)` | Exception \r\n `excludeTags(Collections.emptyList())` | Exceptions\r\n\r\nMy proposal here would be to introduce new methods:\r\n\r\n* `Preconditions.noneNull(Collection)`\r\n* `Preconditions.noneNull(Object[])`\r\n\r\nThese would check that the reference is not null, that the collection/array does not contain any null reference and that the collection/array is not empty. The last check does not really match the method name but I can't think of a better name right now..."},"comment":{"url":"https://api.github.com/repos/junit-team/junit5/issues/comments/245672974","html_url":"https://github.com/junit-team/junit5/issues/496#issuecomment-245672974","issue_url":"https://api.github.com/repos/junit-team/junit5/issues/496","id":245672974,"user":{"login":"sbrannen","id":104798,"avatar_url":"https://avatars.githubusercontent.com/u/104798?v=3","gravatar_id":"","url":"https://api.github.com/users/sbrannen","html_url":"https://github.com/sbrannen","followers_url":"https://api.github.com/users/sbrannen/followers","following_url":"https://api.github.com/users/sbrannen/following{/other_user}","gists_url":"https://api.github.com/users/sbrannen/gists{/gist_id}","starred_url":"https://api.github.com/users/sbrannen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbrannen/subscriptions","organizations_url":"https://api.github.com/users/sbrannen/orgs","repos_url":"https://api.github.com/users/sbrannen/repos","events_url":"https://api.github.com/users/sbrannen/events{/privacy}","received_events_url":"https://api.github.com/users/sbrannen/received_events","type":"User","site_admin":false},"created_at":"2016-09-08T17:23:56Z","updated_at":"2016-09-08T17:23:56Z","body":"Hmmmmm.... I changed my mind: it's not as straightforward as it appears.\r\n\r\nWe have use cases where an _empty_ array is acceptable _but_ `null` values in the array are not acceptable.\r\n\r\nSo we can't simply get rid of `notNull(Object[], String)` like I originally thought/hoped."}}
{"actor":{"display_login":"sbrannen"}}