### Question:
WatchBuilder { public WatchI<Domain> createDomainWatch(String namespace) throws ApiException { return FACTORY.createWatch( ClientPool.getInstance(), callParams, Domain.class, new ListDomainsCall(namespace)); } WatchBuilder(); WatchI<V1Service> createServiceWatch(String namespace); WatchI<V1Pod> createPodWatch(String namespace); WatchI<V1Job> createJobWatch(String namespace); WatchI<V1Event> createEventWatch(String namespace); WatchI<Domain> createDomainWatch(String namespace); WatchI<V1ConfigMap> createConfigMapWatch(String namespace); WatchI<V1Namespace> createNamespacesWatch(); WatchBuilder withFieldSelector(String fieldSelector); WatchBuilder withLabelSelector(String labelSelector); WatchBuilder withLabelSelectors(String... labelSelectors); WatchBuilder withResourceVersion(String resourceVersion); WatchBuilder withTimeoutSeconds(Integer timeoutSeconds);  }### Answer:
@Test public void whenDomainWatchReceivesAddResponse_returnItFromIterator() throws Exception { Domain domain = new Domain() .withApiVersion(API_VERSION) .withKind("Domain") .withMetadata(createMetaData("domain1", NAMESPACE)); defineHttpResponse(DOMAIN_RESOURCE, withResponses(createAddedResponse(domain))); WatchI<Domain> domainWatch = new WatchBuilder().createDomainWatch(NAMESPACE); assertThat(domainWatch, contains(addEvent(domain))); }
@Test public void afterWatchClosed_returnClientToPool() throws Exception { Domain domain = new Domain() .withApiVersion(API_VERSION) .withKind("Domain") .withMetadata(createMetaData("domain1", NAMESPACE)); defineHttpResponse(DOMAIN_RESOURCE, withResponses(createAddedResponse(domain))); try (WatchI<Domain> domainWatch = new WatchBuilder().createDomainWatch(NAMESPACE)) { domainWatch.next(); } assertThat(ClientPoolStub.getPooledClients(), not(empty())); }
@Test public void afterWatchError_closeDoesNotReturnClientToPool() throws Exception { defineHttpResponse(DOMAIN_RESOURCE, withResponses()); try (WatchI<Domain> domainWatch = new WatchBuilder().createDomainWatch(NAMESPACE)) { domainWatch.next(); fail("Should have thrown an exception"); } catch (Throwable ignore) { } assertThat(ClientPoolStub.getPooledClients(), is(empty())); }
@Test public void whenDomainWatchReceivesModifyAndDeleteResponses_returnBothFromIterator() throws Exception { Domain domain1 = new Domain() .withApiVersion(API_VERSION) .withKind("Domain") .withMetadata(createMetaData("domain1", NAMESPACE)); Domain domain2 = new Domain() .withApiVersion(API_VERSION) .withKind("Domain") .withMetadata(createMetaData("domain2", NAMESPACE)); defineHttpResponse( DOMAIN_RESOURCE, withResponses(createModifiedResponse(domain1), createDeletedResponse(domain2))); WatchI<Domain> domainWatch = new WatchBuilder().createDomainWatch(NAMESPACE); assertThat(domainWatch, contains(modifyEvent(domain1), deleteEvent(domain2))); }
@Test public void whenDomainWatchReceivesErrorResponse_returnItFromIterator() throws Exception { defineHttpResponse(DOMAIN_RESOURCE, withResponses(createErrorResponse(HTTP_ENTITY_TOO_LARGE))); WatchI<Domain> domainWatch = new WatchBuilder().createDomainWatch(NAMESPACE); assertThat(domainWatch, contains(errorEvent(HTTP_ENTITY_TOO_LARGE))); }