@Test public void testRunWith() throws Exception { String specString = "org.pantsbuild.tools.junit.lib.MockRunWithTest"; SpecParser parser = new SpecParser(ImmutableList.of(specString)); List<Spec> specs = parser.parse(); assertEquals(1, specs.size()); assertEquals(MockRunWithTest.class, specs.get(0).getSpecClass()); }
@Test public void testMissingMethod() { String specString = DUMMY_CLASS_NAME + "#doesNotExist"; SpecParser parser = new SpecParser(ImmutableList.of(specString)); try { parser.parse(); } catch (SpecException expected) { assertThat(expected.getMessage(), containsString("Method doesNotExist not found in class")); } }
@Test public void testMissingClass() { String specString = "org.foo.bar.Baz"; SpecParser parser = new SpecParser(ImmutableList.of(specString)); try { parser.parse(); } catch (SpecException expected) { assertThat(expected.getMessage(), containsString("Class org.foo.bar.Baz not found")); } }
@Test public void testBadSpec() { String specString = DUMMY_CLASS_NAME + "#" + DUMMY_METHOD_NAME + "#" + "foo"; SpecParser parser = new SpecParser(ImmutableList.of(DUMMY_CLASS_NAME, specString)); try { parser.parse(); } catch (SpecException expected) { assertThat(expected.getMessage(), containsString("Expected only one # in spec")); } }
@Test public void testParserClass() throws Exception { SpecParser parser = new SpecParser(ImmutableList.of(DUMMY_CLASS_NAME)); List<Spec> specs = parser.parse(); assertEquals(1, specs.size()); Spec spec = specs.get(0); assertEquals(UnannotatedTestClass.class, spec.getSpecClass()); assertEquals(DUMMY_CLASS_NAME, spec.getSpecName()); assertEquals(0, spec.getMethods().size()); }
@Test public void testParserMethod() throws Exception { String specString = DUMMY_CLASS_NAME + "#" + DUMMY_METHOD_NAME; SpecParser parser = new SpecParser(ImmutableList.of(specString)); List<Spec> specs = parser.parse(); assertEquals(1, specs.size()); Spec spec = specs.get(0); assertEquals(UnannotatedTestClass.class, spec.getSpecClass()); assertEquals(DUMMY_CLASS_NAME, spec.getSpecName()); assertEquals(ImmutableList.of(DUMMY_METHOD_NAME), spec.getMethods()); }
@Test public void testMethodDupsClass() throws Exception { String specString = DUMMY_CLASS_NAME + "#" + DUMMY_METHOD_NAME; SpecParser parser = new SpecParser(ImmutableList.of(DUMMY_CLASS_NAME, specString)); try { parser.parse(); } catch (SpecException expected) { assertThat( expected.getMessage(), containsString("Request for entire class already requesting individual methods")); } }
private void assertNoSpecs(String className) throws Exception { String specString = "org.pantsbuild.tools.junit.lib." + className; SpecParser parser = new SpecParser(ImmutableList.of(specString)); List<Spec> specs = parser.parse(); assertTrue(specs.isEmpty()); }