@Inject public RequestInfoXPathSet( AdsApiConfiguration apiConfig, NodeExtractor nodeExtractor, Supplier<Transformer> transformerSupplier, @Named("libLogger") Logger libLogger) { Preconditions.checkNotNull(apiConfig); this.contextXPath = new IterableXPath(apiConfig.getRequestContextXPath()); this.contextName = Iterables.isEmpty(this.contextXPath) ? null : Iterables.getLast(this.contextXPath); this.nodeExtractor = Preconditions.checkNotNull(nodeExtractor); this.transformerSupplier = Preconditions.checkNotNull(transformerSupplier); this.libLogger = Preconditions.checkNotNull(libLogger); }
@Inject public RequestInfoXPathSet( AdsApiConfiguration apiConfig, NodeExtractor nodeExtractor, Supplier<Transformer> transformerSupplier, @Named("libLogger") Logger libLogger) { Preconditions.checkNotNull(apiConfig); this.contextXPath = new IterableXPath(apiConfig.getRequestContextXPath()); this.contextName = Iterables.isEmpty(this.contextXPath) ? null : Iterables.getLast(this.contextXPath); this.nodeExtractor = Preconditions.checkNotNull(nodeExtractor); this.transformerSupplier = Preconditions.checkNotNull(transformerSupplier); this.libLogger = Preconditions.checkNotNull(libLogger); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(apiConfig.getRequestContextXPath()).thenReturn("/foo/bar"); xPathSet = new RequestInfoXPathSet(apiConfig, nodeExtractor, transformerSupplier, logger); }
@Test public void testToString() { when(apiConfig.getRequestContextXPath()).thenReturn("/foo/bar"); String toString = xPathSet.toString(); assertThat( "Missing label for context XPath", toString, Matchers.containsString("contextXPath")); assertThat( "toString should contain all of the context XPath elements", toString, Matchers.stringContainsInOrder(Arrays.asList("foo", "bar"))); assertThat("Missing label for context name", toString, Matchers.containsString("contextName")); } }
@Test public void testGettersWithNullConfigXPaths() { when(apiConfig.getRequestContextXPath()).thenReturn(null); xPathSet = new RequestInfoXPathSet(apiConfig, nodeExtractor, transformerSupplier, logger); assertNull( "getContextName should have returned null when no context XPath was supplied", xPathSet.getContextName()); assertFalse( "getContextXPath should have returned an empty iterator when no context XPath was supplied", xPathSet.getContextXPath().iterator().hasNext()); }