### Question:
IndexRequest implements Request { @Override public String getURI() { StringBuilder sb = new StringBuilder(ESTIMATED_URI_LENGTH); try { sb.append(encode(index)) .append(FORWARD_SLASH) .append(encode(type)); if (id != null) { sb.append(FORWARD_SLASH).append(encode(id)); } } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(e.getMessage()); } return sb.toString(); } protected  IndexRequest(Builder builder); String getId(); String getIndex(); String getType(); final ItemSource<ByteBuf> getSource(); @Override String getURI(); @Override String getHttpMethodName(); @Override ItemSource serialize(); void release(); static final String HTTP_METHOD_NAME; static final int ESTIMATED_URI_LENGTH; static final String FORWARD_SLASH; }### Answer:
@Test public void urlContainsIdIfSpecified() { ByteBufItemSource expectedItemSource = mock(ByteBufItemSource.class); String expectedId = UUID.randomUUID().toString(); String expectedIndex = UUID.randomUUID().toString(); String expectedMappingType = UUID.randomUUID().toString(); IndexRequest.Builder builder = createIndexRequestBuilder( expectedItemSource, expectedId, expectedIndex, expectedMappingType); IndexRequest request = builder.build(); assertTrue(request.getURI().contains(expectedId)); }
@Test public void urlDoesNotContainIdIfIdNotSpecified() { ByteBufItemSource expectedItemSource = mock(ByteBufItemSource.class); String expectedId = UUID.randomUUID().toString(); String expectedIndex = UUID.randomUUID().toString(); String expectedMappingType = UUID.randomUUID().toString(); IndexRequest.Builder builder = createIndexRequestBuilder( expectedItemSource, null, expectedIndex, expectedMappingType); IndexRequest request = builder.build(); assertFalse(request.getURI().contains(expectedId)); }
@Test public void urlContainsType() { ByteBufItemSource expectedItemSource = mock(ByteBufItemSource.class); String expectedId = UUID.randomUUID().toString(); String expectedIndex = UUID.randomUUID().toString(); String expectedType = UUID.randomUUID().toString(); IndexRequest.Builder builder = createIndexRequestBuilder( expectedItemSource, expectedId, expectedIndex, expectedType); IndexRequest request = builder.build(); assertTrue(request.getURI().contains(expectedType)); }
@Test public void urlContainsIndex() { ByteBufItemSource expectedItemSource = mock(ByteBufItemSource.class); String expectedIndexName = UUID.randomUUID().toString(); IndexRequest.Builder builder = createIndexRequestBuilder(expectedItemSource) .index(expectedIndexName); IndexRequest request = builder.build(); assertTrue(request.getURI().startsWith(expectedIndexName)); }