@Test public void testStateTest() throws Exception { class TestCase { private Experiment.State state; private String filter; private boolean result; TestCase(Experiment.State state, String filter, boolean result) { this.state = state; this.filter = filter; this.result = result; } } List<TestCase> testCases = new ArrayList<>(); testCases.add(new TestCase(Experiment.State.DRAFT, "notterminated", true)); testCases.add(new TestCase(Experiment.State.DRAFT, "draft", true)); testCases.add(new TestCase(Experiment.State.DRAFT, "any", true)); testCases.add(new TestCase(Experiment.State.RUNNING, "notterminated", true)); testCases.add(new TestCase(Experiment.State.RUNNING, "running", true)); testCases.add(new TestCase(Experiment.State.RUNNING, "any", true)); testCases.add(new TestCase(Experiment.State.PAUSED, "notterminated", true)); testCases.add(new TestCase(Experiment.State.PAUSED, "paused", true)); testCases.add(new TestCase(Experiment.State.PAUSED, "any", true)); testCases.add(new TestCase(Experiment.State.TERMINATED, "terminated", true)); testCases.add(new TestCase(Experiment.State.TERMINATED, "any", true)); testCases.add(new TestCase(Experiment.State.DRAFT, "terminated", false)); testCases.add(new TestCase(Experiment.State.DRAFT, "running", false)); testCases.add(new TestCase(Experiment.State.DRAFT, "paused", false)); testCases.add(new TestCase(Experiment.State.RUNNING, "terminated", false)); testCases.add(new TestCase(Experiment.State.RUNNING, "draft", false)); testCases.add(new TestCase(Experiment.State.RUNNING, "paused", false)); testCases.add(new TestCase(Experiment.State.PAUSED, "terminated", false)); testCases.add(new TestCase(Experiment.State.PAUSED, "running", false)); testCases.add(new TestCase(Experiment.State.PAUSED, "draft", false)); testCases.add(new TestCase(Experiment.State.TERMINATED, "notterminated", false)); testCases.add(new TestCase(Experiment.State.TERMINATED, "running", false)); testCases.add(new TestCase(Experiment.State.TERMINATED, "draft", false)); testCases.add(new TestCase(Experiment.State.TERMINATED, "paused", false)); testCases.add(new TestCase(Experiment.State.DELETED, "notterminated", false)); testCases.add(new TestCase(Experiment.State.DELETED, "terminated", false)); testCases.add(new TestCase(Experiment.State.DELETED, "running", false)); testCases.add(new TestCase(Experiment.State.DELETED, "draft", false)); testCases.add(new TestCase(Experiment.State.DELETED, "paused", false)); testCases.add(new TestCase(Experiment.State.DELETED, "any", false)); testCases.add(new TestCase(Experiment.State.RUNNING, "nonexistent", false)); for (TestCase testCase : testCases) { Assert.assertEquals(testCase.state + " should " + (testCase.result ? "" : "not ") + "match " + testCase.filter, testCase.result, ExperimentFilter.stateTest(testCase.state, testCase.filter)); } }
static boolean stateTest(Experiment.State state, String filter) { if (state == Experiment.State.DELETED) { return false; } switch (filter.toLowerCase()) { case "notterminated": return state == Experiment.State.DRAFT || state == Experiment.State.RUNNING || state == Experiment.State.PAUSED; case "terminated": return state == Experiment.State.TERMINATED; case "running": return state == Experiment.State.RUNNING; case "draft": return state == Experiment.State.DRAFT; case "paused": return state == Experiment.State.PAUSED; case "any": return true; default: return false; } }
ExperimentFilter extends PaginationFilter<Experiment> { static boolean stateTest(Experiment.State state, String filter) { if (state == Experiment.State.DELETED) { return false; } switch (filter.toLowerCase()) { case "notterminated": return state == Experiment.State.DRAFT || state == Experiment.State.RUNNING || state == Experiment.State.PAUSED; case "terminated": return state == Experiment.State.TERMINATED; case "running": return state == Experiment.State.RUNNING; case "draft": return state == Experiment.State.DRAFT; case "paused": return state == Experiment.State.PAUSED; case "any": return true; default: return false; } } }
ExperimentFilter extends PaginationFilter<Experiment> { static boolean stateTest(Experiment.State state, String filter) { if (state == Experiment.State.DELETED) { return false; } switch (filter.toLowerCase()) { case "notterminated": return state == Experiment.State.DRAFT || state == Experiment.State.RUNNING || state == Experiment.State.PAUSED; case "terminated": return state == Experiment.State.TERMINATED; case "running": return state == Experiment.State.RUNNING; case "draft": return state == Experiment.State.DRAFT; case "paused": return state == Experiment.State.PAUSED; case "any": return true; default: return false; } } ExperimentFilter(); }
ExperimentFilter extends PaginationFilter<Experiment> { static boolean stateTest(Experiment.State state, String filter) { if (state == Experiment.State.DELETED) { return false; } switch (filter.toLowerCase()) { case "notterminated": return state == Experiment.State.DRAFT || state == Experiment.State.RUNNING || state == Experiment.State.PAUSED; case "terminated": return state == Experiment.State.TERMINATED; case "running": return state == Experiment.State.RUNNING; case "draft": return state == Experiment.State.DRAFT; case "paused": return state == Experiment.State.PAUSED; case "any": return true; default: return false; } } ExperimentFilter(); @Override boolean test(Experiment experiment); }
ExperimentFilter extends PaginationFilter<Experiment> { static boolean stateTest(Experiment.State state, String filter) { if (state == Experiment.State.DELETED) { return false; } switch (filter.toLowerCase()) { case "notterminated": return state == Experiment.State.DRAFT || state == Experiment.State.RUNNING || state == Experiment.State.PAUSED; case "terminated": return state == Experiment.State.TERMINATED; case "running": return state == Experiment.State.RUNNING; case "draft": return state == Experiment.State.DRAFT; case "paused": return state == Experiment.State.PAUSED; case "any": return true; default: return false; } } ExperimentFilter(); @Override boolean test(Experiment experiment);  }