ImportGremlinPlugin extends AbstractGremlinPlugin { public static Builder build() { return new Builder(); } private  ImportGremlinPlugin(final Builder builder); static Builder build();  }
@Test(expected = IllegalStateException.class) public void shouldImportSomething() { ImportGremlinPlugin.build().create(); }
@Test public void shouldImportClass() { final ImportGremlinPlugin module = ImportGremlinPlugin.build() .classImports(Collections.singletonList(Graph.class.getCanonicalName())).create(); final DefaultImportCustomizer customizer = (DefaultImportCustomizer) module.getCustomizers().get()[0]; assertEquals(1, module.getCustomizers().get().length); assertThat(customizer.getClassImports(), hasItems(Graph.class)); assertEquals(1, customizer.getClassImports().size()); }
@Test public void shouldImportWildcardMethod() throws Exception { final Method zeroArgs = Gremlin.class.getMethod("version"); final ImportGremlinPlugin module = ImportGremlinPlugin.build() .methodImports(Collections.singletonList(Gremlin.class.getCanonicalName() + "#*")).create(); final DefaultImportCustomizer customizer = (DefaultImportCustomizer) module.getCustomizers().get()[0]; assertEquals(1, module.getCustomizers().get().length); assertThat(customizer.getMethodImports(), hasItems(zeroArgs)); assertEquals(2, customizer.getMethodImports().size()); }
@Test public void shouldImportZeroArgMethod() throws Exception { final Method zeroArgs = Gremlin.class.getMethod("version"); final ImportGremlinPlugin module = ImportGremlinPlugin.build() .methodImports(Collections.singletonList(toMethodDescriptor(zeroArgs))).create(); final DefaultImportCustomizer customizer = (DefaultImportCustomizer) module.getCustomizers().get()[0]; assertEquals(1, module.getCustomizers().get().length); assertThat(customizer.getMethodImports(), hasItems(zeroArgs)); assertEquals(1, customizer.getMethodImports().size()); }
@Test public void shouldImportSingleArgMethod() throws Exception { final Method singleArg = IoCore.class.getMethod("createIoBuilder", String.class); final ImportGremlinPlugin module = ImportGremlinPlugin.build() .methodImports(Collections.singletonList(toMethodDescriptor(singleArg))).create(); final DefaultImportCustomizer customizer = (DefaultImportCustomizer) module.getCustomizers().get()[0]; assertEquals(1, module.getCustomizers().get().length); assertThat(customizer.getMethodImports(), hasItems(singleArg)); assertEquals(1, customizer.getMethodImports().size()); }
@Test public void shouldThrowExceptionIfInvalidMethodDescriptor() throws Exception { final String badDescriptor = "Gremlin*version"; try { ImportGremlinPlugin.build() .methodImports(Collections.singletonList(badDescriptor)).create(); fail("Should have failed parsing the method descriptor"); } catch (IllegalArgumentException iae) { assertEquals(iae.getMessage(), "Could not read method descriptor - check format of: " + badDescriptor); } }
@Test public void shouldImportWildcardEnum() throws Exception { final ImportGremlinPlugin module = ImportGremlinPlugin.build() .enumImports(Collections.singletonList(T.class.getCanonicalName() + "#*")).create(); final DefaultImportCustomizer customizer = (DefaultImportCustomizer) module.getCustomizers().get()[0]; assertEquals(1, module.getCustomizers().get().length); assertThat(customizer.getEnumImports(), hasItems(T.id, T.key, T.label, T.value)); assertEquals(4, customizer.getEnumImports().size()); }
@Test public void shouldImportEnum() throws Exception { final ImportGremlinPlugin module = ImportGremlinPlugin.build() .enumImports(Collections.singletonList(T.class.getCanonicalName() + "#" + T.id.name())).create(); final DefaultImportCustomizer customizer = (DefaultImportCustomizer) module.getCustomizers().get()[0]; assertEquals(1, module.getCustomizers().get().length); assertThat(customizer.getEnumImports(), hasItems(T.id)); }
@Test public void shouldImportFields() throws Exception { final Field field = Math.class.getField("PI"); final ImportGremlinPlugin module = ImportGremlinPlugin.build() .fieldsImports(Collections.singletonList(Math.class.getCanonicalName() + "#" + field.getName())).create(); final DefaultImportCustomizer customizer = (DefaultImportCustomizer) module.getCustomizers().get()[0]; assertEquals(1, module.getCustomizers().get().length); assertThat(customizer.getFieldImports(), hasItems(field)); }
@Test public void shouldImportWildcardFields() throws Exception { final ImportGremlinPlugin module = ImportGremlinPlugin.build() .fieldsImports(Collections.singletonList(Math.class.getCanonicalName() + "#*")).create(); final DefaultImportCustomizer customizer = (DefaultImportCustomizer) module.getCustomizers().get()[0]; assertThat(customizer.getFieldImports(), is(ImmutableSet.of(Math.class.getField("PI"), Math.class.getField("E")))); }
@Test public void shouldThrowExceptionIfInvalidEnumDescriptor() throws Exception { final String badDescriptor = "T*id"; try { ImportGremlinPlugin.build() .enumImports(Collections.singletonList(badDescriptor)).create(); fail("Should have failed parsing the enum descriptor"); } catch (IllegalArgumentException iae) { assertEquals("Could not read enum descriptor - check format of: " + badDescriptor, iae.getMessage()); } }