{"action":"created","issue":{"url":"https://api.github.com/repos/junit-team/junit/issues/1092","labels_url":"https://api.github.com/repos/junit-team/junit/issues/1092/labels{/name}","comments_url":"https://api.github.com/repos/junit-team/junit/issues/1092/comments","events_url":"https://api.github.com/repos/junit-team/junit/issues/1092/events","html_url":"https://github.com/junit-team/junit/issues/1092","id":60179905,"number":1092,"title":"Request: Add \"Otherwise\" to Theories","user":{"login":"EarthCitizen","id":1094129,"avatar_url":"https://avatars.githubusercontent.com/u/1094129?v=3","gravatar_id":"","url":"https://api.github.com/users/EarthCitizen","html_url":"https://github.com/EarthCitizen","followers_url":"https://api.github.com/users/EarthCitizen/followers","following_url":"https://api.github.com/users/EarthCitizen/following{/other_user}","gists_url":"https://api.github.com/users/EarthCitizen/gists{/gist_id}","starred_url":"https://api.github.com/users/EarthCitizen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EarthCitizen/subscriptions","organizations_url":"https://api.github.com/users/EarthCitizen/orgs","repos_url":"https://api.github.com/users/EarthCitizen/repos","events_url":"https://api.github.com/users/EarthCitizen/events{/privacy}","received_events_url":"https://api.github.com/users/EarthCitizen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-07T00:37:11Z","updated_at":"2015-05-04T23:02:09Z","closed_at":null,"body":"My appologies in advance if there is a way to do this, but in my search I could not find one.\r\n\r\nIt would be immensly useful if there were an @Otherwise for theories. What this would do is execute for a datapoint or set of datapoints if, and only if, no theory method had a passing assume. This would allow the avoidance of a theory or theories that are basically just negations of all the other assumes.\r\n\r\nIn the example below, without the @Otherwise, it would be necessary to write multiple @Theory methods to have all of the paths leading to false. The other alternative would be have another set of datapoints that should all return false, but that does not allow the potential to catch possible holes in logic that are not obvious at first glance. Additionally, if the datapoints are large-volume and generated with a supplier, it could be a daunting task to make sure you catch all the \"other\" scenarios. Simply catching \"everything else\" is much easier than making sure you capture all the reverse scenarios.\r\n\r\nObviously this specific scenario below is not very complex, but is is just to demonstrate the purpose of @Otherwise.\r\n\r\n```Java\r\n@RunWith(Theories.class)\r\npublic class BooleanTest {\r\n\r\n\t@DataPoints\r\n\tpublic static Object[] values = {\r\n\t\ttrue, false, \"true\", \"false\", \"1\", \"0\", 1, 0, new Object(), null \r\n\t};\r\n\t\r\n\t@Theory\r\n\tpublic void booleanTrue(Object value) {\r\n\t\tassumeThat(value, instanceOf(Boolean.class));\r\n\t\t\r\n\t\tassertThat(convertToBoolean(value), equalTo(value));\r\n\t}\r\n\t\r\n\t@Theory\r\n\tpublic void stringTrue(Object value) {\r\n\t\tassumeThat(value, instanceOf(String.class));\r\n\t\tassumeThat((String) value, equalTo(\"true\"));\r\n\t\t\r\n\t\tassertThat(convertToBoolean(value), equalTo(true));\r\n\t}\r\n\t\r\n\t@Theory\r\n\tpublic void stringOne(Object value) {\r\n\t\tassumeThat(value, instanceOf(String.class));\r\n\t\tassumeThat((String) value, equalTo(\"1\"));\r\n\t\t\r\n\t\tassertThat(convertToBoolean(value), equalTo(true));\r\n\t}\r\n\t\r\n\t@Theory\r\n\tpublic void integerOne(Object value) {\r\n\t\tassumeThat(value, instanceOf(Integer.class));\r\n\t\tassumeThat((Integer) value, not(equalTo(0)));\r\n\t\t\r\n\t\tassertThat(convertToBoolean(value), equalTo(true));\r\n\t}\r\n\t\r\n\t@Otherwise\r\n\tpublic void allOtherCases(Object value) {\r\n\t\tassertThat(convertToBoolean(value), equalTo(false));\r\n\t}\r\n\t\r\n\tpublic static boolean convertToBoolean(Object value) {\r\n\t\tif (value instanceof Boolean) {\r\n\t\t\treturn ((Boolean) value).booleanValue();\r\n\t\t} else if (value instanceof String) {\r\n\t\t\tif (\"true\".equalsIgnoreCase((String) value)) {\r\n\t\t\t\treturn true;\r\n\t\t\t} else if (\"1\".equalsIgnoreCase((String) value)) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t} else if (value instanceof Integer) {\r\n\t\t\tif (((Integer)value) != 0) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\treturn false;\r\n\t}\r\n}\r\n```\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/junit-team/junit/issues/comments/98880562","html_url":"https://github.com/junit-team/junit/issues/1092#issuecomment-98880562","issue_url":"https://api.github.com/repos/junit-team/junit/issues/1092","id":98880562,"user":{"login":"ashleyfrieze","id":5574729,"avatar_url":"https://avatars.githubusercontent.com/u/5574729?v=3","gravatar_id":"","url":"https://api.github.com/users/ashleyfrieze","html_url":"https://github.com/ashleyfrieze","followers_url":"https://api.github.com/users/ashleyfrieze/followers","following_url":"https://api.github.com/users/ashleyfrieze/following{/other_user}","gists_url":"https://api.github.com/users/ashleyfrieze/gists{/gist_id}","starred_url":"https://api.github.com/users/ashleyfrieze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashleyfrieze/subscriptions","organizations_url":"https://api.github.com/users/ashleyfrieze/orgs","repos_url":"https://api.github.com/users/ashleyfrieze/repos","events_url":"https://api.github.com/users/ashleyfrieze/events{/privacy}","received_events_url":"https://api.github.com/users/ashleyfrieze/received_events","type":"User","site_admin":false},"created_at":"2015-05-04T23:02:09Z","updated_at":"2015-05-04T23:02:09Z","body":"This would be a big change, since the current way that the Theories runner operates is by running all permutations through each method. What you're asking is for it to run all methods through each permutation and then drop to the methods marked with Otherwise when no method is interested in this permutation.\r\n\r\nIt might be interesting to see some real-world tests you're trying to write, taken away from the syntax of any specific test runner, just to see whether any other solutions pop up."}}