method2testcases
stringlengths 118
6.63k
|
---|
### Question:
APIProcess extends ConsoleAPI<ProcessItem> implements
APIHasAdd<ProcessItem>,
APIHasUpdate<ProcessItem>,
APIHasGet<ProcessItem>,
APIHasSearch<ProcessItem>,
APIHasDelete { @Override protected void fillCounters(final ProcessItem item, final List<String> counters) { fillNumberOfFailedCasesIfFailedCounterExists(item, counters); fillNumberOfOpenCasesIfOpenCounterExists(item, counters); } @Override String defineDefaultSearchOrder(); @Override ProcessItem add(final ProcessItem item); @Override ProcessItem update(final APIID id, final Map<String, String> attributes); @Override ProcessItem get(final APIID id); @Override ItemSearchResult<ProcessItem> search(final int page, final int resultsByPage, final String search, final String orders,
final Map<String, String> filters); @Override void delete(final List<APIID> ids); }### Answer:
@Test public final void fillCounters_should_fill_number_of_failed_cases_when_counter_of_failed_cases_is_active() { final APIID id = APIID.makeAPIID(78L); final ProcessItem item = mock(ProcessItem.class); doReturn(id).when(item).getId(); final List<String> counters = Arrays.asList(ProcessItem.COUNTER_FAILED_CASES); final long numberOfFailedCases = 2L; final Map<String, String> filters = new HashMap<>(); filters.put(CaseItem.FILTER_CALLER, "any"); filters.put(CaseItem.ATTRIBUTE_PROCESS_ID, item.getId().toString()); filters.put(CaseItem.FILTER_STATE, ProcessInstanceState.ERROR.name()); doReturn(numberOfFailedCases).when(caseDatastore).count(null, null, filters); apiProcess.fillCounters(item, counters); verify(item).setAttribute(ProcessItem.COUNTER_FAILED_CASES, numberOfFailedCases); }
@Test public final void fillCounters_should_do_nothing_when_counter_of_failed_cases_is_not_active() { final ProcessItem item = mock(ProcessItem.class); final List<String> counters = new ArrayList<>(); apiProcess.fillCounters(item, counters); verify(item, never()).setAttribute(anyString(), anyLong()); }
@Test public final void fillCounters_should_fill_number_of_open_cases_when_counter_of_open_cases_is_active() { final APIID id = APIID.makeAPIID(78L); final ProcessItem item = mock(ProcessItem.class); doReturn(id).when(item).getId(); final List<String> counters = Arrays.asList(ProcessItem.COUNTER_OPEN_CASES); final Map<String, String> filters = new HashMap<>(); filters.put(CaseItem.FILTER_CALLER, "any"); filters.put(CaseItem.ATTRIBUTE_PROCESS_ID, id.toString()); final long numberOfOpenCases = 2L; doReturn(numberOfOpenCases).when(caseDatastore).count(null, null, filters); apiProcess.fillCounters(item, counters); verify(item).setAttribute(ProcessItem.COUNTER_OPEN_CASES, numberOfOpenCases); }
@Test public final void fillCounters_should_do_nothing_when_counter_of_open_cases_is_not_active() { final ProcessItem item = mock(ProcessItem.class); final List<String> counters = new ArrayList<>(); apiProcess.fillCounters(item, counters); verify(item, never()).setAttribute(anyString(), anyLong()); }
|
### Question:
ProcessContractResource extends CommonResource { @Get("json") public ContractDefinition getContract() throws ProcessDefinitionNotFoundException { ContractDefinition processContract = processAPI.getProcessContract(getProcessDefinitionIdParameter()); return typeConverterUtil.getAdaptedContractDefinition(processContract); } ProcessContractResource(final ProcessAPI processAPI); @Get("json") ContractDefinition getContract(); }### Answer:
@Test(expected = APIException.class) public void should_throw_exception_if_attribute_is_not_found() throws Exception { doReturn(null).when(processContractResource).getAttribute(anyString()); processContractResource.getContract(); }
|
### Question:
ProcessDefinitionDesignResource extends CommonResource { @Get("json") public String getDesign() throws ProcessDefinitionNotFoundException, IOException { final DesignProcessDefinition design = processAPI.getDesignProcessDefinition(getProcessDefinitionIdParameter()); final JacksonRepresentation<DesignProcessDefinition> jacksonRepresentation = new JacksonRepresentation<DesignProcessDefinition>(design); jacksonRepresentation.getObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); jacksonRepresentation.setCharacterSet(CharacterSet.UTF_8); return replaceLongIdToString(jacksonRepresentation.getText()); } ProcessDefinitionDesignResource(final ProcessAPI processAPI); @Get("json") String getDesign(); }### Answer:
@Test(expected = APIException.class) public void should_throw_exception_if_attribute_is_not_found() throws Exception { doReturn(null).when(processDefinitionDesignResource).getAttribute(anyString()); processDefinitionDesignResource.getDesign(); }
|
### Question:
ProcessDefinitionDesignResource extends CommonResource { protected String replaceLongIdToString(final String design) throws IOException { return design.replaceAll("([^\\\\]\"id\"\\s*:\\s*)(\\d+)", "$1\"$2\""); } ProcessDefinitionDesignResource(final ProcessAPI processAPI); @Get("json") String getDesign(); }### Answer:
@Test public void testReplaceLongIdToString() throws Exception { assertThat(processDefinitionDesignResource.replaceLongIdToString("{ \"id\": 123}")).isEqualToIgnoringCase("{ \"id\": \"123\"}"); assertThat(processDefinitionDesignResource.replaceLongIdToString("{ \"id\":123, \"test\": [ otherid: \"zerze\"]}")).isEqualToIgnoringCase( "{ \"id\":\"123\", \"test\": [ otherid: \"zerze\"]}"); assertThat(processDefinitionDesignResource.replaceLongIdToString("{ \"iaed\": 123}")).isEqualToIgnoringCase("{ \"iaed\": 123}"); assertThat(processDefinitionDesignResource.replaceLongIdToString("{ \"name\": \"\\\"id\\\": 123\"}")).isEqualToIgnoringCase( "{ \"name\": \"\\\"id\\\": 123\"}"); assertThat(processDefinitionDesignResource.replaceLongIdToString("{ \"name\": \"\\\"id\\\": 123\"}")).isEqualToIgnoringCase( "{ \"name\": \"\\\"id\\\": 123\"}"); }
|
### Question:
APIProcessConnectorDependency extends ConsoleAPI<ProcessConnectorDependencyItem> implements
APIHasSearch<ProcessConnectorDependencyItem> { protected void checkMandatoryAttributes(final Map<String, String> filters) { if (MapUtil.isBlank(filters, ATTRIBUTE_PROCESS_ID)) { throw new APIFilterMandatoryException(ATTRIBUTE_PROCESS_ID); } if (MapUtil.isBlank(filters, ATTRIBUTE_CONNECTOR_NAME)) { throw new APIFilterMandatoryException(ATTRIBUTE_CONNECTOR_NAME); } if (MapUtil.isBlank(filters, ATTRIBUTE_CONNECTOR_VERSION)) { throw new APIFilterMandatoryException(ATTRIBUTE_CONNECTOR_VERSION); } } @Override String defineDefaultSearchOrder(); @Override ItemSearchResult<ProcessConnectorDependencyItem> search(final int page, final int resultsByPage, final String search, final String orders,
final Map<String, String> filters); }### Answer:
@Test(expected = APIFilterMandatoryException.class) public void checkProcessIdIsMandatory() throws Exception { Map<String, String> filters = buildFilters(null, "aConnectorName", "aConnectorVersion"); apiProcessConnectorDependency.checkMandatoryAttributes(filters); }
@Test(expected = APIFilterMandatoryException.class) public void checkConnectorNameIsMandatory() throws Exception { Map<String, String> filters = buildFilters("1", "", "aConnectorVersion"); apiProcessConnectorDependency.checkMandatoryAttributes(filters); }
@Test(expected = APIFilterMandatoryException.class) public void checkConnectorVersionIsMandatory() throws Exception { Map<String, String> filters = buildFilters("1", "aConnectorName", ""); apiProcessConnectorDependency.checkMandatoryAttributes(filters); }
@Test public void checkMandatoryAttributesDontThrowExceptionIfAllAtributesAreSet() throws Exception { Map<String, String> filters = buildFilters("1", "aConnectorName", "aConnectorVersion"); apiProcessConnectorDependency.checkMandatoryAttributes(filters); assertTrue("no exception thrown", true); }
|
### Question:
APIProcessConnectorDependency extends ConsoleAPI<ProcessConnectorDependencyItem> implements
APIHasSearch<ProcessConnectorDependencyItem> { @Override public ItemSearchResult<ProcessConnectorDependencyItem> search(final int page, final int resultsByPage, final String search, final String orders, final Map<String, String> filters) { checkMandatoryAttributes(filters); return super.search(page, resultsByPage, search, orders, filters); } @Override String defineDefaultSearchOrder(); @Override ItemSearchResult<ProcessConnectorDependencyItem> search(final int page, final int resultsByPage, final String search, final String orders,
final Map<String, String> filters); }### Answer:
@Test(expected = APIFilterMandatoryException.class) public void searchCheckMandatoryAttributes() throws Exception { Map<String, String> filtersWithoutProcessId = buildFilters(null, "aConnectorName", "aConnectorVersion"); apiProcessConnectorDependency.search(0, 10, null, null, filtersWithoutProcessId); }
|
### Question:
TenantResourceItem implements Serializable { public String getLastUpdateDate() { return lastUpdateDate; } TenantResourceItem(final TenantResource tenantResource); String getId(); void setId(String id); String getName(); void setName(String name); TenantResourceType getType(); void setType(TenantResourceType type); TenantResourceState getState(); void setState(TenantResourceState state); String getLastUpdatedBy(); void setLastUpdatedBy(final String lastUpdatedBy); String getLastUpdateDate(); }### Answer:
@Test public void should_format_lastUpdateDate_as_ISO8601_string_when_tenantResourceItem_is_created(){ String dateAsString = "2018-01-05T09:04:19Z"; Instant instant = Instant.ofEpochSecond(1515143059); when(tenantResource.getLastUpdateDate()).thenReturn(OffsetDateTime.ofInstant(instant, ZoneOffset.UTC)); TenantResourceItem tenantResourceItem = new TenantResourceItem(tenantResource); assertThat(tenantResourceItem.getLastUpdateDate()).isEqualTo(dateAsString); }
|
### Question:
CustomUserInfoConverter extends ItemConverter<CustomUserInfoItem, CustomUserInfoValue> { public CustomUserInfoDefinitionItem convert(CustomUserInfoDefinition definition) { CustomUserInfoDefinitionItem item = new CustomUserInfoDefinitionItem(); item.setId(APIID.makeAPIID(definition.getId())); item.setName(definition.getName()); item.setDescription(definition.getDescription()); return item; } CustomUserInfoDefinitionItem convert(CustomUserInfoDefinition definition); CustomUserInfoItem convert(CustomUserInfo information); @Override CustomUserInfoItem convert(CustomUserInfoValue value); }### Answer:
@Test public void should_return_a_fully_configured_definition() throws Exception { CustomUserInfoDefinition dummy = new EngineCustomUserInfoDefinition(1L, "foo", "bar"); CustomUserInfoDefinitionItem definition = converter.convert(dummy); assertThat(definition.getAttributes()).containsOnly( entry("id", "1"), entry("name", "foo"), entry("description", "bar")); }
@Test public void should_return_a_fully_configured_custom_information() throws Exception { CustomUserInfoDefinition definition = new EngineCustomUserInfoDefinition(3L); CustomUserInfoValueImpl value = new CustomUserInfoValueImpl(); value.setValue("foo"); CustomUserInfoItem information = converter.convert(new CustomUserInfo(2L, definition, value)); assertThat(information.getAttributes()).containsOnly( entry("userId", "2"), entry("definitionId", "3"), entry("value", "foo")); assertThat(information.getDefinition().getId()).isEqualTo(APIID.makeAPIID(3L)); }
@Test public void should_return_a_fully_configured_custom_information_form_a_value() throws Exception { CustomUserInfoValueImpl value = new CustomUserInfoValueImpl(); value.setUserId(5); value.setDefinitionId(6); value.setValue("foo"); CustomUserInfoItem information = converter.convert(value); assertThat(information.getAttributes()).containsOnly( entry("userId", "5"), entry("definitionId", "6"), entry("value", "foo")); }
|
### Question:
APICustomUserInfoValue extends ConsoleAPI<CustomUserInfoItem> implements APIHasSearch<CustomUserInfoItem>, APIHasUpdate<CustomUserInfoItem> { @Override public ItemSearchResult<CustomUserInfoItem> search(int page, int resultsByPage, String search, String orders, Map<String, String> filters) { SearchResult<CustomUserInfoValue> result = getClient().searchCustomUserInfoValues(new SearchOptionsCreator( page, resultsByPage, search, new Sorts(orders), new Filters(filters, new GenericFilterCreator(new CustomUserInfoAttributeConverter()))).create()); return new ItemSearchResultConverter<CustomUserInfoItem, CustomUserInfoValue>( page, resultsByPage, result, new CustomUserInfoConverter()).toItemSearchResult(); } APICustomUserInfoValue(CustomUserInfoEngineClientCreator engineClientCreator); @Override ItemSearchResult<CustomUserInfoItem> search(int page, int resultsByPage, String search, String orders, Map<String, String> filters); @Override String defineDefaultSearchOrder(); @Override CustomUserInfoItem update(APIID id, Map<String, String> attributes); }### Answer:
@Test public void should_retrieve_custom_user_info() throws Exception { given(engine.searchCustomUserInfoValues(any(SearchOptions.class))).willReturn( new SearchResultImpl<CustomUserInfoValue>(3, Arrays.<CustomUserInfoValue> asList( createValue("foo"), createValue("bar")))); ItemSearchResult<CustomUserInfoItem> result = api.search(0, 2, null, null, Collections.<String, String>emptyMap()); assertThat(result.getPage()).isEqualTo(0); assertThat(result.getTotal()).isEqualTo(3); assertThat(result.getLength()).isEqualTo(2); assertThat(result.getResults().get(0).getValue()).isEqualTo("foo"); assertThat(result.getResults().get(1).getValue()).isEqualTo("bar"); }
@Test public void should_retrieve_custom_user_info_sorted() throws Exception { given(engine.searchCustomUserInfoValues(any(SearchOptions.class))).willReturn( new SearchResultImpl<CustomUserInfoValue>(0, Collections.<CustomUserInfoValue> emptyList())); ArgumentCaptor<SearchOptions> argument = ArgumentCaptor.forClass(SearchOptions.class); api.search(0, 2, null, "userId ASC", Collections.<String, String> emptyMap()); verify(engine).searchCustomUserInfoValues(argument.capture()); assertThat(argument.getValue().getSorts().get(0).getField()).isEqualTo("userId"); assertThat(argument.getValue().getSorts().get(0).getOrder()).isEqualTo(Order.ASC); }
@Test public void should_retrieve_custom_user_info_filtered() throws Exception { given(engine.searchCustomUserInfoValues(any(SearchOptions.class))).willReturn( new SearchResultImpl<CustomUserInfoValue>(0, Collections.<CustomUserInfoValue> emptyList())); ArgumentCaptor<SearchOptions> argument = ArgumentCaptor.forClass(SearchOptions.class); api.search(0, 2, null, null, Collections.singletonMap(CustomUserInfoItem.ATTRIBUTE_VALUE, "bar")); verify(engine).searchCustomUserInfoValues(argument.capture()); assertThat(argument.getValue().getFilters().get(0).getField()).isEqualTo(CustomUserInfoItem.ATTRIBUTE_VALUE); assertThat(argument.getValue().getFilters().get(0).getValue()).isEqualTo("bar"); }
@Test public void should_retrieve_custom_user_info_term_filtered() throws Exception { given(engine.searchCustomUserInfoValues(any(SearchOptions.class))).willReturn( new SearchResultImpl<CustomUserInfoValue>(0, Collections.<CustomUserInfoValue> emptyList())); ArgumentCaptor<SearchOptions> argument = ArgumentCaptor.forClass(SearchOptions.class); api.search(0, 2, "foo", null, Collections.<String, String>emptyMap()); verify(engine).searchCustomUserInfoValues(argument.capture()); assertThat(argument.getValue().getSearchTerm()).isEqualTo("foo"); }
|
### Question:
APICustomUserInfoValue extends ConsoleAPI<CustomUserInfoItem> implements APIHasSearch<CustomUserInfoItem>, APIHasUpdate<CustomUserInfoItem> { @Override public CustomUserInfoItem update(APIID id, Map<String, String> attributes) { check(containsOnly(ATTRIBUTE_VALUE, attributes), new _("Only the value attribute can be updated")); return converter.convert(getClient().setCustomUserInfoValue( id.getPartAsLong(1), id.getPartAsLong(0), attributes.get(ATTRIBUTE_VALUE))); } APICustomUserInfoValue(CustomUserInfoEngineClientCreator engineClientCreator); @Override ItemSearchResult<CustomUserInfoItem> search(int page, int resultsByPage, String search, String orders, Map<String, String> filters); @Override String defineDefaultSearchOrder(); @Override CustomUserInfoItem update(APIID id, Map<String, String> attributes); }### Answer:
@Test public void should_update_a_given_custom_item_value() throws Exception { CustomUserInfoValueImpl update = new CustomUserInfoValueImpl(); update.setValue("foo"); given(engine.setCustomUserInfoValue(1L, 2L, "foo")).willReturn(update); CustomUserInfoItem value = api.update(APIID.makeAPIID(2L, 1L), Collections.singletonMap("value", "foo")); assertThat(value.getValue()).isEqualTo("foo"); }
|
### Question:
APICustomUserInfoDefinition extends ConsoleAPI<CustomUserInfoDefinitionItem> implements
APIHasAdd<CustomUserInfoDefinitionItem>,
APIHasSearch<CustomUserInfoDefinitionItem>,
APIHasDelete { public CustomUserInfoDefinitionItem add(CustomUserInfoDefinitionItem definition) { return converter.convert(engineClientCreator.create(getEngineSession()) .createDefinition(new CustomUserInfoDefinitionCreator( definition.getName(), definition.getDescription()))); } APICustomUserInfoDefinition(CustomUserInfoEngineClientCreator engineClientCreator); CustomUserInfoDefinitionItem add(CustomUserInfoDefinitionItem definition); void delete(final List<APIID> ids); ItemSearchResult<CustomUserInfoDefinitionItem> search(
final int page,
final int resultsByPage,
final String search,
final String orders,
final Map<String, String> filters); String defineDefaultSearchOrder(); static final String FIX_ORDER; }### Answer:
@Test public void add_should_return_the_added_item() throws Exception { given(engine.createDefinition(any(CustomUserInfoDefinitionCreator.class))) .willReturn(new EngineCustomUserInfoDefinition(2L)); CustomUserInfoDefinitionItem added = api.add(new CustomUserInfoDefinitionItem()); assertThat(added.getId()).isEqualTo(APIID.makeAPIID(2L)); }
@Test public void add_should_create_an_item_based_on_item_passed_in_parameter() throws Exception { given(engine.createDefinition(any(CustomUserInfoDefinitionCreator.class))) .willReturn(new EngineCustomUserInfoDefinition(1L)); ArgumentCaptor<CustomUserInfoDefinitionCreator> argument = ArgumentCaptor.forClass(CustomUserInfoDefinitionCreator.class); CustomUserInfoDefinitionItem item = new CustomUserInfoDefinitionItem(); item.setName("foo"); item.setDescription("bar"); api.add(item); verify(engine).createDefinition(argument.capture()); assertThat(argument.getValue().getName()).isEqualTo("foo"); assertThat(argument.getValue().getDescription()).isEqualTo("bar"); }
|
### Question:
APICustomUserInfoDefinition extends ConsoleAPI<CustomUserInfoDefinitionItem> implements
APIHasAdd<CustomUserInfoDefinitionItem>,
APIHasSearch<CustomUserInfoDefinitionItem>,
APIHasDelete { public void delete(final List<APIID> ids) { for (APIID id : ids) { engineClientCreator.create(getEngineSession()).deleteDefinition(id.toLong()); } } APICustomUserInfoDefinition(CustomUserInfoEngineClientCreator engineClientCreator); CustomUserInfoDefinitionItem add(CustomUserInfoDefinitionItem definition); void delete(final List<APIID> ids); ItemSearchResult<CustomUserInfoDefinitionItem> search(
final int page,
final int resultsByPage,
final String search,
final String orders,
final Map<String, String> filters); String defineDefaultSearchOrder(); static final String FIX_ORDER; }### Answer:
@Test public void delete_should_delete_all_items_with_id_passed_through() throws Exception { ArgumentCaptor<Long> argument = ArgumentCaptor.forClass(Long.class); api.delete(Arrays.asList( APIID.makeAPIID(1L), APIID.makeAPIID(2L))); verify(engine, times(2)).deleteDefinition(argument.capture()); assertThat(argument.getAllValues()).containsOnly(1L, 2L); }
|
### Question:
APICustomUserInfoDefinition extends ConsoleAPI<CustomUserInfoDefinitionItem> implements
APIHasAdd<CustomUserInfoDefinitionItem>,
APIHasSearch<CustomUserInfoDefinitionItem>,
APIHasDelete { public ItemSearchResult<CustomUserInfoDefinitionItem> search( final int page, final int resultsByPage, final String search, final String orders, final Map<String, String> filters) { check(search == null, new _("Search terms are not supported by this API")); check(filters == null || filters.isEmpty(), new _("Filters are not supported by this API")); check(orders.equals(FIX_ORDER), new _("Sorting is not supported by this API")); CustomUserInfoEngineClient client = engineClientCreator.create(getEngineSession()); List<CustomUserInfoDefinitionItem> result = new ArrayList<CustomUserInfoDefinitionItem>(); for (CustomUserInfoDefinition definition : client.listDefinitions(page * resultsByPage, resultsByPage)) { result.add(converter.convert(definition)); } return new ItemSearchResult<CustomUserInfoDefinitionItem>(page, resultsByPage, client.countDefinitions(), result); } APICustomUserInfoDefinition(CustomUserInfoEngineClientCreator engineClientCreator); CustomUserInfoDefinitionItem add(CustomUserInfoDefinitionItem definition); void delete(final List<APIID> ids); ItemSearchResult<CustomUserInfoDefinitionItem> search(
final int page,
final int resultsByPage,
final String search,
final String orders,
final Map<String, String> filters); String defineDefaultSearchOrder(); static final String FIX_ORDER; }### Answer:
@Test public void search_should_retrieve_the_list_of_item_from_the_specified_range() throws Exception { given(engine.listDefinitions(4, 2)).willReturn(Arrays.<CustomUserInfoDefinition> asList( new EngineCustomUserInfoDefinition(3L), new EngineCustomUserInfoDefinition(4L))); given(engine.countDefinitions()).willReturn(6L); List<CustomUserInfoDefinitionItem> result = api.search(2, 2, null, APICustomUserInfoDefinition.FIX_ORDER, null).getResults(); assertThat(result.get(0).getId()).isEqualTo(APIID.makeAPIID(3L)); assertThat(result.get(1).getId()).isEqualTo(APIID.makeAPIID(4L)); }
@Test public void search_should_retrieve_the_total_number_of_definitions() throws Exception { given(engine.countDefinitions()).willReturn(42L); ItemSearchResult<CustomUserInfoDefinitionItem> result = api.search(0, 2, null, APICustomUserInfoDefinition.FIX_ORDER, null); assertThat(result.getTotal()).isEqualTo(42); }
@Test public void should_allow_an_empty_filter() throws Exception { given(engine.countDefinitions()).willReturn(42L); ItemSearchResult<CustomUserInfoDefinitionItem> result = api.search(0, 2, null, APICustomUserInfoDefinition.FIX_ORDER, Collections.<String, String> emptyMap()); assertThat(result.getTotal()).isEqualTo(42); }
@Test(expected = APIException.class) public void search_should_throw_an_exception_when_filters_are_passed_through() throws Exception { api.search(0, 1, null, APICustomUserInfoDefinition.FIX_ORDER, Collections.singletonMap("name", "foo")); }
@Test(expected = APIException.class) public void search_should_throw_an_exception_when_an_order_is_passed_through() throws Exception { api.search(0, 1, null, "NAME ASC", null); }
@Test(expected = APIException.class) public void search_should_throw_an_exception_when_a_search_is_passed_through() throws Exception { api.search(0, 1, "foo", APICustomUserInfoDefinition.FIX_ORDER, null); }
|
### Question:
APIUser extends ConsoleAPI<UserItem> implements APIHasAdd<UserItem>, APIHasDelete, APIHasUpdate<UserItem>,
APIHasGet<UserItem>, APIHasSearch<UserItem> { @Override public UserItem update(final APIID id, final Map<String, String> item) { MapUtil.removeIfBlank(item, UserItem.ATTRIBUTE_PASSWORD); if (item.get(UserItem.ATTRIBUTE_PASSWORD) != null) { checkPasswordRobustness(item.get(UserItem.ATTRIBUTE_PASSWORD)); } return getUserDatastore().update(id, item); } @Override String defineDefaultSearchOrder(); @Override UserItem add(final UserItem item); @Override UserItem update(final APIID id, final Map<String, String> item); @Override UserItem get(final APIID id); @Override ItemSearchResult<UserItem> search(final int page, final int resultsByPage, final String search, final String orders,
final Map<String, String> filters); @Override void delete(final List<APIID> ids); }### Answer:
@Test public void should_not_update_password_if_empty() throws Exception { apiUser.update(USER_ID, map(UserItem.ATTRIBUTE_PASSWORD, "")); verify(userDatastore).update(eq(USER_ID), eq(Collections.<String, String> emptyMap())); }
@Test public void should_check_password_robustness_on_update() throws Exception { expectedException.expect(ValidationException.class); expectedException.expectMessage("the validator TestValidator rejected this password"); apiUser.update(USER_ID, map(UserItem.ATTRIBUTE_PASSWORD, "this password is not accepted by the TestValidator validator")); }
@Test public void should_update_password_if_valid() throws Exception { apiUser.update(USER_ID, map(UserItem.ATTRIBUTE_PASSWORD, "accepted password")); verify(userDatastore).update(eq(USER_ID), eq(map(UserItem.ATTRIBUTE_PASSWORD, "accepted password"))); }
|
### Question:
APIUser extends ConsoleAPI<UserItem> implements APIHasAdd<UserItem>, APIHasDelete, APIHasUpdate<UserItem>,
APIHasGet<UserItem>, APIHasSearch<UserItem> { @Override public UserItem add(final UserItem item) { if (StringUtil.isBlank(item.getPassword())) { throw new ValidationException(Collections.singletonList(new ValidationError("Password", "%attribute% is mandatory"))); } checkPasswordRobustness(item.getPassword()); return getUserDatastore().add(item); } @Override String defineDefaultSearchOrder(); @Override UserItem add(final UserItem item); @Override UserItem update(final APIID id, final Map<String, String> item); @Override UserItem get(final APIID id); @Override ItemSearchResult<UserItem> search(final int page, final int resultsByPage, final String search, final String orders,
final Map<String, String> filters); @Override void delete(final List<APIID> ids); }### Answer:
@Test public void should_check_password_robustness_on_add() throws Exception { UserItem userItem = new UserItem(); userItem.setUserName("John"); userItem.setPassword("this password is not accepted by the TestValidator validator"); expectedException.expect(ValidationException.class); expectedException.expectMessage("the validator TestValidator rejected this password"); apiUser.add(userItem); }
@Test public void should_throw_exception_when_adding_a_user_with_no_password() throws Exception { UserItem userItem = new UserItem(); userItem.setUserName("John"); expectedException.expect(ValidationException.class); apiUser.add(userItem); }
@Test public void should_add_user_if_password_is_valid() throws Exception { UserItem userItem = new UserItem(); userItem.setUserName("John"); userItem.setPassword("accepted password"); apiUser.add(userItem); }
|
### Question:
ConfigurationFile { public Set<String> getPropertyAsSet(final String propertyName) { final String propertyAsString = getProperty(propertyName); return stringToSet(propertyAsString); } ConfigurationFile(final String propertiesFilename); ConfigurationFile(String propertiesFilename, long tenantId); String getProperty(final String propertyName); void removeProperty(final String propertyName); void setProperty(final String propertyName, final String propertyValue); Set<String> getPropertyAsSet(final String propertyName); void setPropertyAsSet(final String property, final Set<String> permissions); }### Answer:
@Test public void should_getProperty_return_the_right_permissions_list() throws Exception { final ConfigurationFile tenantProperties = new ConfigurationFile(COMPOUND_PERMISSIONS_MAPPING_FILE, TENANT_ID); final Set<String> compoundPermissionsList = tenantProperties.getPropertyAsSet("taskListingPage"); assertThat(compoundPermissionsList).containsOnly("TaskVisualization", "CaseVisualization"); }
@Test public void should_getProperty_return_the_right_permissions_list_with_single_value() throws Exception { final ConfigurationFile tenantProperties = new ConfigurationFile(COMPOUND_PERMISSIONS_MAPPING_FILE, TENANT_ID); final Set<String> compoundPermissionsList = tenantProperties.getPropertyAsSet("processListingPage"); assertThat(compoundPermissionsList).containsOnly("processVisualization"); }
|
### Question:
APICustomUserInfoUser extends ConsoleAPI<CustomUserInfoItem> implements APIHasSearch<CustomUserInfoItem> { @Override public ItemSearchResult<CustomUserInfoItem> search(int page, int resultsByPage, String search, String orders, Map<String, String> filters) { check(containsOnly(FILTER_USER_ID, filters), new _("The only mandatory filter is %name%", new Arg("name", FILTER_USER_ID))); check(orders.equals(FIX_ORDER), new _("Sorting is not supported by this API")); check(search == null, new _("Search terms are not supported by this API")); CustomUserInfoEngineClient client = engineClientCreator.create(getEngineSession()); List<CustomUserInfo> items = client.listCustomInformation( Long.parseLong(filters.get(FILTER_USER_ID)), page * resultsByPage, resultsByPage); List<CustomUserInfoItem> information = new ArrayList<CustomUserInfoItem>(); for (CustomUserInfo item : items) { information.add(converter.convert(item)); } return new ItemSearchResult<CustomUserInfoItem>(page, information.size(), client.countDefinitions(), information); } APICustomUserInfoUser(CustomUserInfoEngineClientCreator engineClientCreator); @Override ItemSearchResult<CustomUserInfoItem> search(int page, int resultsByPage, String search, String orders, Map<String, String> filters); @Override String defineDefaultSearchOrder(); static final String FIX_ORDER; }### Answer:
@Test public void should_retrieve_the_CustomUserInfo_for_a_given_user_id() throws Exception { given(engine.listCustomInformation(3L, 0, 2)).willReturn(Arrays.asList( new CustomUserInfo(3L, new EngineCustomUserInfoDefinition(5L), new CustomUserInfoValueImpl()), new CustomUserInfo(3L, new EngineCustomUserInfoDefinition(6L), new CustomUserInfoValueImpl()))); given(engine.countDefinitions()).willReturn(2L); List<CustomUserInfoItem> information = api.search(0, 2, null, "Fix order", Collections.singletonMap("userId", "3")).getResults(); assertThat(information.get(0).getDefinition().getId()).isEqualTo(APIID.makeAPIID(5L)); assertThat(information.get(1).getDefinition().getId()).isEqualTo(APIID.makeAPIID(6L)); }
@Test public void should_paginate_CustomUserInfo_search() throws Exception { given(engine.countDefinitions()).willReturn(2L); api.search(2, 2, null, "Fix order", Collections.singletonMap("userId", "3")).getResults(); verify(engine).listCustomInformation(3L, 4, 2); }
@Test(expected = APIException.class) public void should_fail_when_passing_an_order_to_the_search() { api.search(0, 2, null, "NAME ASC", Collections.singletonMap("userId", "3")).getResults(); }
@Test(expected = APIException.class) public void should_fail_when_passing_a_term_to_the_search() { api.search(0, 2, "foo", "Fix order", Collections.singletonMap("userId", "3")).getResults(); }
@Test(expected = APIException.class) public void should_fail_when_passing_a_no_filter_to_the_search() { api.search(0, 2, null, "Fix order", null).getResults(); }
@Test(expected = APIException.class) public void should_fail_when_passing_wrong_filter_to_the_search() { api.search(0, 2, null, "Fix order", Collections.singletonMap("foo", "bar")).getResults(); }
|
### Question:
JSonSimpleDeserializer implements JSonUnserializer { public static AbstractTreeNode<String> unserializeTree(final String json) { return getInstance()._unserializeTree(json); } static AbstractTreeNode<String> unserializeTree(final String json); @Override AbstractTreeNode<String> _unserializeTree(final String json); }### Answer:
@Test public void testMalformedJson() { try { JSonSimpleDeserializer.unserializeTree("[toto}"); } catch (final Exception e) { return; } fail("Malformed Json must throw an exception"); }
@Test public void testEmptyInput() { final AbstractTreeNode<String> tree = JSonSimpleDeserializer.unserializeTree(""); assertNull(tree); }
@Test public void testSimpleObject() { final AbstractTreeNode<String> tree = JSonSimpleDeserializer.unserializeTree("{\"name\":\"toto\",\"path\":\"titi\"}"); if (!(tree instanceof TreeIndexed<?>)) { fail("Fail to parse a simple object in JSON"); } final TreeIndexed<String> tree2 = (TreeIndexed<String>) tree; assertEquals(tree2.getValue("name"), "toto"); assertEquals(tree2.getValue("path"), "titi"); assertNull(tree2.getValue("unassigned")); }
@Test public void testEmptyObject() { final AbstractTreeNode<String> tree = JSonSimpleDeserializer.unserializeTree("{}"); if (!(tree instanceof TreeIndexed<?>)) { fail("Fail to parse a simple object in JSON"); } assertEquals("{}", tree.toJson()); }
@Test public void testSimpleArray() { final AbstractTreeNode<String> tree = JSonSimpleDeserializer.unserializeTree(" [\"name\",5,true]"); if (!(tree instanceof Tree<?>)) { fail("Fail to parse a simple array in JSON"); } final Tree<String> tree2 = (Tree<String>) tree; assertEquals("name", tree2.getValues().get(0)); assertEquals("5", tree2.getValues().get(1)); assertEquals("1", tree2.getValues().get(2)); assertEquals("name", ((TreeLeaf<String>) tree2.get(0)).getValue()); assertEquals("5", ((TreeLeaf<String>) tree2.get(1)).getValue()); assertEquals("1", ((TreeLeaf<String>) tree2.get(2)).getValue()); }
@Test public void testEmptyArray() { final AbstractTreeNode<String> tree = JSonSimpleDeserializer.unserializeTree("[]"); if (!(tree instanceof Tree<?>)) { fail("Fail to parse a simple array in JSON"); } assertEquals("[]", tree.toJson()); }
@Test public void testOneElementArray() { final AbstractTreeNode<String> tree = JSonSimpleDeserializer.unserializeTree("[101]"); if (!(tree instanceof Tree<?>)) { fail("Fail to parse a simple array in JSON"); } assertEquals("[\"101\"]", tree.toJson()); final Tree<String> tree2 = (Tree<String>) tree; assertEquals(tree2.getValues().get(0), "101"); }
@Test public void testObjectWithArray() { final AbstractTreeNode<String> tree = JSonSimpleDeserializer.unserializeTree("{\"name\":\"toto\",\"categories_id\":[1,2,5]}"); if (!(tree instanceof TreeIndexed<?>)) { fail("Fail to parse a compound object in JSON"); } final AbstractTreeNode<String> treeCat = ((TreeIndexed<String>) tree).get("categories_id"); if (!(treeCat instanceof Tree<?>)) { fail("Fail to parse an array in an object in JSON"); } final Tree<String> tree2 = (Tree<String>) treeCat; assertEquals(tree2.getValues().get(0), "1"); assertEquals(tree2.getValues().get(1), "2"); assertEquals(tree2.getValues().get(2), "5"); }
|
### Question:
JacksonDeserializer { public <T> T deserialize(String json, Class<T> clazz) { return deserialize(json, mapper.getTypeFactory().constructType(clazz)); } T deserialize(String json, Class<T> clazz); List<T> deserializeList(String json, Class<T> clazz); @SuppressWarnings("unchecked") T convertValue(Object fromValue, Class<?> toValue); }### Answer:
@Test(expected = APIException.class) public void deserialize_throw_exception_if_json_is_non_well_formed() throws Exception { String nonWellFormedJson = "someJsonNonWellFormedJson"; jacksonDeserializer.deserialize(nonWellFormedJson, String.class); }
@Test(expected = APIException.class) public void deserialize_throw_exception_if_mapping_bettween_class_and_json_is_incorrect() throws Exception { String notUserJson = "{\"unknownUserAttribute\": \"unknownAttributeValue\"}"; jacksonDeserializer.deserialize(notUserJson, User.class); }
@Test public void deserialize_can_deserialize_primitives_types() throws Exception { Long deserializedLong = jacksonDeserializer.deserialize("1", Long.class); assertThat(deserializedLong, is(1L)); }
@Test public void deserialize_can_deserialize_complex_types() throws Exception { User expectedUser = new User(1, "Colin", "Puy", new Date(428558400000L), new Address("310 La Gouterie", "Charnecles")); String json = "{\"address\":{\"street\":\"310 La Gouterie\",\"city\":\"Charnecles\"},\"id\":1,\"firstName\":\"Colin\",\"lastName\":\"Puy\",\"birthday\":428558400000}"; User deserializedUser = jacksonDeserializer.deserialize(json, User.class); assertThat(deserializedUser, equalTo(expectedUser)); }
|
### Question:
JacksonDeserializer { public <T> List<T> deserializeList(String json, Class<T> clazz) { return deserialize(json , mapper.getTypeFactory().constructCollectionType(List.class, clazz)); } T deserialize(String json, Class<T> clazz); List<T> deserializeList(String json, Class<T> clazz); @SuppressWarnings("unchecked") T convertValue(Object fromValue, Class<?> toValue); }### Answer:
@Test(expected = APIException.class) public void deserializeList_throw_exception_if_json_is_not_a_list() throws Exception { String json = "{\"address\":{\"street\":\"310 La Gouterie\",\"city\":\"Charnecles\"},\"id\":1,\"firstName\":\"Colin\",\"lastName\":\"Puy\",\"birthday\":428558400000}"; jacksonDeserializer.deserializeList(json, User.class); }
@Test public void deserializeList_can_deserialize_primitives_types() throws Exception { List<Long> longs = jacksonDeserializer.deserializeList("[1, 2, 3]", Long.class); assertThat(longs, hasItems(1L, 2L, 3L)); }
@Test public void deserializeList_can_deserialize_list_of_complex_type() throws Exception { User expectedUser1 = new User(1, "Colin", "Puy", new Date(428558400000L), new Address("310 La Gouterie", "Charnecles")); User expectedUser2 = new User(2, "Clara", "Morgan", new Date(349246800000L), new Address("somewhere i don't know", "Paris")); String json = "[" + "{\"address\":{\"city\":\"Charnecles\",\"street\":\"310 La Gouterie\"},\"id\":1,\"firstName\":\"Colin\",\"lastName\":\"Puy\",\"birthday\":428558400000}," + "{\"address\":{\"city\":\"Paris\",\"street\":\"somewhere i don't know\"},\"id\":2,\"firstName\":\"Clara\",\"lastName\":\"Morgan\",\"birthday\":349246800000}" + "]"; List<User> users = jacksonDeserializer.deserializeList(json, User.class); assertThat(users, hasItem(expectedUser1)); assertThat(users, hasItem(expectedUser2)); }
|
### Question:
ServerProperties { public String getValue(final String propertyName) { return serverProperties.getProperty(propertyName); } private ServerProperties(); static synchronized ServerProperties getInstance(); String getValue(final String propertyName); }### Answer:
@Test public void should_return_property_value() { assertThat(serverProperties.getValue("auth.UserLogger")).isEqualTo("org.bonitasoft.console.common.server.login.credentials.UserLogger"); }
|
### Question:
JacksonSerializer { public String serialize(Object obj) throws JsonGenerationException, JsonMappingException, IOException { try{ return mapper.writeValueAsString(obj); }catch(Throwable e){ e.printStackTrace(); throw new RuntimeException(e); } } String serialize(Object obj); }### Answer:
@Test public void testSerialize() throws Exception { JacksonSerializer serializer = new JacksonSerializer(); ProfileImportStatusMessageFake message = new ProfileImportStatusMessageFake("profile1", "repalce"); message.addError("Organization: skks"); message.addError("Page: page1"); String serialize = serializer.serialize(message); assertThat(serialize).isEqualTo("{\"errors\":[\"Organization: skks\",\"Page: page1\"],\"profielName\":\"profile1\"}"); }
|
### Question:
RestRequestParser { public RestRequestParser invoke() { String pathInfo = request.getPathInfo(); if (pathInfo == null || pathInfo.split("/").length < 3) { pathInfo = request.getServletPath(); } final String[] path = pathInfo.split("/"); if (path.length < 3) { throw new APIMalformedUrlException("Missing API or resource name [" + request.getRequestURL() + "]"); } apiName = path[1]; resourceName = path[2]; if (path.length > 3) { final List<String> pathList = Arrays.asList(path); resourceQualifiers = APIID.makeAPIID(pathList.subList(3, pathList.size())); } else { resourceQualifiers = null; } return this; } RestRequestParser(final HttpServletRequest request); String getApiName(); String getResourceName(); APIID getResourceQualifiers(); RestRequestParser invoke(); }### Answer:
@Test(expected = APIMalformedUrlException.class) public void should_parsePath_with_bad_request() { doReturn("API/bpm").when(httpServletRequest).getPathInfo(); doReturn("/API").when(httpServletRequest).getServletPath(); restRequestParser.invoke(); }
|
### Question:
DateConverter implements Converter<Date> { @Override public Date convert(String toBeConverted) throws ConversionException { if (toBeConverted == null || toBeConverted.isEmpty()) { return null; } try { SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", DateFormatSymbols.getInstance(Locale.ENGLISH)); return formatter.parse(toBeConverted); } catch (ParseException e) { throw new ConversionException(toBeConverted + " cannot be converted to Date", e); } } @Override Date convert(String toBeConverted); }### Answer:
@Test public void nullIsConvertedToNull() throws Exception { Date converted = converter.convert(null); assertNull(converted); }
@Test public void emptyIsConvertedToNull() throws Exception { Date converted = converter.convert(""); assertNull(converted); }
@Test public void shouldConvertDateStringIntoDate() throws Exception { Calendar c = Calendar.getInstance(); int hourOfDay = 11; int minute = 43; int second = 30; int dayOfDateate = 18; int year = 2014; c.set(year, Calendar.AUGUST, dayOfDateate, hourOfDay, minute, second); String timeZone = "GMT"; c.setTimeZone(TimeZone.getTimeZone(timeZone)); c.set(Calendar.MILLISECOND, 0); Date date = c.getTime(); Date converted = converter.convert("Mon Aug " + dayOfDateate + " " + hourOfDay + ":" + minute + ":" + second + " " + timeZone + " " + year); assertEquals(date.toString() + " is not well converted", date, converted); }
@Test(expected = ConversionException.class) public void nonParsableStringThrowAConversionException() throws Exception { converter.convert("nonParsable"); }
|
### Question:
LongConverter implements Converter<Long> { @Override public Long convert(String toBeConverted) throws ConversionException { if (toBeConverted == null || toBeConverted.isEmpty()) { return null; } try { return Long.parseLong(toBeConverted); } catch (NumberFormatException e) { throw new ConversionException(toBeConverted + " cannot be converted to Long", e); } } @Override Long convert(String toBeConverted); }### Answer:
@Test public void nullIsConvertedToNull() throws Exception { Long converted = converter.convert(null); assertNull(converted); }
@Test public void emptyIsConvertedToNull() throws Exception { Long converted = converter.convert(""); assertNull(converted); }
@Test public void longNumberIsParsedToLong() throws Exception { long converted = converter.convert("456789"); assertEquals(456789L, converted); }
@Test(expected = ConversionException.class) public void nonParsableStringThrowAConversionException() throws Exception { converter.convert("nonParsable"); }
|
### Question:
ConfigurationFilesManager { Properties getAlsoCustomAndInternalPropertiesFromFilename(Map<String, Properties> propertiesByFilename, String propertiesFileName) { Properties properties = new Properties(); if (propertiesByFilename != null) { if (propertiesByFilename.containsKey(propertiesFileName)) { properties.putAll(propertiesByFilename.get(propertiesFileName)); } final String internalFilename = getSuffixedPropertyFilename(propertiesFileName, "-internal"); if (propertiesByFilename.containsKey(internalFilename)) { properties.putAll(propertiesByFilename.get(internalFilename)); } final String customFilename = getSuffixedPropertyFilename(propertiesFileName, "-custom"); if (propertiesByFilename.containsKey(customFilename)) { properties.putAll(propertiesByFilename.get(customFilename)); } } return properties; } static ConfigurationFilesManager getInstance(); Properties getPlatformProperties(String propertiesFile); Properties getTenantProperties(String propertiesFileName, long tenantId); void setPlatformConfigurations(Map<String, byte[]> configurationFiles); void setTenantConfigurations(Map<String, byte[]> configurationFiles, long tenantId); void setTenantConfiguration(String fileName, byte[] content, long tenantId); void removeProperty(String propertiesFilename, long tenantId, String propertyName); void setProperty(String propertiesFilename, long tenantId, String propertyName, String propertyValue); void updateAggregatedProperties(String propertiesFilename, long tenantId, String propertyName, String propertyValue,
Map<String, Properties> resources); File getPlatformConfigurationFile(String fileName); File getTenantConfigurationFile(String fileName, long tenantId); File getTenantAutoLoginConfiguration(long tenantId); }### Answer:
@Test public void getAlsoCustomAndInternalPropertiesFromFilename_should_merge_custom_properties_if_exist() throws Exception { Map<String, Properties> propertiesMap = new HashMap<>(2); final Properties defaultProps = new Properties(); defaultProps.put("defaultKey", "defaultValue"); propertiesMap.put("toto.properties", defaultProps); final Properties customProps = new Properties(); customProps.put("customKey", "customValue"); propertiesMap.put("toto-custom.properties", customProps); final Properties properties = configurationFilesManager.getAlsoCustomAndInternalPropertiesFromFilename(propertiesMap, "toto.properties"); assertThat(properties).containsEntry("defaultKey", "defaultValue").containsEntry("customKey", "customValue"); }
@Test public void getAlsoCustomAndInternalPropertiesFromFilename_should_merge_internal_properties_if_exist() throws Exception { Map<String, Properties> propertiesMap = new HashMap<>(2); final Properties defaultProps = new Properties(); defaultProps.put("defaultKey", "defaultValue"); propertiesMap.put("toto.properties", defaultProps); final Properties internalProps = new Properties(); internalProps.put("internalKey", "internalValue"); propertiesMap.put("toto-internal.properties", internalProps); final Properties properties = configurationFilesManager.getAlsoCustomAndInternalPropertiesFromFilename(propertiesMap, "toto.properties"); assertThat(properties).containsEntry("defaultKey", "defaultValue").containsEntry("internalKey", "internalValue"); }
@Test public void custom_properties_should_overwrite_internal_properties() throws Exception { final Properties defaultProps = new Properties(); defaultProps.put("defaultKey", "defaultValue"); final Properties internalProps = new Properties(); internalProps.put("otherKey", "someInternallyManagedValue"); final Properties customProps = new Properties(); final String expectedOverwrittenValue = "custom_changed_value"; customProps.put("otherKey", expectedOverwrittenValue); Map<String, Properties> propertiesMap = new HashMap<>(3); propertiesMap.put("overwrite.properties", defaultProps); propertiesMap.put("overwrite-internal.properties", internalProps); propertiesMap.put("overwrite-custom.properties", customProps); final Properties properties = configurationFilesManager.getAlsoCustomAndInternalPropertiesFromFilename(propertiesMap, "overwrite.properties"); assertThat(properties).containsEntry("defaultKey", "defaultValue").containsEntry("otherKey", expectedOverwrittenValue); }
|
### Question:
IntegerConverter implements Converter<Integer> { @Override public Integer convert(String toBeConverted) throws ConversionException { if (toBeConverted == null || toBeConverted.isEmpty()) { return null; } try { return Integer.parseInt(toBeConverted); } catch (NumberFormatException e) { throw new ConversionException(toBeConverted + " cannot be converted to Integer", e); } } @Override Integer convert(String toBeConverted); }### Answer:
@Test public void nullIsConvertedToNull() throws Exception { Integer converted = converter.convert(null); assertNull(converted); }
@Test public void emptyIsConvertedToNull() throws Exception { Integer converted = converter.convert(""); assertNull(converted); }
@Test public void intNumberIsParsedToInteger() throws Exception { int converted = converter.convert("456789"); assertEquals(456789, converted); }
@Test(expected = ConversionException.class) public void nonParsableStringThrowAConversionException() throws Exception { converter.convert("nonParsable"); }
|
### Question:
DoubleConverter implements Converter<Double> { @Override public Double convert(String toBeConverted) throws ConversionException { if (toBeConverted == null || toBeConverted.isEmpty()) { return null; } try { return Double.parseDouble(toBeConverted); } catch (NumberFormatException e) { throw new ConversionException(toBeConverted + " cannot be converted to Double", e); } } @Override Double convert(String toBeConverted); }### Answer:
@Test public void nullIsConvertedToNull() throws Exception { Double converted = converter.convert(null); assertNull(converted); }
@Test public void emptyIsConvertedToNull() throws Exception { Double converted = converter.convert(""); assertNull(converted); }
@Test public void doubleNumberIsParsedToDouble() throws Exception { double converted = converter.convert("1.23"); assertEquals(1.23d, converted, 0d); }
@Test(expected = ConversionException.class) public void nonParsableStringThrowAConversionException() throws Exception { converter.convert("nonParsable"); }
|
### Question:
BooleanConverter implements Converter<Boolean> { @Override public Boolean convert(String toBeConverted) { if (toBeConverted == null || toBeConverted.isEmpty()) { return null; } return Boolean.valueOf(toBeConverted); } @Override Boolean convert(String toBeConverted); }### Answer:
@Test public void trueIsConvertedToTrue() throws Exception { Boolean converted = converter.convert("true"); assertTrue(converted); }
@Test public void falseIsConvertedToFalse() throws Exception { Boolean converted = converter.convert("false"); assertFalse(converted); }
@Test public void nullIsConvertedToNull() throws Exception { Boolean converted = converter.convert(null); assertNull(converted); }
@Test public void emptyIsConvertedToNull() throws Exception { Boolean converted = converter.convert(""); assertNull(converted); }
@Test public void anythingElseIsConvertedToFalse() throws Exception { Boolean converted = converter.convert("something"); assertFalse(converted); }
|
### Question:
StringConverter implements Converter<String> { @Override public String convert(String convert) { return convert; } @Override String convert(String convert); }### Answer:
@Test public void stringConverterIsDummy() throws Exception { String converted = new StringConverter().convert("any string"); assertEquals("any string", converted); }
|
### Question:
ConverterFactory { public Converter<?> createConverter(String className) { if (isClass(String.class, className)) { return new StringConverter(); } else if (isClass(Date.class, className)) { return new DateConverter(); } else if (isClass(Double.class, className)) { return new DoubleConverter(); } else if (isClass(Long.class, className)) { return new LongConverter(); } else if (isClass(Boolean.class, className)) { return new BooleanConverter(); } else if (isClass(Integer.class, className)) { return new IntegerConverter(); } throw new UnsupportedOperationException("Canno't create converter for class name : " + className); } Converter<?> createConverter(String className); }### Answer:
@Test public void factoryCreateABooleanConverterForBooleanClassName() throws Exception { Converter<?> createConverter = factory.createConverter(Boolean.class.getName()); assertTrue(createConverter instanceof BooleanConverter); }
@Test @Ignore("until ENGINE-1099 is resolved") public void factoryCreateADateConverterForDateClassName() throws Exception { Converter<?> createConverter = factory.createConverter(Date.class.getName()); assertTrue(createConverter instanceof DateConverter); }
@Test public void factoryCreateADoubleConverterForDoubleClassName() throws Exception { Converter<?> createConverter = factory.createConverter(Double.class.getName()); assertTrue(createConverter instanceof DoubleConverter); }
@Test public void factoryCreateALongConverterForLongClassName() throws Exception { Converter<?> createConverter = factory.createConverter(Long.class.getName()); assertTrue(createConverter instanceof LongConverter); }
@Test public void factoryCreateAStringConverterForStringClassName() throws Exception { Converter<?> createConverter = factory.createConverter(String.class.getName()); assertTrue(createConverter instanceof StringConverter); }
@Test public void factoryCreateAnIntegerConverterForIntegerClassName() throws Exception { Converter<?> createConverter = factory.createConverter(Integer.class.getName()); assertTrue(createConverter instanceof IntegerConverter); }
@Test(expected = UnsupportedOperationException.class) public void factoryThrowExceptionForUnsuportedConverter() throws Exception { factory.createConverter(Servlet.class.getName()); }
|
### Question:
FormServiceProviderImpl implements FormServiceProvider { protected String extractProcessDefinitionUUID(final String formId) { final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("\\"); stringBuilder.append(FormServiceProviderUtil.FORM_ID_SEPARATOR); final String processDefinitionUUID; final String formUUID = formId.split(stringBuilder.toString())[0]; final String[] splitedFormUUID = formUUID.split(FormWorkflowAPIImpl.UUID_SEPARATOR); final StringBuilder stringBuilder2 = new StringBuilder(); stringBuilder2.append(splitedFormUUID[0]); stringBuilder2.append(FormWorkflowAPIImpl.UUID_SEPARATOR); stringBuilder2.append(splitedFormUUID[1]); processDefinitionUUID = stringBuilder2.toString(); return processDefinitionUUID; } FormServiceProviderImpl(); @Override Document getFormDefinitionDocument(final Map<String, Object> context); @Override boolean isAllowed(final String formId, final String permissions, final String productVersion, final String migrationProductVersion,
final Map<String, Object> context, final boolean isFormPermissions); @Override @SuppressWarnings("unchecked") Serializable resolveExpression(final Expression expression, final Map<String, Object> context); @Override @SuppressWarnings("unchecked") Map<String, Serializable> resolveExpressions(final List<Expression> expressions, final Map<String, Object> context); @Override @SuppressWarnings("unchecked") Map<String, Object> executeActions(final List<FormAction> actions, final Map<String, Object> context); @Override FormURLComponents getNextFormURLParameters(final String formId, final Map<String, Object> context); @Override Map<String, String> getAttributesToInsert(final Map<String, Object> context); @Override @SuppressWarnings("unchecked") List<FormValidator> validateField(final List<FormValidator> validators, final String fieldId, final FormFieldValue fieldValue,
final String submitButtonId, final Map<String, Object> context); @Override @SuppressWarnings("unchecked") List<FormValidator> validatePage(final List<FormValidator> validators, final Map<String, FormFieldValue> fields, final String submitButtonId,
final Map<String, Object> context); @Override Date getDeployementDate(final Map<String, Object> context); @Override IApplicationConfigDefAccessor getApplicationConfigDefinition(final Document formDefinitionDocument, final Map<String, Object> context); @Override IApplicationFormDefAccessor getApplicationFormDefinition(final String formId, final Document formDefinitionDocument,
final Map<String, Object> context); @Override File getApplicationResourceDir(final Date applicationDeploymentDate, final Map<String, Object> context); @Override FormFieldValue getAttachmentFormFieldValue(final Object value, final Map<String, Object> context); @Override boolean isEditMode(final String formID, final Map<String, Object> context); @Override boolean isCurrentValue(final Map<String, Object> context); @Override Map<String, Object> skipForm(final String formID, final Map<String, Object> context); @Override FormURLComponents getAnyTodoListForm(final Map<String, Object> context); @Override void assignForm(final String formID, final Map<String, Object> context); @Override ClassLoader getClassloader(final Map<String, Object> context); @Override void storeFormTransientDataContext(final HttpSession session, final String storageKey, final Map<String, Serializable> transientDataContext,
final Map<String, Object> context); @Override Map<String, Serializable> retrieveFormTransientDataContext(final HttpSession session, final String storageKey, final Map<String, Object> context); @Override void removeFormTransientDataContext(final HttpSession session, final String storageKey, final Map<String, Object> context); static final String EXECUTE_ACTIONS_PARAM; }### Answer:
@Test public void testextractProcessDefinitionUUID() throws Exception { final String formId = "processName--1.0$entry"; final String extractProcessDefinitionUUID = formServiceProviderImpl.extractProcessDefinitionUUID(formId); assertThat(extractProcessDefinitionUUID).isEqualTo("processName--1.0"); }
@Test public void testextractProcessDefinitionUUID_with_step_name() throws Exception { final String formId = "processName--1.0--Step1$entry"; final String extractProcessDefinitionUUID = formServiceProviderImpl.extractProcessDefinitionUUID(formId); assertThat(extractProcessDefinitionUUID).isEqualTo("processName--1.0"); }
|
### Question:
TypeConverter { public Serializable convert(String className, String convert) throws ConversionException { return factory.createConverter(className).convert(convert); } TypeConverter(); TypeConverter(ConverterFactory factory); Serializable convert(String className, String convert); }### Answer:
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void convertCreateAFactoryAndConvertStringValueToSerializableObject() throws Exception { Converter typedConverter = mock(Converter.class); when(factory.createConverter(anyString())).thenReturn(typedConverter); converter.convert("aClassName", "somethingToconvert"); verify(typedConverter).convert("somethingToconvert"); }
|
### Question:
FilePathBuilder { public FilePathBuilder append(final String path) { if (path == null || path.isEmpty()) { return this; } this.path.append(File.separator); insert(path); return this; } FilePathBuilder(final String path); FilePathBuilder append(final String path); @Override String toString(); }### Answer:
@Test public void testAppend() throws Exception { String path1 = "org", path2 = "bonita", path3 = "web/service"; FilePathBuilder path = new FilePathBuilder(path1).append(path2).append(path3); assertEquals(buildExpectedPath(path1, path2, path3), path.toString()); }
|
### Question:
ToolkitHttpServlet extends HttpServlet { protected final void outputException(final Throwable e, final HttpServletRequest req, final HttpServletResponse resp, final int httpStatusCode) { if (httpStatusCode >= 0) { resp.setStatus(httpStatusCode); } resp.setContentType("application/json;charset=UTF-8"); try { final PrintWriter output = resp.getWriter(); if(e instanceof APIException) { setLocalization((APIException) e, LocaleUtils.getUserLocaleAsString(req)); } output.print(e == null ? "" : JSonSerializer.serialize(e)); output.flush(); } catch (final Exception e2) { throw new APIException(e2); } } ToolkitHttpServlet(); @Override final void service(final ServletRequest req, final ServletResponse res); }### Answer:
@Test public void testOutputExceptionPrintProperJson() throws Exception { APIException exception = new APIException("message"); doReturn(writer).when(resp).getWriter(); toolkitHttpServlet.outputException(exception, req, resp, 500); verify(writer).print(exception.toJson()); }
@Test public void testLocaleIsPassedFromRequestToException() throws Exception { APIException exception = mock(APIException.class, withSettings().defaultAnswer(RETURNS_MOCKS)); doReturn(writer).when(resp).getWriter(); doReturn(new Cookie[] { new Cookie(LocaleUtils.LOCALE_COOKIE_NAME, "fr_FR") }).when(req).getCookies(); toolkitHttpServlet.outputException(exception, req, resp, 500); verify(exception).setLocale(LOCALE.fr); }
@Test public void testIfLocaleIsNotInACookieThatBrowserLocaleIsPassedThrough() throws Exception { APIException exception = mock(APIException.class, withSettings().defaultAnswer(RETURNS_MOCKS)); doReturn(writer).when(resp).getWriter(); doReturn(new Cookie[0]).when(req).getCookies(); doReturn(Locale.CANADA_FRENCH).when(req).getLocale(); toolkitHttpServlet.outputException(exception, req, resp, 500); verify(exception).setLocale(LOCALE.fr); }
@Test public void testIfLocaleIsNotInACookieNorBrowserThatDefaultLocaleIsPassedThrough() throws Exception { APIException exception = mock(APIException.class, withSettings().defaultAnswer(RETURNS_MOCKS)); doReturn(writer).when(resp).getWriter(); doReturn(new Cookie[0]).when(req).getCookies(); doReturn(null).when(req).getLocale(); toolkitHttpServlet.outputException(exception, req, resp, 500); verify(exception).setLocale(LOCALE.en); }
|
### Question:
WebBonitaConstantsUtils { public File getFormsWorkFolder() { return getFolder(webBonitaConstants.getFormsTempFolderPath()); } protected WebBonitaConstantsUtils(final long tenantId); protected WebBonitaConstantsUtils(); synchronized static WebBonitaConstantsUtils getInstance(final long tenantId); synchronized static WebBonitaConstantsUtils getInstance(); File getTempFolder(); File getConfFolder(); File getPortalThemeFolder(); File getConsoleDefaultIconsFolder(); File getReportFolder(); File getPagesFolder(); File getFormsWorkFolder(); File geBDMWorkFolder(); File getTenantsFolder(); }### Answer:
@Test public void testWeCanGetFormsWorkFolder() throws Exception { WebBonitaConstantsTenancyImpl constantsTenants = new WebBonitaConstantsTenancyImpl(1L); final File expected = new File(constantsTenants.getFormsTempFolderPath()); final File folder = webBonitaConstantsUtilsWithTenantId.getFormsWorkFolder(); assertThat(folder.getPath()).isEqualTo(expected.getPath()); assertThat(folder).exists(); }
|
### Question:
JsonExceptionSerializer { public String end() { return json.append("}").toString(); } JsonExceptionSerializer(Throwable exception); String end(); JsonExceptionSerializer appendAttribute(final String name, final Object value); }### Answer:
@Test public void testWeCanConvertExceptionWithoutMessage() throws Exception { HttpException exception = new HttpException(); JsonExceptionSerializer serializer = new JsonExceptionSerializer(exception); String json = serializer.end(); assertEquals(exception, json); }
@Test public void testWeCanConvertExceptionWithMessageToJson() throws Exception { HttpException exception = new HttpException("message"); JsonExceptionSerializer serializer = new JsonExceptionSerializer(exception); String json = serializer.end(); assertEquals(exception, json); }
@Test public void testJsonContainsInternationalizedMessageWhenLocalIsSet() throws Exception { APIException exception = new APIException(new _("message")); fakeI18n.setL10n("localization"); exception.setLocale(LOCALE.en); JsonExceptionSerializer serializer = new JsonExceptionSerializer(exception); String json = serializer.end(); assertThat(json, equalTo( "{\"exception\":\"" + exception.getClass().toString() + "\"," + "\"message\":\"localization\"" + "}")); }
|
### Question:
JSonSerializer extends JSonUtil { public static String serialize(final JsonSerializable object) { return serializeInternal(object).toString(); } static String serialize(final JsonSerializable object); static String serialize(final Object object); static String serialize(final Object key, final Object value); static String serializeCollection(final Collection<? extends Object> list); static String serializeMap(final Map<? extends Object, ? extends Object> map); static String serializeException(final Throwable e); static String serializeStringMap(final Map<? extends Object, String> map); }### Answer:
@Test public void should_serialize_an_exception() throws Exception { Exception exception = new Exception("an exception"); String serialize = JSonSerializer.serialize(exception); assertThat(serialize).isEqualTo("{\"exception\":\"class java.lang.Exception\",\"message\":\"an exception\"}"); }
@Test public void should_serialize_only_first_cause_of_an_exception() throws Exception { Exception exception = new Exception("first one", new Exception("second one", new Exception("third one"))); String serialize = JSonSerializer.serialize(exception); assertThat(serialize).isEqualTo( "{\"exception\":\"class java.lang.Exception\"," + "\"message\":\"first one\"," + "\"cause\":{" + "\"exception\":\"class java.lang.Exception\"," + "\"message\":\"second one\"" + "}" + "}"); }
|
### Question:
JSonUtil { public static String escape(final String string) { return escapeInternal(string).toString(); } static String quote(final String value); static StringBuilder quoteInternal(final String value); static String escape(final String string); static String unquote(final String string); static String unescape(final String string); static HashMap<String, String> unescape(final HashMap<String, String> values); }### Answer:
@Test public void should_escape_unsafe_html_characters() { assertThat(escape("<script>alert('bad')</script>")) .isEqualTo("\\u003cscript\\u003ealert(\\u0027bad\\u0027)\\u003c\\/script\\u003e"); }
|
### Question:
AngularParameterCleaner { public String getHashWithoutAngularParameters() { return hash .replaceAll("&?" + token + "_id=[^&\\?#]*", "") .replaceAll("&?" + token + "_tab=[^&\\?#]*", ""); } AngularParameterCleaner(final String token, final String hash); String getHashWithoutAngularParameters(); }### Answer:
@Test public void appendTabFromTokensToUrlWithArchivedTabTokenShouldBeAppendToUrl() throws Exception { assertEquals("", new AngularParameterCleaner("cases", "cases_tab=archived").getHashWithoutAngularParameters()); assertEquals("", new AngularParameterCleaner("cases", "&cases_tab=archived").getHashWithoutAngularParameters()); assertEquals("&", new AngularParameterCleaner("cases", "cases_tab=archived&").getHashWithoutAngularParameters()); assertEquals("&test=faux", new AngularParameterCleaner("cases", "cases_tab=archived&test=faux").getHashWithoutAngularParameters()); assertEquals("test=faux", new AngularParameterCleaner("cases", "test=faux&cases_tab=archived").getHashWithoutAngularParameters()); assertEquals("test=vrai&test=faux", new AngularParameterCleaner("cases", "test=vrai&cases_tab=archived&test=faux").getHashWithoutAngularParameters()); assertEquals("&", new AngularParameterCleaner("cases", "&cases_tab=archived&cases_tab=archived&cases_tab=archived&").getHashWithoutAngularParameters()); assertEquals("?", new AngularParameterCleaner("cases", "?cases_tab=archived").getHashWithoutAngularParameters()); assertEquals("?test#", new AngularParameterCleaner("cases", "?test&cases_tab=archived#").getHashWithoutAngularParameters()); assertEquals("#?test", new AngularParameterCleaner("cases", "#?test&cases_tab=archived").getHashWithoutAngularParameters()); assertEquals("test=vrai }
|
### Question:
Plugin extends PluginAdapter { @Override public void initialize(PluginLoaderData plugindata, Toolbox toolbox) { } @Override void initialize(PluginLoaderData plugindata, Toolbox toolbox); static final Logger LOG; }### Answer:
@Test public void testInitialize() { fail("Not yet implemented."); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { @Override public abstract boolean equals(Object obj); static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@SuppressWarnings("PMD.UseAssertEqualsInsteadOfAssertTrue") @Test public void testEquals() { TimeSpan one = TimeSpan.get(100L, 200L); TimeSpan sameAsOne = TimeSpan.get(100L, 200L); TimeSpan two = TimeSpan.get(100L, 201L); TimeSpan three = TimeSpan.get(99L, 200L); assertTrue(one.equals(sameAsOne)); assertTrue(sameAsOne.equals(one)); assertFalse(one.equals(two)); assertFalse(one.equals(three)); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { public boolean isTimeless() { return this == TIMELESS; } static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@Test public void testIsTimeless() { assertTrue(TimeSpan.TIMELESS.isTimeless()); assertFalse(TimeSpan.get(0, 25).isTimeless()); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { @Override public TimeSpan getTimeSpan() { return this; } static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@Test public void getTimeSpan() { TimeSpan span = TimeSpan.TIMELESS; assertTrue(span == span.getTimeSpan()); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { public boolean isBefore(TimeSpan o) { return precedesIntersectsOrTrails(o) > 0; } static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@Test public void testIsBefore() { TimeSpan beforeTimespan = TimeSpan.get(0, new Seconds(5)); TimeSpan afterTimespan = TimeSpan.get(10000, new Seconds(5)); assertTrue(beforeTimespan.isBefore(afterTimespan)); assertFalse(afterTimespan.isBefore(beforeTimespan)); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { public boolean isAfter(TimeSpan o) { return precedesIntersectsOrTrails(o) < 0; } static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@Test public void testIsAfter() { TimeSpan beforeTimespan = TimeSpan.get(0, new Seconds(5)); TimeSpan afterTimespan = TimeSpan.get(10000, new Seconds(5)); assertFalse(beforeTimespan.isAfter(afterTimespan)); assertTrue(afterTimespan.isAfter(beforeTimespan)); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { public TimeInstant getMidpointInstant() { return TimeInstant.get(getMidpoint()); } static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@Test public void testGetMidpointInstant() { TimeSpan span = TimeSpan.get(0, 2); TimeInstant instant = span.getMidpointInstant(); assertEquals(1, instant.getEpochMillis()); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { public abstract Duration getDuration(); static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@Test public void testGetDuration() { assertEquals(new Milliseconds(100L), TimeSpan.get(100L, 200L).getDuration()); assertEquals(Months.ONE, TimeSpan.get(100L, Months.ONE).getDuration()); }
@Test(expected = UnsupportedOperationException.class) public void testGetDurationUnbounded1() { TimeSpan.TIMELESS.getDuration(); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { public abstract long getDurationMs(); static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@Test public void testGetDurationMs() { assertEquals(100L, TimeSpan.get(100L, 200L).getDurationMs()); }
@Test(expected = UnsupportedOperationException.class) public void testGetDurationMsUnbounded1() { TimeSpan.TIMELESS.getDurationMs(); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { public abstract long getEnd(); static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@Test public void testGetEnd() { long t1 = 1L; long t2 = 2L; TimeSpan span = TimeSpan.get(t1, t2); assertTrue(span.getEnd() == t2); }
@Test(expected = UnsupportedOperationException.class) public void testGetEndUnbounded1() { TimeSpan.TIMELESS.getEnd(); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { public Date getEndDate() { return new Date(getEnd()); } static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@Test public void testGetEndDate() { long t1 = 1L; long t2 = 2L; TimeSpan span = TimeSpan.get(t1, t2); assertTrue(span.getEndDate().getTime() == t2); }
@Test(expected = UnsupportedOperationException.class) public void testGetEndDateUnbounded1() { TimeSpan.TIMELESS.getEndDate(); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { public long getMidpoint() { return (getStart() >> 1) + (getEnd() >> 1) + (getStart() & getEnd() & 1L); } static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@Test public void testGetMidpoint() { assertEquals(15L, TimeSpan.get(10L, 20L).getMidpoint()); assertEquals(11L, TimeSpan.get(11L, 11L).getMidpoint()); assertEquals(12L, TimeSpan.get(11L, 13L).getMidpoint()); assertEquals(Long.MAX_VALUE - 100L, TimeSpan.get(Long.MAX_VALUE - 101L, Long.MAX_VALUE - 99L).getMidpoint()); }
@Test(expected = UnsupportedOperationException.class) public void testGetMidpointUnbounded1() { TimeSpan.TIMELESS.getMidpoint(); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { public Date getMidpointDate() { return new Date(getMidpoint()); } static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@Test public void testGetMidpointDate() { long t1 = 10L; long t2 = 20L; TimeSpan span = TimeSpan.get(t1, t2); assertTrue(span.getMidpointDate().getTime() == 15L); }
@Test(expected = UnsupportedOperationException.class) public void testGetMidpointDateUnbounded1() { TimeSpan.TIMELESS.getMidpointDate(); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { public abstract long getStart(); static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@Test public void testGetStart() { long t1 = 1L; long t2 = 2L; TimeSpan span = TimeSpan.get(t1, t2); assertTrue(span.getStart() == t1); }
@Test(expected = UnsupportedOperationException.class) public void testGetStartUnbounded1() { TimeSpan.TIMELESS.getStart(); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { public Date getStartDate() { return new Date(getStart()); } static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@Test public void testGetStartDate() { long t1 = 1L; long t2 = 2L; TimeSpan span = TimeSpan.get(t1, t2); assertTrue(span.getStartDate().getTime() == t1); }
@Test(expected = UnsupportedOperationException.class) public void testGetStartDateUnbounded1() { TimeSpan.TIMELESS.getStartDate(); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { @Override public abstract int hashCode(); static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@Test public void testHashCode() { TimeSpan one = TimeSpan.get(100L, 200L); TimeSpan sameAsOne = TimeSpan.get(100L, 200L); TimeSpan two = TimeSpan.get(100L, 201L); TimeSpan three = TimeSpan.get(99L, 200L); assertTrue(one.hashCode() == sameAsOne.hashCode()); assertFalse(one.hashCode() == two.hashCode()); assertFalse(one.hashCode() == three.hashCode()); }
|
### Question:
GroupByAvailableActiveLayersTreeBuilder extends GroupByDefaultTreeBuilder { @Override public String getGroupByName() { return "Active"; } @Override String getGroupByName(); @Override GroupCategorizer getGroupCategorizer(); }### Answer:
@Test public void testGetGroupByName() { GroupByAvailableActiveLayersTreeBuilder builder = new GroupByAvailableActiveLayersTreeBuilder(); assertEquals("Active", builder.getGroupByName()); }
|
### Question:
GroupByTagsTreeBuilder extends GroupByDefaultTreeBuilder { @Override public String getGroupByName() { return "Tag"; } @Override String getGroupByName(); @Override GroupCategorizer getGroupCategorizer(); }### Answer:
@Test public void testGetGroupByName() { GroupByTagsTreeBuilder builder = new GroupByTagsTreeBuilder(); assertEquals("Tag", builder.getGroupByName()); }
|
### Question:
TimeSpan implements Comparable<TimeSpan>, Serializable, TimeSpanProvider, SizeProvider { @Override public String toString() { return TimeSpanFormatter.toString(this); } static TimeSpan fromISO8601String(String input); static TimeSpan fromLongs(long start, long end, long unboundedStart, long unboundedEnd); static TimeSpan get(); static TimeSpan get(Date instantaneous); static TimeSpan spanOrPt(Date start, Date end); static TimeSpan get(Date start, Date end); static TimeSpan get(Date start, Duration dur); static TimeSpan get(Duration dur, Date end); static TimeSpan get(Duration dur, long end); static TimeSpan get(Duration dur, TimeInstant end); static TimeSpan get(long time); static TimeSpan get(long start, Duration dur); static TimeSpan get(long start, long end); static TimeSpan get(TimeInstant instant); static TimeSpan get(TimeInstant start, Duration dur); static TimeSpan get(TimeInstant start, TimeInstant end); static TimeSpan newUnboundedEndTimeSpan(Date start); static TimeSpan newUnboundedEndTimeSpan(long start); static TimeSpan newUnboundedStartTimeSpan(Date end); static TimeSpan newUnboundedStartTimeSpan(long end); TimeInstant clamp(TimeInstant t); TimeSpan clamp(TimeSpan t); abstract int compareEnd(long time); abstract int compareStart(long time); abstract boolean contains(TimeSpan other); @Override abstract boolean equals(Object obj); boolean formsContiguousRange(TimeSpan other); abstract Duration getDuration(); abstract long getDurationMs(); abstract long getEnd(); abstract long getEnd(long unboundedValue); Date getEndDate(); Date getEndDate(Date unboundedValue); TimeInstant getEndInstant(); abstract Duration getGapBetween(TimeSpan other); abstract TimeSpan getIntersection(TimeSpan other); long getMidpoint(); Date getMidpointDate(); TimeInstant getMidpointInstant(); abstract RangeRelationType getRelation(TimeSpan other); abstract long getStart(); abstract long getStart(long unboundedValue); Date getStartDate(); Date getStartDate(Date unboundedValue); TimeInstant getStartInstant(); @Override TimeSpan getTimeSpan(); @Override abstract int hashCode(); abstract TimeSpan interpolate(TimeSpan other, double fraction); boolean isAfter(TimeSpan o); boolean isBefore(TimeSpan o); abstract boolean isBounded(); abstract boolean isInstantaneous(); boolean isTimeless(); abstract boolean isUnboundedEnd(); abstract boolean isUnboundedStart(); abstract boolean isZero(); TimeSpan minus(Duration dur); boolean overlaps(Collection<? extends TimeSpan> list); boolean overlaps(Date time); abstract boolean overlaps(long time); boolean overlaps(TimeInstant time); abstract boolean overlaps(TimeSpan other); TimeSpan plus(Duration dur); abstract int precedesIntersectsOrTrails(TimeSpan b); abstract TimeSpan simpleUnion(TimeSpan other); List<TimeSpan> subDivide(int divisions); List<TimeSpan> subtract(Collection<? extends TimeSpan> others); abstract List<TimeSpan> subtract(TimeSpan other); String toDisplayString(); String toISO8601String(); String toSmartString(); @Override String toString(); abstract boolean touches(TimeSpan other); abstract TimeSpan union(TimeSpan other); static final TimeSpan TIMELESS; static final TimeSpan ZERO; }### Answer:
@Test public void testToString() { long t1 = 1L; long t2 = 2L; TimeSpan span = TimeSpan.get(t1, t2); String string = span.toString(); assertTrue(string.length() > 0); assertFalse(string.equals(span.getClass().getName() + "@" + Integer.toHexString(span.hashCode()))); }
|
### Question:
DefaultTimeSpanSet implements TimeSpanSet { @Override public boolean contains(Date aDate) { return contains(aDate.getTime()); } DefaultTimeSpanSet(); DefaultTimeSpanSet(TimeSpan ts); DefaultTimeSpanSet(TimeSpanSet other); @Override boolean add(TimeSpan e); @Override final boolean add(TimeSpanSet other); @Override boolean addAll(Collection<? extends TimeSpan> c); @Override void clear(); @Override boolean contains(Date aDate); @Override boolean contains(long aTime); @Override boolean contains(Object o); @Override boolean contains(TimeSpan value); @Override boolean containsAll(Collection<?> c); @Override boolean equals(Object obj); @Override List<TimeSpan> getTimeSpans(); @Override int hashCode(); @Override TimeSpanSet intersection(TimeSpan ts); @Override TimeSpanSet intersection(TimeSpanSet otherSet); @Override boolean intersects(TimeSpan value); @Override boolean intersects(TimeSpanProvider ts); @Override boolean intersects(TimeSpanSet other); @Override boolean isEmpty(); @Override Iterator<TimeSpan> iterator(); @Override boolean remove(Object o); @Override boolean remove(TimeSpan spanToRemove); @Override boolean remove(TimeSpanSet other); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override int size(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override String toString(); @Override TimeSpanSet union(TimeSpanSet other); }### Answer:
@Test public void testContains() { long[] setA = { 1, 2, 5, 6, 8, 9, 11, 12, 13, 14, 15, 55, 56, 57 }; DefaultTimeSpanSet rlsA = new DefaultTimeSpanSet(); rlsA.addAll(createTestTimeSpans(setA)); assertEquals(5, rlsA.size()); DefaultTimeSpanSet rlsB = new DefaultTimeSpanSet(); rlsB.addAll(createTestTimeSpans(setA)); long[] setC = { 1, 2, 5, 6, 14, 15, 55, 56, 57 }; DefaultTimeSpanSet rlsC = new DefaultTimeSpanSet(); rlsC.addAll(createTestTimeSpans(setC)); assertEquals(rlsA, rlsB); assertFalse(rlsA.equals(rlsC)); assertEquals(rlsA.hashCode(), rlsB.hashCode()); assertTrue(rlsA.hashCode() != rlsC.hashCode()); DefaultTimeSpanSet emptySet = new DefaultTimeSpanSet(); assertTrue(emptySet.isEmpty()); assertFalse(rlsA.isEmpty()); assertFalse(rlsC.isEmpty()); rlsC.clear(); assertTrue(rlsC.isEmpty()); assertTrue(rlsA.contains(12)); assertTrue(rlsA.contains(55)); assertFalse(rlsA.contains(3)); assertFalse(rlsA.contains(16)); assertFalse(rlsA.contains(-1)); assertFalse(rlsA.contains(5000)); assertTrue(rlsA.contains(Long.valueOf(12))); assertTrue(rlsA.contains(Long.valueOf(55))); assertFalse(rlsA.contains(Long.valueOf(3))); assertFalse(rlsA.contains(Long.valueOf(16))); assertFalse(rlsA.contains(Long.valueOf(-1))); assertFalse(rlsA.contains(Long.valueOf(5000))); }
|
### Question:
GroupByDefaultTreeBuilder implements ActiveGroupByTreeBuilder, AvailableGroupByTreeBuilder { @Override public String getGroupByName() { return "Source"; } Set<String> getCategories(); DataGroupController getDataGroupController(); @Override String getGroupByName(); @Override GroupCategorizer getGroupCategorizer(); @Override Comparator<? super DataGroupInfo> getGroupComparator(); @Override Predicate<DataGroupInfo> getDataCategoryFilter(); @Override Predicate<DataGroupInfo> getGroupFilter(); Toolbox getToolbox(); @Override TreeOptions getTreeOptions(); @Override Comparator<? super DataTypeInfo> getTypeComparator(); @Override void initializeForActive(Toolbox toolbox); @Override void initializeForAvailable(Toolbox toolbox); @Override void setGroupComparator(Comparator<? super DataGroupInfo> comp); void setTypeComparator(Comparator<? super DataTypeInfo> comp); boolean isActiveGroupsOnly(); boolean isSubNodesForMultiMemberGroups(); }### Answer:
@Test public void testGetGroupByName() { GroupByDefaultTreeBuilder builder = new GroupByDefaultTreeBuilder(); assertEquals("Source", builder.getGroupByName()); }
|
### Question:
DefaultTimeSpanSet implements TimeSpanSet { @Override public boolean remove(Object o) { TimeSpan ts = getAsTimespan(o); if (ts != null) { return remove(ts); } return false; } DefaultTimeSpanSet(); DefaultTimeSpanSet(TimeSpan ts); DefaultTimeSpanSet(TimeSpanSet other); @Override boolean add(TimeSpan e); @Override final boolean add(TimeSpanSet other); @Override boolean addAll(Collection<? extends TimeSpan> c); @Override void clear(); @Override boolean contains(Date aDate); @Override boolean contains(long aTime); @Override boolean contains(Object o); @Override boolean contains(TimeSpan value); @Override boolean containsAll(Collection<?> c); @Override boolean equals(Object obj); @Override List<TimeSpan> getTimeSpans(); @Override int hashCode(); @Override TimeSpanSet intersection(TimeSpan ts); @Override TimeSpanSet intersection(TimeSpanSet otherSet); @Override boolean intersects(TimeSpan value); @Override boolean intersects(TimeSpanProvider ts); @Override boolean intersects(TimeSpanSet other); @Override boolean isEmpty(); @Override Iterator<TimeSpan> iterator(); @Override boolean remove(Object o); @Override boolean remove(TimeSpan spanToRemove); @Override boolean remove(TimeSpanSet other); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override int size(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override String toString(); @Override TimeSpanSet union(TimeSpanSet other); }### Answer:
@Test public void testRemove() { long[] setA = { 1, 2, 3, 5, 6, 8, 9, 11, 12, 13, 14, 15 }; DefaultTimeSpanSet rls = new DefaultTimeSpanSet(); rls.addAll(createTestTimeSpans(setA)); rls.add(TimeSpan.get(55, 100)); assertEquals(5, rls.size()); boolean changed = rls.remove(TimeSpan.get(54, 57)); assertTrue(changed); assertEquals(5, rls.size()); changed = rls.remove(TimeSpan.get(10, 13)); assertTrue(changed); assertEquals(5, rls.size()); changed = rls.remove(TimeSpan.get(1, 2)); assertTrue(changed); assertEquals(5, rls.size()); changed = rls.remove(TimeSpan.get(14, 21)); assertTrue(changed); assertEquals(5, rls.size()); changed = rls.remove(TimeSpan.get(98, 111)); assertTrue(changed); assertEquals(5, rls.size()); rls.add(TimeSpan.get(1, 2)); changed = rls.remove(TimeSpan.get(2, 4)); assertTrue(changed); assertEquals(5, rls.size()); changed = rls.remove(TimeSpan.get(60, 66)); assertTrue(changed); assertEquals(6, rls.size()); changed = rls.remove(TimeSpan.get(60, 66)); assertFalse(changed); assertEquals(6, rls.size()); changed = rls.remove(TimeSpan.get(57, 60)); assertTrue(changed); assertEquals(5, rls.size()); changed = rls.remove(TimeSpan.get(3, 8)); assertTrue(changed); assertEquals(4, rls.size()); changed = rls.remove(TimeSpan.get(7, 61)); assertTrue(changed); assertEquals(2, rls.size()); }
|
### Question:
DefaultTimeSpanSet implements TimeSpanSet { @Override public TimeSpanSet union(TimeSpanSet other) { DefaultTimeSpanSet newSet = new DefaultTimeSpanSet(this); newSet.add(other); return newSet; } DefaultTimeSpanSet(); DefaultTimeSpanSet(TimeSpan ts); DefaultTimeSpanSet(TimeSpanSet other); @Override boolean add(TimeSpan e); @Override final boolean add(TimeSpanSet other); @Override boolean addAll(Collection<? extends TimeSpan> c); @Override void clear(); @Override boolean contains(Date aDate); @Override boolean contains(long aTime); @Override boolean contains(Object o); @Override boolean contains(TimeSpan value); @Override boolean containsAll(Collection<?> c); @Override boolean equals(Object obj); @Override List<TimeSpan> getTimeSpans(); @Override int hashCode(); @Override TimeSpanSet intersection(TimeSpan ts); @Override TimeSpanSet intersection(TimeSpanSet otherSet); @Override boolean intersects(TimeSpan value); @Override boolean intersects(TimeSpanProvider ts); @Override boolean intersects(TimeSpanSet other); @Override boolean isEmpty(); @Override Iterator<TimeSpan> iterator(); @Override boolean remove(Object o); @Override boolean remove(TimeSpan spanToRemove); @Override boolean remove(TimeSpanSet other); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override int size(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override String toString(); @Override TimeSpanSet union(TimeSpanSet other); }### Answer:
@Test public void testUnion() { long[] setA = { 1, 2, 5, 6, 8, 9, 11, 12, 13, 14, 15, 55, 56, 57 }; DefaultTimeSpanSet rlsA = new DefaultTimeSpanSet(); rlsA.addAll(createTestTimeSpans(setA)); long[] setB = { 1, 2, 5, 7, 15, 17, 50, 51, 52, 57 }; DefaultTimeSpanSet rlsB = new DefaultTimeSpanSet(); rlsB.addAll(createTestTimeSpans(setB)); TimeSpanSet unionedSet = rlsA.union(rlsB); assertEquals(6, unionedSet.size()); assertEquals(1, unionedSet.getTimeSpans().get(0).getStart()); assertEquals(3, unionedSet.getTimeSpans().get(0).getEnd()); assertEquals(5, unionedSet.getTimeSpans().get(1).getStart()); assertEquals(10, unionedSet.getTimeSpans().get(1).getEnd()); assertEquals(11, unionedSet.getTimeSpans().get(2).getStart()); assertEquals(16, unionedSet.getTimeSpans().get(2).getEnd()); assertEquals(17, unionedSet.getTimeSpans().get(3).getStart()); assertEquals(18, unionedSet.getTimeSpans().get(3).getEnd()); assertEquals(50, unionedSet.getTimeSpans().get(4).getStart()); assertEquals(53, unionedSet.getTimeSpans().get(4).getEnd()); assertEquals(55, unionedSet.getTimeSpans().get(5).getStart()); assertEquals(58, unionedSet.getTimeSpans().get(5).getEnd()); }
|
### Question:
DefaultTimeSpanSet implements TimeSpanSet { @Override public String toString() { StringBuilder sb = new StringBuilder(32); myElementListLock.lock(); try { sb.append("TimeSpanSet{"); boolean isFirst = true; for (TimeSpan block : myElementList) { if (isFirst) { isFirst = !isFirst; } else { sb.append(','); } sb.append(block.toString()); } sb.append('}'); } finally { myElementListLock.unlock(); } return sb.toString(); } DefaultTimeSpanSet(); DefaultTimeSpanSet(TimeSpan ts); DefaultTimeSpanSet(TimeSpanSet other); @Override boolean add(TimeSpan e); @Override final boolean add(TimeSpanSet other); @Override boolean addAll(Collection<? extends TimeSpan> c); @Override void clear(); @Override boolean contains(Date aDate); @Override boolean contains(long aTime); @Override boolean contains(Object o); @Override boolean contains(TimeSpan value); @Override boolean containsAll(Collection<?> c); @Override boolean equals(Object obj); @Override List<TimeSpan> getTimeSpans(); @Override int hashCode(); @Override TimeSpanSet intersection(TimeSpan ts); @Override TimeSpanSet intersection(TimeSpanSet otherSet); @Override boolean intersects(TimeSpan value); @Override boolean intersects(TimeSpanProvider ts); @Override boolean intersects(TimeSpanSet other); @Override boolean isEmpty(); @Override Iterator<TimeSpan> iterator(); @Override boolean remove(Object o); @Override boolean remove(TimeSpan spanToRemove); @Override boolean remove(TimeSpanSet other); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override int size(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override String toString(); @Override TimeSpanSet union(TimeSpanSet other); }### Answer:
@Test public void testToString() { TimeZone.setDefault(TimeZone.getTimeZone("GMT")); long[] setA = { 1, 2, 5, 6, 8, 9, 11, 12, 13, 14, 15, 55, 56, 57 }; DefaultTimeSpanSet rlsA = new DefaultTimeSpanSet(); rlsA.addAll(createTestTimeSpans(setA)); assertEquals("TimeSpanSet{TimeSpan[1970-01-01 00:00:00.001,1970-01-01 00:00:00.003]," + "TimeSpan[1970-01-01 00:00:00.005,1970-01-01 00:00:00.007]," + "TimeSpan[1970-01-01 00:00:00.008,1970-01-01 00:00:00.010]," + "TimeSpan[1970-01-01 00:00:00.011,1970-01-01 00:00:00.016]," + "TimeSpan[1970-01-01 00:00:00.055,1970-01-01 00:00:00.058]}", rlsA.toString()); }
|
### Question:
DefaultTimeSpanSet implements TimeSpanSet { @Override public Object[] toArray() { Object[] result = null; myElementListLock.lock(); try { result = myElementList.toArray(); } finally { myElementListLock.unlock(); } return result; } DefaultTimeSpanSet(); DefaultTimeSpanSet(TimeSpan ts); DefaultTimeSpanSet(TimeSpanSet other); @Override boolean add(TimeSpan e); @Override final boolean add(TimeSpanSet other); @Override boolean addAll(Collection<? extends TimeSpan> c); @Override void clear(); @Override boolean contains(Date aDate); @Override boolean contains(long aTime); @Override boolean contains(Object o); @Override boolean contains(TimeSpan value); @Override boolean containsAll(Collection<?> c); @Override boolean equals(Object obj); @Override List<TimeSpan> getTimeSpans(); @Override int hashCode(); @Override TimeSpanSet intersection(TimeSpan ts); @Override TimeSpanSet intersection(TimeSpanSet otherSet); @Override boolean intersects(TimeSpan value); @Override boolean intersects(TimeSpanProvider ts); @Override boolean intersects(TimeSpanSet other); @Override boolean isEmpty(); @Override Iterator<TimeSpan> iterator(); @Override boolean remove(Object o); @Override boolean remove(TimeSpan spanToRemove); @Override boolean remove(TimeSpanSet other); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override int size(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override String toString(); @Override TimeSpanSet union(TimeSpanSet other); }### Answer:
@Test public void testToArray() { long[] setA = { 1, 2, 5, 6, 8, 9, 11, 12, 13, 14, 15, 55, 56, 57 }; DefaultTimeSpanSet rlsA = new DefaultTimeSpanSet(); rlsA.addAll(createTestTimeSpans(setA)); Object[] timeSpans = rlsA.toArray(); assertEquals(5, timeSpans.length); assertTrue(timeSpans[0] instanceof TimeSpan); assertTrue(timeSpans[1] instanceof TimeSpan); assertTrue(timeSpans[2] instanceof TimeSpan); assertTrue(timeSpans[3] instanceof TimeSpan); assertTrue(timeSpans[4] instanceof TimeSpan); assertEquals(1, ((TimeSpan)timeSpans[0]).getStart()); assertEquals(3, ((TimeSpan)timeSpans[0]).getEnd()); assertEquals(5, ((TimeSpan)timeSpans[1]).getStart()); assertEquals(7, ((TimeSpan)timeSpans[1]).getEnd()); assertEquals(8, ((TimeSpan)timeSpans[2]).getStart()); assertEquals(10, ((TimeSpan)timeSpans[2]).getEnd()); assertEquals(11, ((TimeSpan)timeSpans[3]).getStart()); assertEquals(16, ((TimeSpan)timeSpans[3]).getEnd()); assertEquals(55, ((TimeSpan)timeSpans[4]).getStart()); assertEquals(58, ((TimeSpan)timeSpans[4]).getEnd()); }
|
### Question:
DefaultTimeSpanSet implements TimeSpanSet { @Override public boolean containsAll(Collection<?> c) { for (Object o : c) { TimeSpan ts = getAsTimespan(o); if (ts == null || !contains(ts)) { return false; } } return true; } DefaultTimeSpanSet(); DefaultTimeSpanSet(TimeSpan ts); DefaultTimeSpanSet(TimeSpanSet other); @Override boolean add(TimeSpan e); @Override final boolean add(TimeSpanSet other); @Override boolean addAll(Collection<? extends TimeSpan> c); @Override void clear(); @Override boolean contains(Date aDate); @Override boolean contains(long aTime); @Override boolean contains(Object o); @Override boolean contains(TimeSpan value); @Override boolean containsAll(Collection<?> c); @Override boolean equals(Object obj); @Override List<TimeSpan> getTimeSpans(); @Override int hashCode(); @Override TimeSpanSet intersection(TimeSpan ts); @Override TimeSpanSet intersection(TimeSpanSet otherSet); @Override boolean intersects(TimeSpan value); @Override boolean intersects(TimeSpanProvider ts); @Override boolean intersects(TimeSpanSet other); @Override boolean isEmpty(); @Override Iterator<TimeSpan> iterator(); @Override boolean remove(Object o); @Override boolean remove(TimeSpan spanToRemove); @Override boolean remove(TimeSpanSet other); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override int size(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override String toString(); @Override TimeSpanSet union(TimeSpanSet other); }### Answer:
@Test public void testContainsAll() { long[] setA = { 1, 2, 5, 6, 8, 9, 11, 12, 13, 14, 15, 55, 56, 57 }; DefaultTimeSpanSet rlsA = new DefaultTimeSpanSet(); rlsA.addAll(createTestTimeSpans(setA)); Collection<TimeSpan> testValues = Arrays.asList(new TimeSpanLongLong(1, 2), new TimeSpanLongLong(11, 16)); assertTrue(rlsA.containsAll(testValues)); }
|
### Question:
DefaultTimeSpanSet implements TimeSpanSet { @Override public boolean add(TimeSpan e) { if (e == null || e.isTimeless()) { return false; } boolean changedSomething = false; myElementListLock.lock(); try { int size = myElementList.size(); if (size == 0) { myElementList.add(e); changedSomething = true; } else if (size == 1) { if (addSpanWhenListHasOnlyOneBlock(e)) { changedSomething = true; } } else { changedSomething = binarySearchInsert(e); } } finally { myElementListLock.unlock(); } return changedSomething; } DefaultTimeSpanSet(); DefaultTimeSpanSet(TimeSpan ts); DefaultTimeSpanSet(TimeSpanSet other); @Override boolean add(TimeSpan e); @Override final boolean add(TimeSpanSet other); @Override boolean addAll(Collection<? extends TimeSpan> c); @Override void clear(); @Override boolean contains(Date aDate); @Override boolean contains(long aTime); @Override boolean contains(Object o); @Override boolean contains(TimeSpan value); @Override boolean containsAll(Collection<?> c); @Override boolean equals(Object obj); @Override List<TimeSpan> getTimeSpans(); @Override int hashCode(); @Override TimeSpanSet intersection(TimeSpan ts); @Override TimeSpanSet intersection(TimeSpanSet otherSet); @Override boolean intersects(TimeSpan value); @Override boolean intersects(TimeSpanProvider ts); @Override boolean intersects(TimeSpanSet other); @Override boolean isEmpty(); @Override Iterator<TimeSpan> iterator(); @Override boolean remove(Object o); @Override boolean remove(TimeSpan spanToRemove); @Override boolean remove(TimeSpanSet other); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override int size(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override String toString(); @Override TimeSpanSet union(TimeSpanSet other); }### Answer:
@Test public void testAddNull() { DefaultTimeSpanSet rlsA = new DefaultTimeSpanSet(); assertFalse(rlsA.add((TimeSpan)null)); }
@Test public void testAddTimeless() { DefaultTimeSpanSet rlsA = new DefaultTimeSpanSet(); assertFalse(rlsA.add(new TimelessTimeSpan())); }
|
### Question:
DefaultTimeSpanSet implements TimeSpanSet { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } DefaultTimeSpanSet other = (DefaultTimeSpanSet)obj; return Objects.equals(myElementList, other.myElementList); } DefaultTimeSpanSet(); DefaultTimeSpanSet(TimeSpan ts); DefaultTimeSpanSet(TimeSpanSet other); @Override boolean add(TimeSpan e); @Override final boolean add(TimeSpanSet other); @Override boolean addAll(Collection<? extends TimeSpan> c); @Override void clear(); @Override boolean contains(Date aDate); @Override boolean contains(long aTime); @Override boolean contains(Object o); @Override boolean contains(TimeSpan value); @Override boolean containsAll(Collection<?> c); @Override boolean equals(Object obj); @Override List<TimeSpan> getTimeSpans(); @Override int hashCode(); @Override TimeSpanSet intersection(TimeSpan ts); @Override TimeSpanSet intersection(TimeSpanSet otherSet); @Override boolean intersects(TimeSpan value); @Override boolean intersects(TimeSpanProvider ts); @Override boolean intersects(TimeSpanSet other); @Override boolean isEmpty(); @Override Iterator<TimeSpan> iterator(); @Override boolean remove(Object o); @Override boolean remove(TimeSpan spanToRemove); @Override boolean remove(TimeSpanSet other); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override int size(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override String toString(); @Override TimeSpanSet union(TimeSpanSet other); }### Answer:
@Test public void testEqualsWrongType() { DefaultTimeSpanSet rlsA = new DefaultTimeSpanSet(); assertFalse(rlsA.equals(RandomStringUtils.randomAlphabetic(5))); }
|
### Question:
TimeInstant implements Comparable<TimeInstant>, Serializable, SizeProvider { public String toISO8601String() { return DateTimeUtilities.generateISO8601DateString(toDate()); } static TimeInstant get(); static TimeInstant get(Calendar time); static TimeInstant get(Date time); static TimeInstant get(long epochMillis); static TimeInstant max(TimeInstant t1, TimeInstant t2); static TimeInstant min(TimeInstant t1, TimeInstant t2); @Override int compareTo(TimeInstant o); @Override boolean equals(Object obj); abstract long getEpochMillis(); @Override int hashCode(); boolean isAfter(TimeInstant other); boolean isBefore(TimeInstant other); boolean isOverlapped(Collection<? extends TimeSpan> timeSpans); TimeInstant minus(Duration dur); Duration minus(TimeInstant other); TimeInstant plus(Duration dur); Date toDate(); String toDisplayString(); String toDisplayString(String fmt); String toISO8601String(); @Override String toString(); }### Answer:
@Test public void testToISO8601String() throws ParseException { SimpleDateFormat fmt = new SimpleDateFormat(DateTimeFormats.DATE_TIME_FORMAT); TimeInstant timeInstant = TimeInstant.get(fmt.parse("2010-03-13 12:35:17")); String actual = timeInstant.toISO8601String(); String expected = "2010-03-13T12:35:17Z"; Assert.assertEquals(expected, actual); fmt = new SimpleDateFormat(DateTimeFormats.DATE_TIME_MILLIS_FORMAT); timeInstant = TimeInstant.get(fmt.parse("2010-03-13 12:35:17.001")); actual = timeInstant.toISO8601String(); expected = "2010-03-13T12:35:17.001Z"; Assert.assertEquals(expected, actual); }
|
### Question:
GroupByDefaultTreeBuilder implements ActiveGroupByTreeBuilder, AvailableGroupByTreeBuilder { @Override public void initializeForActive(Toolbox toolbox) { setToolbox(toolbox); myActiveGroupsOnly = true; mySubNodesForMultiMemberGroups = true; } Set<String> getCategories(); DataGroupController getDataGroupController(); @Override String getGroupByName(); @Override GroupCategorizer getGroupCategorizer(); @Override Comparator<? super DataGroupInfo> getGroupComparator(); @Override Predicate<DataGroupInfo> getDataCategoryFilter(); @Override Predicate<DataGroupInfo> getGroupFilter(); Toolbox getToolbox(); @Override TreeOptions getTreeOptions(); @Override Comparator<? super DataTypeInfo> getTypeComparator(); @Override void initializeForActive(Toolbox toolbox); @Override void initializeForAvailable(Toolbox toolbox); @Override void setGroupComparator(Comparator<? super DataGroupInfo> comp); void setTypeComparator(Comparator<? super DataTypeInfo> comp); boolean isActiveGroupsOnly(); boolean isSubNodesForMultiMemberGroups(); }### Answer:
@Test public void testInitializeForActive() { EasyMockSupport support = new EasyMockSupport(); Toolbox toolbox = support.createMock(Toolbox.class); support.replayAll(); GroupByDefaultTreeBuilder builder = new GroupByDefaultTreeBuilder(); builder.initializeForActive(toolbox); assertEquals(toolbox, builder.getToolbox()); assertTrue(builder.isActiveGroupsOnly()); assertTrue(builder.isSubNodesForMultiMemberGroups()); support.verifyAll(); }
|
### Question:
BinaryTimeTree { public BinaryTimeTree() { this(DEFAULT_MAX_VALUES_PER_NODE, DEFAULT_MAX_DEPTH); } BinaryTimeTree(); BinaryTimeTree(int maxValuesPerNode, int maxDepth); void clear(); int countInRange(TimeSpan range); CountReport countsInBins(TimeSpan overAllRange, int numberOfBins); TIntList countsInRanges(List<TimeSpan> countTimes); List<E> findInRange(TimeSpan range); boolean insert(E tsProvider); boolean insert(List<E> collection); int internalSize(BTreeNode<E> node); int maxValuesPerNodeInteral(BTreeNode<E> node, int maxValues); int queryMaxValuesPerNode(); int size(); }### Answer:
@Test public void testBinaryTimeTree() { assertNotNull(myTestObject); }
|
### Question:
BinaryTimeTree { public void clear() { nodeClear(myTopNode); myTopNode.setRange(null); } BinaryTimeTree(); BinaryTimeTree(int maxValuesPerNode, int maxDepth); void clear(); int countInRange(TimeSpan range); CountReport countsInBins(TimeSpan overAllRange, int numberOfBins); TIntList countsInRanges(List<TimeSpan> countTimes); List<E> findInRange(TimeSpan range); boolean insert(E tsProvider); boolean insert(List<E> collection); int internalSize(BTreeNode<E> node); int maxValuesPerNodeInteral(BTreeNode<E> node, int maxValues); int queryMaxValuesPerNode(); int size(); }### Answer:
@Test public void testClear() { myTestObject.clear(); assertEquals(0, myTestObject.size()); }
|
### Question:
BinaryTimeTree { public int countInRange(TimeSpan range) { return myTopNode.countInRange(range); } BinaryTimeTree(); BinaryTimeTree(int maxValuesPerNode, int maxDepth); void clear(); int countInRange(TimeSpan range); CountReport countsInBins(TimeSpan overAllRange, int numberOfBins); TIntList countsInRanges(List<TimeSpan> countTimes); List<E> findInRange(TimeSpan range); boolean insert(E tsProvider); boolean insert(List<E> collection); int internalSize(BTreeNode<E> node); int maxValuesPerNodeInteral(BTreeNode<E> node, int maxValues); int queryMaxValuesPerNode(); int size(); }### Answer:
@Test(expected = NullPointerException.class) public void testCountInRangeEmptyNode() { assertEquals(0, myTestObject.countInRange(TimeSpan.ZERO)); }
@Test public void testCountInRange() { TimeSpan span1 = new TimeSpanLongLong(0, 1); TimeSpan span2 = new TimeSpanLongLong(1, 2); TimeSpanProvider mock1 = createNiceMock(TimeSpanProvider.class); TimeSpanProvider mock2 = createNiceMock(TimeSpanProvider.class); expect(mock1.getTimeSpan()).andReturn(span1).anyTimes(); expect(mock2.getTimeSpan()).andReturn(span2).anyTimes(); replay(mock1, mock2); myTestObject.insert(Arrays.asList(mock1, mock2)); assertEquals(1, myTestObject.countInRange(span1)); }
|
### Question:
BinaryTimeTree { public CountReport countsInBins(TimeSpan overAllRange, int numberOfBins) { List<TimeSpan> tsList = overAllRange.subDivide(numberOfBins); if (tsList.isEmpty()) { return new CountReport(); } int minBinCount = Integer.MAX_VALUE; int maxBinCount = 0; int totalCount = 0; List<TimeAndCount> resultList = New.list(tsList.size()); for (TimeSpan span : tsList) { int count = countInRange(span); totalCount += count; if (count > maxBinCount) { maxBinCount = count; } if (count < minBinCount) { minBinCount = count; } resultList.add(new TimeAndCount(span, count)); } return new CountReport(totalCount, minBinCount, maxBinCount, resultList); } BinaryTimeTree(); BinaryTimeTree(int maxValuesPerNode, int maxDepth); void clear(); int countInRange(TimeSpan range); CountReport countsInBins(TimeSpan overAllRange, int numberOfBins); TIntList countsInRanges(List<TimeSpan> countTimes); List<E> findInRange(TimeSpan range); boolean insert(E tsProvider); boolean insert(List<E> collection); int internalSize(BTreeNode<E> node); int maxValuesPerNodeInteral(BTreeNode<E> node, int maxValues); int queryMaxValuesPerNode(); int size(); }### Answer:
@Test public void testCountsInBins() { TimeSpan span1 = new TimeSpanLongLong(0, 100); TimeSpan span2 = new TimeSpanLongLong(0, 50); TimeSpanProvider mock1 = createNiceMock(TimeSpanProvider.class); TimeSpanProvider mock2 = createNiceMock(TimeSpanProvider.class); expect(mock1.getTimeSpan()).andReturn(span1).anyTimes(); expect(mock2.getTimeSpan()).andReturn(span2).anyTimes(); replay(mock1, mock2); myTestObject.insert(Arrays.asList(mock1, mock2)); CountReport report = myTestObject.countsInBins(span1, 50); assertEquals(2, report.getMaxBinCount()); assertEquals(1, report.getMinBinCount()); assertEquals(76, report.getTotalCount()); }
|
### Question:
BinaryTimeTree { public TIntList countsInRanges(List<TimeSpan> countTimes) { Utilities.checkNull(countTimes, "countTimes"); if (countTimes.isEmpty()) { return new TIntArrayList(0); } TIntList resultList = new TIntArrayList(countTimes.size()); for (TimeSpan span : countTimes) { resultList.add(countInRange(span)); } return resultList; } BinaryTimeTree(); BinaryTimeTree(int maxValuesPerNode, int maxDepth); void clear(); int countInRange(TimeSpan range); CountReport countsInBins(TimeSpan overAllRange, int numberOfBins); TIntList countsInRanges(List<TimeSpan> countTimes); List<E> findInRange(TimeSpan range); boolean insert(E tsProvider); boolean insert(List<E> collection); int internalSize(BTreeNode<E> node); int maxValuesPerNodeInteral(BTreeNode<E> node, int maxValues); int queryMaxValuesPerNode(); int size(); }### Answer:
@Test public void testCountsInRanges() { TimeSpan span1 = new TimeSpanLongLong(0, 100); TimeSpan span2 = new TimeSpanLongLong(0, 50); TimeSpanProvider mock1 = createNiceMock(TimeSpanProvider.class); TimeSpanProvider mock2 = createNiceMock(TimeSpanProvider.class); expect(mock1.getTimeSpan()).andReturn(span1).anyTimes(); expect(mock2.getTimeSpan()).andReturn(span2).anyTimes(); replay(mock1, mock2); myTestObject.insert(Arrays.asList(mock1, mock2)); TIntList list = myTestObject.countsInRanges(Arrays.asList(span1, span2)); assertEquals(2, list.size()); }
@Test public void testCountsInRangesEmpty() { TIntList list = myTestObject.countsInRanges(new ArrayList<>()); assertTrue(list.isEmpty()); }
|
### Question:
BinaryTimeTree { public int internalSize(BTreeNode<E> node) { int size = node.getValues().size(); for (BTreeNode<E> subNode : node.getSubNodes()) { if (subNode != null) { size += internalSize(subNode); } } return size; } BinaryTimeTree(); BinaryTimeTree(int maxValuesPerNode, int maxDepth); void clear(); int countInRange(TimeSpan range); CountReport countsInBins(TimeSpan overAllRange, int numberOfBins); TIntList countsInRanges(List<TimeSpan> countTimes); List<E> findInRange(TimeSpan range); boolean insert(E tsProvider); boolean insert(List<E> collection); int internalSize(BTreeNode<E> node); int maxValuesPerNodeInteral(BTreeNode<E> node, int maxValues); int queryMaxValuesPerNode(); int size(); }### Answer:
@Test public void testInternalSize() { BTreeNode<TimeSpanProvider> node = new BTreeNode<>(); BTreeNode<TimeSpanProvider> subNode1 = new BTreeNode<>(); BTreeNode<TimeSpanProvider> subNode2 = new BTreeNode<>(); BTreeNode<TimeSpanProvider> subNode3 = new BTreeNode<>(); BTreeNode<TimeSpanProvider> subNode4 = new BTreeNode<>(); BTreeNode<TimeSpanProvider> subNode5 = new BTreeNode<>(); subNode1.getValues().add(createMock(TimeSpanProvider.class)); subNode1.getValues().add(createMock(TimeSpanProvider.class)); subNode2.getValues().add(createMock(TimeSpanProvider.class)); subNode2.getValues().add(createMock(TimeSpanProvider.class)); subNode2.getValues().add(createMock(TimeSpanProvider.class)); subNode3.getValues().add(createMock(TimeSpanProvider.class)); subNode3.getValues().add(createMock(TimeSpanProvider.class)); node.setSubNodes(new ArrayList<>(Arrays.asList(subNode1, subNode2, subNode3, subNode4, subNode5))); node.setRange(new TimeSpanLongLong(0, 1000)); TimeSpanProvider provider1 = createMock(TimeSpanProvider.class); TimeSpanProvider provider2 = createMock(TimeSpanProvider.class); TimeSpanLongLong span1 = new TimeSpanLongLong(10, 20); expect(provider1.getTimeSpan()).andReturn(span1).anyTimes(); TimeSpanLongLong span2 = new TimeSpanLongLong(20, 200); expect(provider2.getTimeSpan()).andReturn(span2).anyTimes(); replay(provider1, provider2); assertEquals(7, myTestObject.internalSize(node)); }
|
### Question:
BinaryTimeTree { public int maxValuesPerNodeInteral(BTreeNode<E> node, int maxValues) { if (node == null) { return 0; } int max = maxValues; int size = node.getValues().size(); if (size > max) { max = size; } for (BTreeNode<E> subNode : node.getSubNodes()) { if (subNode != null) { size = maxValuesPerNodeInteral(subNode, max); } if (size > max) { max = size; } } return max; } BinaryTimeTree(); BinaryTimeTree(int maxValuesPerNode, int maxDepth); void clear(); int countInRange(TimeSpan range); CountReport countsInBins(TimeSpan overAllRange, int numberOfBins); TIntList countsInRanges(List<TimeSpan> countTimes); List<E> findInRange(TimeSpan range); boolean insert(E tsProvider); boolean insert(List<E> collection); int internalSize(BTreeNode<E> node); int maxValuesPerNodeInteral(BTreeNode<E> node, int maxValues); int queryMaxValuesPerNode(); int size(); }### Answer:
@Test public void testMaxValuesPerNodeInteral() { TimeSpan span1 = new TimeSpanLongLong(0, 1); TimeSpan span2 = new TimeSpanLongLong(1, 2); TimeSpanProvider mock1 = createNiceMock(TimeSpanProvider.class); TimeSpanProvider mock2 = createNiceMock(TimeSpanProvider.class); TimeSpanProvider mock3 = createNiceMock(TimeSpanProvider.class); TimeSpanProvider mock4 = createNiceMock(TimeSpanProvider.class); TimeSpanProvider mock5 = createNiceMock(TimeSpanProvider.class); expect(mock1.getTimeSpan()).andReturn(span1).anyTimes(); expect(mock2.getTimeSpan()).andReturn(span2).anyTimes(); replay(mock1, mock2); BTreeNode<TimeSpanProvider> node = new BTreeNode<>(); node.getValues().add(mock1); node.getValues().add(mock2); BTreeNode<TimeSpanProvider> subNode = new BTreeNode<>(); subNode.getValues().add(mock3); subNode.getValues().add(mock4); subNode.getValues().add(mock5); node.getSubNodes().add(subNode); assertEquals(3, myTestObject.maxValuesPerNodeInteral(node, 1)); }
@Test public void testMaxValuesPerNodeInteralNull() { assertEquals(0, myTestObject.maxValuesPerNodeInteral(null, 5)); }
@Test public void testMaxValuesPerNodeInteralEmpty() { assertEquals(5, myTestObject.maxValuesPerNodeInteral(new BTreeNode<>(), 5)); }
|
### Question:
GroupByDefaultTreeBuilder implements ActiveGroupByTreeBuilder, AvailableGroupByTreeBuilder { @Override public void initializeForAvailable(Toolbox toolbox) { setToolbox(toolbox); } Set<String> getCategories(); DataGroupController getDataGroupController(); @Override String getGroupByName(); @Override GroupCategorizer getGroupCategorizer(); @Override Comparator<? super DataGroupInfo> getGroupComparator(); @Override Predicate<DataGroupInfo> getDataCategoryFilter(); @Override Predicate<DataGroupInfo> getGroupFilter(); Toolbox getToolbox(); @Override TreeOptions getTreeOptions(); @Override Comparator<? super DataTypeInfo> getTypeComparator(); @Override void initializeForActive(Toolbox toolbox); @Override void initializeForAvailable(Toolbox toolbox); @Override void setGroupComparator(Comparator<? super DataGroupInfo> comp); void setTypeComparator(Comparator<? super DataTypeInfo> comp); boolean isActiveGroupsOnly(); boolean isSubNodesForMultiMemberGroups(); }### Answer:
@Test public void testInitializeForAvailable() { EasyMockSupport support = new EasyMockSupport(); Toolbox toolbox = support.createMock(Toolbox.class); support.replayAll(); GroupByDefaultTreeBuilder builder = new GroupByDefaultTreeBuilder(); builder.initializeForAvailable(toolbox); assertEquals(toolbox, builder.getToolbox()); assertFalse(builder.isActiveGroupsOnly()); assertFalse(builder.isSubNodesForMultiMemberGroups()); support.verifyAll(); }
|
### Question:
BinaryTimeTree { protected TimeSpan enlargeTimeRange(Collection<E> collection, TimeSpan range) { TimeSpan maxRange = range; if (maxRange == null) { maxRange = TimeSpan.get(0, OUR_MAX_TIME); } for (TimeSpanProvider tsp : collection) { if (!maxRange.contains(tsp.getTimeSpan())) { maxRange = maxRange.simpleUnion(tsp.getTimeSpan()); } } return maxRange; } BinaryTimeTree(); BinaryTimeTree(int maxValuesPerNode, int maxDepth); void clear(); int countInRange(TimeSpan range); CountReport countsInBins(TimeSpan overAllRange, int numberOfBins); TIntList countsInRanges(List<TimeSpan> countTimes); List<E> findInRange(TimeSpan range); boolean insert(E tsProvider); boolean insert(List<E> collection); int internalSize(BTreeNode<E> node); int maxValuesPerNodeInteral(BTreeNode<E> node, int maxValues); int queryMaxValuesPerNode(); int size(); }### Answer:
@Test public void testEnlargeTimeRange() { TimeSpan span = new TimeSpanLongLong(10, 20); TimeSpan span1 = new TimeSpanLongLong(0, 8); TimeSpan span2 = new TimeSpanLongLong(26, 50); TimeSpan result = myTestObject.enlargeTimeRange(Arrays.asList(span1, span2), span); assertEquals(0, result.getStart()); assertEquals(50, result.getEnd()); }
|
### Question:
BinaryTimeTree { protected void nodeClear(BTreeNode<E> node) { if (node == null) { return; } if (node.getSubNodes() != null) { for (BTreeNode<E> subNode : node.getSubNodes()) { if (subNode != null) { nodeClear(subNode); } } node.getSubNodes().clear(); } if (node.getValues() != null) { node.getValues().clear(); } } BinaryTimeTree(); BinaryTimeTree(int maxValuesPerNode, int maxDepth); void clear(); int countInRange(TimeSpan range); CountReport countsInBins(TimeSpan overAllRange, int numberOfBins); TIntList countsInRanges(List<TimeSpan> countTimes); List<E> findInRange(TimeSpan range); boolean insert(E tsProvider); boolean insert(List<E> collection); int internalSize(BTreeNode<E> node); int maxValuesPerNodeInteral(BTreeNode<E> node, int maxValues); int queryMaxValuesPerNode(); int size(); }### Answer:
@Test public void testNodeClearWithSubnodes() { BTreeNode<TimeSpanProvider> node = new BTreeNode<>(); BTreeNode<TimeSpanProvider> subNode1 = new BTreeNode<>(); BTreeNode<TimeSpanProvider> subNode2 = new BTreeNode<>(); BTreeNode<TimeSpanProvider> subNode3 = new BTreeNode<>(); BTreeNode<TimeSpanProvider> subNode4 = new BTreeNode<>(); BTreeNode<TimeSpanProvider> subNode5 = new BTreeNode<>(); subNode1.getValues().add(createMock(TimeSpanProvider.class)); subNode1.getValues().add(createMock(TimeSpanProvider.class)); subNode2.getValues().add(createMock(TimeSpanProvider.class)); subNode2.getValues().add(createMock(TimeSpanProvider.class)); subNode2.getValues().add(createMock(TimeSpanProvider.class)); subNode3.getValues().add(createMock(TimeSpanProvider.class)); subNode3.getValues().add(createMock(TimeSpanProvider.class)); subNode5.setValues(null); node.setSubNodes(new ArrayList<>(Arrays.asList(subNode1, subNode2, subNode3, subNode4, subNode5))); node.setValues(new ArrayList<>(Arrays.asList(createMock(TimeSpanProvider.class), createMock(TimeSpanProvider.class)))); myTestObject.nodeClear(node); assertTrue(node.getValues().isEmpty()); assertTrue(node.getSubNodes().isEmpty()); }
@Test public void testNodeClearWithNullValues() { BTreeNode<TimeSpanProvider> node = new BTreeNode<>(); node.setValues(null); node.setSubNodes(null); myTestObject.nodeClear(node); assertNull(node.getValues()); assertNull(node.getSubNodes()); }
@Test public void testNodeClearNull() { myTestObject.nodeClear(null); }
|
### Question:
BinaryTimeTree { protected void subDivide(List<E> collection, BTreeNode<E> node) { node.setRange(enlargeTimeRange(collection, node.getRange())); if (collection.size() > myMaxValuesPerNode && node.getLevel() < myMaxDepth) { int mid = collection.size() / 2; List<E> leftCol = new ArrayList<>(); leftCol.addAll(collection.subList(0, mid)); List<E> rightCol = new ArrayList<>(); rightCol.addAll(collection.subList(mid, collection.size())); BTreeNode<E> newNode = new BTreeNode<>(); newNode.setLevel(node.getLevel() + 1); node.getSubNodes().add(newNode); newNode = new BTreeNode<>(); newNode.setLevel(node.getLevel() + 1); node.getSubNodes().add(newNode); BTreeNode<E> leftNode = node.getSubNodes().get(0); BTreeNode<E> rightNode = node.getSubNodes().get(1); subDivide(leftCol, leftNode); subDivide(rightCol, rightNode); } else { node.setValues(collection); } } BinaryTimeTree(); BinaryTimeTree(int maxValuesPerNode, int maxDepth); void clear(); int countInRange(TimeSpan range); CountReport countsInBins(TimeSpan overAllRange, int numberOfBins); TIntList countsInRanges(List<TimeSpan> countTimes); List<E> findInRange(TimeSpan range); boolean insert(E tsProvider); boolean insert(List<E> collection); int internalSize(BTreeNode<E> node); int maxValuesPerNodeInteral(BTreeNode<E> node, int maxValues); int queryMaxValuesPerNode(); int size(); }### Answer:
@Test public void testSubDivide() { myTestObject = new BinaryTimeTree<>(1, 1); BTreeNode<TimeSpanProvider> node = new BTreeNode<>(); BTreeNode<TimeSpanProvider> subNode1 = new BTreeNode<>(); BTreeNode<TimeSpanProvider> subNode2 = new BTreeNode<>(); BTreeNode<TimeSpanProvider> subNode3 = new BTreeNode<>(); BTreeNode<TimeSpanProvider> subNode4 = new BTreeNode<>(); BTreeNode<TimeSpanProvider> subNode5 = new BTreeNode<>(); subNode1.getValues().add(createMock(TimeSpanProvider.class)); subNode1.getValues().add(createMock(TimeSpanProvider.class)); subNode2.getValues().add(createMock(TimeSpanProvider.class)); subNode2.getValues().add(createMock(TimeSpanProvider.class)); subNode2.getValues().add(createMock(TimeSpanProvider.class)); subNode3.getValues().add(createMock(TimeSpanProvider.class)); subNode3.getValues().add(createMock(TimeSpanProvider.class)); node.setSubNodes(new ArrayList<>(Arrays.asList(subNode1, subNode2, subNode3, subNode4, subNode5))); node.setRange(new TimeSpanLongLong(0, 1000)); TimeSpanProvider provider1 = createMock(TimeSpanProvider.class); TimeSpanProvider provider2 = createMock(TimeSpanProvider.class); TimeSpanLongLong span1 = new TimeSpanLongLong(10, 20); expect(provider1.getTimeSpan()).andReturn(span1).anyTimes(); TimeSpanLongLong span2 = new TimeSpanLongLong(20, 200); expect(provider2.getTimeSpan()).andReturn(span2).anyTimes(); replay(provider1, provider2); List<TimeSpanProvider> values = new ArrayList<>(Arrays.asList(provider1, provider2)); node.setValues(values); myTestObject.subDivide(values, node); assertEquals(7, node.getSubNodes().size()); }
|
### Question:
TimeSpanList extends AbstractList<TimeSpan> implements Serializable { public abstract TimeSpanList clone(Collection<? extends TimeSpan> spans); static TimeSpanList emptyList(); static void mergeOverlaps(final List<TimeSpan> list); static void mergeOverlaps(final List<TimeSpan> list, boolean mergeTouching); static TimeSpanList singleton(TimeSpan obj); abstract TimeSpanList clone(Collection<? extends TimeSpan> spans); boolean covers(TimeSpan other); boolean covers(TimeSpanList other); TimeSpan getExtent(); abstract TimeSpanList intersection(TimeSpan ts); abstract TimeSpanList intersection(TimeSpanList other); boolean intersects(TimeSpan timeSpan); abstract TimeSpanList union(TimeSpan ts); abstract TimeSpanList union(TimeSpanList other); static final TimeSpanList TIMELESS; }### Answer:
@Test public void testClone() { final TimeSpan ts1 = TimeSpan.get(8L, 20L); TimeSpanList singleton = TimeSpanList.singleton(ts1); List<TimeSpan> tsList = new ArrayList<>(); tsList.add(TimeSpan.get(10L, 20L)); tsList.add(TimeSpan.get(30L, 40L)); tsList.add(TimeSpan.get(50L, 60L)); TimeSpanList clone1 = singleton.clone(tsList); Assert.assertEquals(tsList.size(), clone1.size()); Assert.assertTrue(clone1.containsAll(tsList)); testImmutable(clone1); TimeSpanList emptyList = TimeSpanList.emptyList(); TimeSpanList clone2 = emptyList.clone(tsList); Assert.assertEquals(tsList.size(), clone2.size()); Assert.assertTrue(clone2.containsAll(tsList)); testImmutable(clone2); }
|
### Question:
TimeSpanList extends AbstractList<TimeSpan> implements Serializable { public static TimeSpanList emptyList() { return EMPTY_LIST; } static TimeSpanList emptyList(); static void mergeOverlaps(final List<TimeSpan> list); static void mergeOverlaps(final List<TimeSpan> list, boolean mergeTouching); static TimeSpanList singleton(TimeSpan obj); abstract TimeSpanList clone(Collection<? extends TimeSpan> spans); boolean covers(TimeSpan other); boolean covers(TimeSpanList other); TimeSpan getExtent(); abstract TimeSpanList intersection(TimeSpan ts); abstract TimeSpanList intersection(TimeSpanList other); boolean intersects(TimeSpan timeSpan); abstract TimeSpanList union(TimeSpan ts); abstract TimeSpanList union(TimeSpanList other); static final TimeSpanList TIMELESS; }### Answer:
@Test public void testEmptyList() { TimeSpanList emptyList = TimeSpanList.emptyList(); Assert.assertTrue(emptyList.isEmpty()); testImmutable(emptyList); Assert.assertSame(TimeSpan.ZERO, emptyList.getExtent()); }
|
### Question:
TimeSpanList extends AbstractList<TimeSpan> implements Serializable { public TimeSpan getExtent() { if (isEmpty()) { return TimeSpan.ZERO; } else if (size() == 1) { return get(0); } else { long minTime = Long.MAX_VALUE; long maxTime = Long.MIN_VALUE; for (int index = 0; index < size(); ++index) { if (get(index).getStart() < minTime) { minTime = get(index).getStart(); } if (get(index).getEnd() > maxTime) { maxTime = get(index).getEnd(); } } return TimeSpan.get(minTime, maxTime); } } static TimeSpanList emptyList(); static void mergeOverlaps(final List<TimeSpan> list); static void mergeOverlaps(final List<TimeSpan> list, boolean mergeTouching); static TimeSpanList singleton(TimeSpan obj); abstract TimeSpanList clone(Collection<? extends TimeSpan> spans); boolean covers(TimeSpan other); boolean covers(TimeSpanList other); TimeSpan getExtent(); abstract TimeSpanList intersection(TimeSpan ts); abstract TimeSpanList intersection(TimeSpanList other); boolean intersects(TimeSpan timeSpan); abstract TimeSpanList union(TimeSpan ts); abstract TimeSpanList union(TimeSpanList other); static final TimeSpanList TIMELESS; }### Answer:
@Test public void testGetExtent() { final TimeSpan ts0 = TimeSpan.get(8L, 20L); final TimeSpan ts1 = TimeSpan.get(4L, 6L); final TimeSpan ts2 = TimeSpan.get(2L, 2L); TimeSpanList list = new TimeSpanList() { private static final long serialVersionUID = 1L; @Override public TimeSpanList clone(Collection<? extends TimeSpan> spans) { throw new UnsupportedOperationException(); } @Override public TimeSpan get(int index) { switch (index) { case 0: return ts0; case 1: return ts1; case 2: return ts2; default: throw new IllegalArgumentException(); } } @Override public TimeSpanList intersection(TimeSpan ts) { throw new UnsupportedOperationException(); } @Override public TimeSpanList intersection(TimeSpanList other) { throw new UnsupportedOperationException(); } @Override public int size() { return 3; } @Override public TimeSpanList union(TimeSpan ts) { throw new UnsupportedOperationException(); } @Override public TimeSpanList union(TimeSpanList other) { throw new UnsupportedOperationException(); } }; Assert.assertEquals(TimeSpan.get(2L, 20L), list.getExtent()); }
|
### Question:
TimeSpanList extends AbstractList<TimeSpan> implements Serializable { public static void mergeOverlaps(final List<TimeSpan> list) { mergeOverlaps(list, false); } static TimeSpanList emptyList(); static void mergeOverlaps(final List<TimeSpan> list); static void mergeOverlaps(final List<TimeSpan> list, boolean mergeTouching); static TimeSpanList singleton(TimeSpan obj); abstract TimeSpanList clone(Collection<? extends TimeSpan> spans); boolean covers(TimeSpan other); boolean covers(TimeSpanList other); TimeSpan getExtent(); abstract TimeSpanList intersection(TimeSpan ts); abstract TimeSpanList intersection(TimeSpanList other); boolean intersects(TimeSpan timeSpan); abstract TimeSpanList union(TimeSpan ts); abstract TimeSpanList union(TimeSpanList other); static final TimeSpanList TIMELESS; }### Answer:
@Test public void testMergeOverlaps() { final TimeSpan ts0 = TimeSpan.get(8L, 20L); final TimeSpan ts1 = TimeSpan.get(1L, 6L); final TimeSpan ts2 = TimeSpan.get(2L, 2L); final TimeSpan ts3 = TimeSpan.get(19L, 25L); final TimeSpan ts4 = TimeSpan.get(24L, 26L); List<TimeSpan> list = new ArrayList<>(); list.add(ts0); list.add(ts1); list.add(ts2); list.add(ts3); list.add(ts4); TimeSpanList.mergeOverlaps(list); Assert.assertEquals(2, list.size()); Assert.assertEquals(TimeSpan.get(8L, 26L), list.get(0)); Assert.assertEquals(TimeSpan.get(1L, 6L), list.get(1)); }
|
### Question:
GroupByTypeTreeBuilder extends GroupByDefaultTreeBuilder { @Override public String getGroupByName() { return "Type"; } @Override String getGroupByName(); @Override GroupCategorizer getGroupCategorizer(); }### Answer:
@Test public void testGetGroupByName() { GroupByTypeTreeBuilder builder = new GroupByTypeTreeBuilder(); assertEquals("Type", builder.getGroupByName()); }
|
### Question:
TimeSpanList extends AbstractList<TimeSpan> implements Serializable { public abstract TimeSpanList intersection(TimeSpan ts); static TimeSpanList emptyList(); static void mergeOverlaps(final List<TimeSpan> list); static void mergeOverlaps(final List<TimeSpan> list, boolean mergeTouching); static TimeSpanList singleton(TimeSpan obj); abstract TimeSpanList clone(Collection<? extends TimeSpan> spans); boolean covers(TimeSpan other); boolean covers(TimeSpanList other); TimeSpan getExtent(); abstract TimeSpanList intersection(TimeSpan ts); abstract TimeSpanList intersection(TimeSpanList other); boolean intersects(TimeSpan timeSpan); abstract TimeSpanList union(TimeSpan ts); abstract TimeSpanList union(TimeSpanList other); static final TimeSpanList TIMELESS; }### Answer:
@Test public void testSingleTimeSpanIntersection() { List<TimeSpan> tsList = new ArrayList<>(); tsList.add(TimeSpan.get(10L, 20L)); tsList.add(TimeSpan.get(30L, 40L)); tsList.add(TimeSpan.get(50L, 60L)); TimeSpanArrayList tsl = new TimeSpanArrayList(tsList); TimeSpan overlapTS = TimeSpan.get(15, 55); TimeSpanList result = tsl.intersection(overlapTS); Assert.assertEquals(result.size(), 3); Assert.assertEquals(result.get(0), TimeSpan.get(15L, 20L)); Assert.assertEquals(result.get(1), TimeSpan.get(30L, 40L)); Assert.assertEquals(result.get(2), TimeSpan.get(50L, 55L)); result = tsl.intersection(TimeSpan.get(1L, 2L)); Assert.assertEquals(result.size(), 0); }
@Test public void testTimeSpanListIntersection() { List<TimeSpan> tsList1 = new ArrayList<>(); tsList1.add(TimeSpan.get(10L, 20L)); tsList1.add(TimeSpan.get(30L, 40L)); tsList1.add(TimeSpan.get(50L, 60L)); List<TimeSpan> tsList2 = new ArrayList<>(); tsList2.add(TimeSpan.get(32L, 35L)); tsList2.add(TimeSpan.get(39L, 44L)); tsList2.add(TimeSpan.get(47L, 80L)); TimeSpanArrayList tsl1 = new TimeSpanArrayList(tsList1); TimeSpanArrayList tsl2 = new TimeSpanArrayList(tsList2); TimeSpanList result = tsl1.intersection(tsl2); Assert.assertEquals(result.size(), 3); Assert.assertEquals(result.get(0), TimeSpan.get(32L, 35L)); Assert.assertEquals(result.get(1), TimeSpan.get(39L, 40L)); Assert.assertEquals(result.get(2), TimeSpan.get(50L, 60L)); }
|
### Question:
TimeSpanList extends AbstractList<TimeSpan> implements Serializable { public static TimeSpanList singleton(TimeSpan obj) { return new SingletonList(obj); } static TimeSpanList emptyList(); static void mergeOverlaps(final List<TimeSpan> list); static void mergeOverlaps(final List<TimeSpan> list, boolean mergeTouching); static TimeSpanList singleton(TimeSpan obj); abstract TimeSpanList clone(Collection<? extends TimeSpan> spans); boolean covers(TimeSpan other); boolean covers(TimeSpanList other); TimeSpan getExtent(); abstract TimeSpanList intersection(TimeSpan ts); abstract TimeSpanList intersection(TimeSpanList other); boolean intersects(TimeSpan timeSpan); abstract TimeSpanList union(TimeSpan ts); abstract TimeSpanList union(TimeSpanList other); static final TimeSpanList TIMELESS; }### Answer:
@Test public void testSingleton() { final TimeSpan ts = TimeSpan.get(8L, 20L); TimeSpanList singleton = TimeSpanList.singleton(ts); Assert.assertEquals(1, singleton.size()); Assert.assertSame(ts, singleton.get(0)); testImmutable(singleton); Assert.assertSame(ts, singleton.getExtent()); }
|
### Question:
GroupByActiveZOrderTreeBuilder extends GroupByDefaultTreeBuilder { @Override public String getGroupByName() { return "Z-Order"; } @Override String getGroupByName(); @Override GroupCategorizer getGroupCategorizer(); @Override Comparator<? super DataGroupInfo> getGroupComparator(); @Override TreeOptions getTreeOptions(); @Override Comparator<? super DataTypeInfo> getTypeComparator(); }### Answer:
@Test public void testGetGroupByName() { GroupByActiveZOrderTreeBuilder builder = new GroupByActiveZOrderTreeBuilder(); assertEquals("Z-Order", builder.getGroupByName()); }
|
### Question:
TimeSpanArrayList extends TimeSpanList implements RandomAccess { @Override public TimeSpanList clone(Collection<? extends TimeSpan> spans) { return new TimeSpanArrayList(spans); } TimeSpanArrayList(Collection<? extends TimeSpan> timeSpans); @Override TimeSpanList clone(Collection<? extends TimeSpan> spans); @Override TimeSpan get(int index); List<TimeSpan> getTimeSpans(); @Override TimeSpanList intersection(TimeSpan ts); @Override TimeSpanList intersection(TimeSpanList other); @Override int size(); @Override TimeSpanList union(TimeSpan ts); @Override TimeSpanList union(TimeSpanList other); }### Answer:
@Test public void testClone() { List<TimeSpan> list1 = new ArrayList<>(); list1.add(TimeSpan.get(1L, 4L)); list1.add(TimeSpan.get(5L, 7L)); list1.add(TimeSpan.get(9L, 11L)); TimeSpanList tsList = new TimeSpanArrayList(list1); List<TimeSpan> list2 = new ArrayList<>(list1); list2.add(TimeSpan.get(3L, 6L)); list2.add(TimeSpan.get(10L, 12L)); TimeSpanList clone = tsList.clone(list2); List<TimeSpan> expected = new ArrayList<>(); expected.add(TimeSpan.get(1L, 7L)); expected.add(TimeSpan.get(9L, 12L)); Assert.assertEquals(list1.size(), tsList.size()); Assert.assertTrue(tsList.containsAll(list1)); Assert.assertEquals(expected.size(), clone.size()); Assert.assertTrue(clone.containsAll(expected)); }
|
### Question:
ModuleStateManagerImpl implements ModuleStateManager { @Override public void deactivateAllStates() { Collection<? extends String> activeStateIds; synchronized (myActiveStates) { activeStateIds = getActiveStateIds(); myActiveStates.clear(); } for (String stateId : activeStateIds) { StateDataExtended data; synchronized (myStateMap) { data = myStateMap.get(stateId); } if (data != null) { deactivateStates(data); } } saveToPreferences(); } ModuleStateManagerImpl(PreferencesRegistry preferencesRegistry); @Override void deactivateAllStates(); @Override Collection<String> detectModules(Node node); @Override Collection<String> detectModules(StateType state); @Override Collection<? extends String> getActiveStateIds(); @Override Collection<? extends String> getModuleNames(); @Override Collection<? extends String> getModulesThatCanSaveState(); @Override Collection<? extends String> getModulesThatSaveStateByDefault(); @Override Collection<String> getRegisteredStateIds(); @Override StateType getState(String state); @Override Map<String, Collection<? extends String>> getStateDependenciesForModules(Collection<? extends String> modules); @Override String getStateDescription(String state); @Override Collection<? extends String> getStateTags(String state); @Override boolean isStateActive(String state); @Override void registerModuleStateController(String moduleName, ModuleStateController controller); @Override void registerState(String id, String description, Collection<? extends String> tags,
Collection<? extends String> modules, Element element); @Override void registerState(String id, String description, Collection<? extends String> tags,
Collection<? extends String> modules, StateType state); @Override void saveState(String id, String description, Collection<? extends String> tags, Collection<? extends String> modules,
Node parentNode); @Override void saveState(String id, String description, Collection<? extends String> tags, Collection<? extends String> modules,
StateType state); @Override void toggleState(String id); @Override void unregisterModuleStateController(String moduleName, ModuleStateController controller); @Override void unregisterState(String id); }### Answer:
@Test public void testDeactivateAllStates() throws InterruptedException { ModuleStateManager manager = new ModuleStateManagerImpl(null); ModuleStateController one = EasyMock.createNiceMock(ModuleStateController.class); ModuleStateController two = EasyMock.createNiceMock(ModuleStateController.class); ModuleStateController three1 = EasyMock.createNiceMock(ModuleStateController.class); ModuleStateController three2 = EasyMock.createNiceMock(ModuleStateController.class); Element node = EasyMock.createMock(Element.class); one.activateState(EasyMock.eq(STATEID), EasyMock.eq(DESCRIPTION), EasyMockHelper.eq(TAGS), EasyMock.eq(node)); three1.activateState(EasyMock.eq(STATEID), EasyMock.eq(DESCRIPTION), EasyMockHelper.eq(TAGS), EasyMock.eq(node)); three2.activateState(EasyMock.eq(STATEID), EasyMock.eq(DESCRIPTION), EasyMockHelper.eq(TAGS), EasyMock.eq(node)); EasyMock.replay(one, two, three1, three2, node); manager.registerModuleStateController(ONE, one); manager.registerModuleStateController(TWO, two); manager.registerModuleStateController(THREE, three1); manager.registerModuleStateController(THREE, three2); manager.registerState(STATEID, DESCRIPTION, TAGS, Arrays.asList(ONE, THREE), node); manager.toggleState(STATEID); EasyMock.verify(one, two, three1, three2, node); Assert.assertTrue(manager.isStateActive(STATEID)); Assert.assertTrue(manager.getActiveStateIds().size() == 1 && manager.getActiveStateIds().contains(STATEID)); EasyMock.reset(one, two, three1, three2); one.deactivateState(STATEID, node); three1.deactivateState(STATEID, node); three2.deactivateState(STATEID, node); EasyMock.replay(one, two, three1, three2); manager.deactivateAllStates(); EasyMock.verify(one, two, three1, three2, node); Assert.assertFalse(manager.isStateActive(STATEID)); Assert.assertTrue(manager.getActiveStateIds().isEmpty()); }
|
### Question:
ModuleStateManagerImpl implements ModuleStateManager { @Override public Collection<String> detectModules(Node node) { Collection<String> moduleNames = New.set(); synchronized (myControllerMap) { for (Entry<String, List<Reference<ModuleStateController>>> entry : myControllerMap.entrySet()) { for (Reference<ModuleStateController> ref : entry.getValue()) { ModuleStateController moduleStateController = ref.get(); if (moduleStateController != null && moduleStateController.canActivateState(node) && !moduleStateController.isAlwaysActivateState()) { moduleNames.add(entry.getKey()); } } } } return moduleNames; } ModuleStateManagerImpl(PreferencesRegistry preferencesRegistry); @Override void deactivateAllStates(); @Override Collection<String> detectModules(Node node); @Override Collection<String> detectModules(StateType state); @Override Collection<? extends String> getActiveStateIds(); @Override Collection<? extends String> getModuleNames(); @Override Collection<? extends String> getModulesThatCanSaveState(); @Override Collection<? extends String> getModulesThatSaveStateByDefault(); @Override Collection<String> getRegisteredStateIds(); @Override StateType getState(String state); @Override Map<String, Collection<? extends String>> getStateDependenciesForModules(Collection<? extends String> modules); @Override String getStateDescription(String state); @Override Collection<? extends String> getStateTags(String state); @Override boolean isStateActive(String state); @Override void registerModuleStateController(String moduleName, ModuleStateController controller); @Override void registerState(String id, String description, Collection<? extends String> tags,
Collection<? extends String> modules, Element element); @Override void registerState(String id, String description, Collection<? extends String> tags,
Collection<? extends String> modules, StateType state); @Override void saveState(String id, String description, Collection<? extends String> tags, Collection<? extends String> modules,
Node parentNode); @Override void saveState(String id, String description, Collection<? extends String> tags, Collection<? extends String> modules,
StateType state); @Override void toggleState(String id); @Override void unregisterModuleStateController(String moduleName, ModuleStateController controller); @Override void unregisterState(String id); }### Answer:
@Test public void testDetectModules() { Node node = EasyMock.createMock(Node.class); ModuleStateController controller1 = EasyMock.createNiceMock(ModuleStateController.class); EasyMock.expect(Boolean.valueOf(controller1.canActivateState(node))).andReturn(Boolean.TRUE).atLeastOnce(); ModuleStateController controller2 = EasyMock.createNiceMock(ModuleStateController.class); EasyMock.expect(Boolean.valueOf(controller2.canActivateState(node))).andReturn(Boolean.FALSE).atLeastOnce(); ModuleStateController controller3a = EasyMock.createNiceMock(ModuleStateController.class); EasyMock.expect(Boolean.valueOf(controller3a.canActivateState(node))).andReturn(Boolean.TRUE).atLeastOnce(); ModuleStateController controller3b = EasyMock.createNiceMock(ModuleStateController.class); EasyMock.expect(Boolean.valueOf(controller3b.canActivateState(node))).andReturn(Boolean.FALSE).atLeastOnce(); EasyMock.replay(node, controller1, controller2, controller3a, controller3b); ModuleStateManager manager = new ModuleStateManagerImpl((PreferencesRegistry)null); Collection<? extends String> moduleNames; moduleNames = manager.detectModules(node); Assert.assertTrue(moduleNames.isEmpty()); manager.registerModuleStateController(TWO, controller2); moduleNames = manager.detectModules(node); Assert.assertTrue(moduleNames.isEmpty()); manager.registerModuleStateController(ONE, controller1); moduleNames = manager.detectModules(node); Assert.assertEquals(1, moduleNames.size()); Assert.assertTrue(moduleNames.contains(ONE)); manager.registerModuleStateController(THREE, controller3a); manager.registerModuleStateController(THREE, controller3b); moduleNames = manager.detectModules(node); Assert.assertEquals(2, moduleNames.size()); Assert.assertTrue(moduleNames.contains(ONE)); Assert.assertTrue(moduleNames.contains(THREE)); EasyMock.verify(node, controller1, controller2, controller3a, controller3b); }
|
### Question:
ColumnLabels extends Observable implements Serializable { public ObservableList<ColumnLabel> getColumnsInLabel() { return myColumnsInLabel; } ObservableList<ColumnLabel> getColumnsInLabel(); boolean isAlwaysShowLabels(); void setAlwaysShowLabels(boolean alwaysShowLabels); void copyFrom(ColumnLabels other); @Override int hashCode(); @Override boolean equals(Object obj); static final String ALWAYS_SHOW_LABELS_PROP; }### Answer:
@Test public void testSerializeEmpty() throws IOException, ClassNotFoundException { EasyMockSupport support = new EasyMockSupport(); @SuppressWarnings("unchecked") ListDataListener<ColumnLabel> listener = support.createMock(ListDataListener.class); support.replayAll(); ColumnLabels model = new ColumnLabels(); ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream objectOut = new ObjectOutputStream(out); objectOut.writeObject(model); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); ObjectInputStream objectIn = new ObjectInputStream(in); ColumnLabels actual = (ColumnLabels)objectIn.readObject(); actual.getColumnsInLabel().addChangeListener(listener); support.verifyAll(); }
|
### Question:
ModuleStateManagerImpl implements ModuleStateManager { @Override public Collection<? extends String> getModulesThatCanSaveState() { Collection<String> moduleNames = New.set(); synchronized (myControllerMap) { for (Entry<String, List<Reference<ModuleStateController>>> entry : myControllerMap.entrySet()) { for (Reference<ModuleStateController> ref : entry.getValue()) { ModuleStateController moduleStateController = ref.get(); if (moduleStateController != null && moduleStateController.canSaveState() && !moduleStateController.isAlwaysSaveState()) { moduleNames.add(entry.getKey()); } } } } return moduleNames; } ModuleStateManagerImpl(PreferencesRegistry preferencesRegistry); @Override void deactivateAllStates(); @Override Collection<String> detectModules(Node node); @Override Collection<String> detectModules(StateType state); @Override Collection<? extends String> getActiveStateIds(); @Override Collection<? extends String> getModuleNames(); @Override Collection<? extends String> getModulesThatCanSaveState(); @Override Collection<? extends String> getModulesThatSaveStateByDefault(); @Override Collection<String> getRegisteredStateIds(); @Override StateType getState(String state); @Override Map<String, Collection<? extends String>> getStateDependenciesForModules(Collection<? extends String> modules); @Override String getStateDescription(String state); @Override Collection<? extends String> getStateTags(String state); @Override boolean isStateActive(String state); @Override void registerModuleStateController(String moduleName, ModuleStateController controller); @Override void registerState(String id, String description, Collection<? extends String> tags,
Collection<? extends String> modules, Element element); @Override void registerState(String id, String description, Collection<? extends String> tags,
Collection<? extends String> modules, StateType state); @Override void saveState(String id, String description, Collection<? extends String> tags, Collection<? extends String> modules,
Node parentNode); @Override void saveState(String id, String description, Collection<? extends String> tags, Collection<? extends String> modules,
StateType state); @Override void toggleState(String id); @Override void unregisterModuleStateController(String moduleName, ModuleStateController controller); @Override void unregisterState(String id); }### Answer:
@Test public void testGetModulesThatCanSaveState() { ModuleStateManager manager = new ModuleStateManagerImpl(null); ModuleStateController one = EasyMock.createNiceMock(ModuleStateController.class); ModuleStateController two = EasyMock.createNiceMock(ModuleStateController.class); EasyMock.expect(Boolean.valueOf(one.canSaveState())).andReturn(Boolean.TRUE); EasyMock.expect(Boolean.valueOf(two.canSaveState())).andReturn(Boolean.FALSE); EasyMock.replay(one, two); manager.registerModuleStateController(ONE, one); manager.registerModuleStateController(TWO, two); Collection<? extends String> names; names = manager.getModulesThatCanSaveState(); Assert.assertTrue(names.size() == 1 && names.contains(ONE)); EasyMock.verify(one, two); EasyMock.reset(one, two); EasyMock.expect(Boolean.valueOf(one.canSaveState())).andReturn(Boolean.FALSE); EasyMock.expect(Boolean.valueOf(two.canSaveState())).andReturn(Boolean.TRUE); EasyMock.replay(one, two); names = manager.getModulesThatCanSaveState(); Assert.assertTrue(names.size() == 1 && names.contains(TWO)); EasyMock.verify(one, two); EasyMock.reset(one, two); EasyMock.expect(Boolean.valueOf(one.canSaveState())).andReturn(Boolean.TRUE); EasyMock.expect(Boolean.valueOf(two.canSaveState())).andReturn(Boolean.TRUE); EasyMock.replay(one, two); names = manager.getModulesThatCanSaveState(); Assert.assertTrue(names.size() == 2 && names.containsAll(Arrays.asList(ONE, TWO))); EasyMock.verify(one, two); }
|
### Question:
ModuleStateManagerImpl implements ModuleStateManager { @Override public Collection<? extends String> getModulesThatSaveStateByDefault() { Collection<String> moduleNames = New.set(); synchronized (myControllerMap) { for (Entry<String, List<Reference<ModuleStateController>>> entry : myControllerMap.entrySet()) { for (Reference<ModuleStateController> ref : entry.getValue()) { ModuleStateController moduleStateController = ref.get(); if (moduleStateController != null && moduleStateController.isSaveStateByDefault()) { moduleNames.add(entry.getKey()); } } } } return moduleNames; } ModuleStateManagerImpl(PreferencesRegistry preferencesRegistry); @Override void deactivateAllStates(); @Override Collection<String> detectModules(Node node); @Override Collection<String> detectModules(StateType state); @Override Collection<? extends String> getActiveStateIds(); @Override Collection<? extends String> getModuleNames(); @Override Collection<? extends String> getModulesThatCanSaveState(); @Override Collection<? extends String> getModulesThatSaveStateByDefault(); @Override Collection<String> getRegisteredStateIds(); @Override StateType getState(String state); @Override Map<String, Collection<? extends String>> getStateDependenciesForModules(Collection<? extends String> modules); @Override String getStateDescription(String state); @Override Collection<? extends String> getStateTags(String state); @Override boolean isStateActive(String state); @Override void registerModuleStateController(String moduleName, ModuleStateController controller); @Override void registerState(String id, String description, Collection<? extends String> tags,
Collection<? extends String> modules, Element element); @Override void registerState(String id, String description, Collection<? extends String> tags,
Collection<? extends String> modules, StateType state); @Override void saveState(String id, String description, Collection<? extends String> tags, Collection<? extends String> modules,
Node parentNode); @Override void saveState(String id, String description, Collection<? extends String> tags, Collection<? extends String> modules,
StateType state); @Override void toggleState(String id); @Override void unregisterModuleStateController(String moduleName, ModuleStateController controller); @Override void unregisterState(String id); }### Answer:
@Test public void testGetModulesThatSaveStateByDefault() { ModuleStateManager manager = new ModuleStateManagerImpl(null); ModuleStateController one = EasyMock.createMock(ModuleStateController.class); ModuleStateController two = EasyMock.createMock(ModuleStateController.class); EasyMock.expect(Boolean.valueOf(one.isSaveStateByDefault())).andReturn(Boolean.TRUE); EasyMock.expect(Boolean.valueOf(two.isSaveStateByDefault())).andReturn(Boolean.FALSE); EasyMock.replay(one, two); manager.registerModuleStateController(ONE, one); manager.registerModuleStateController(TWO, two); Collection<? extends String> names; names = manager.getModulesThatSaveStateByDefault(); Assert.assertTrue(names.size() == 1 && names.contains(ONE)); EasyMock.verify(one, two); EasyMock.reset(one, two); EasyMock.expect(Boolean.valueOf(one.isSaveStateByDefault())).andReturn(Boolean.FALSE); EasyMock.expect(Boolean.valueOf(two.isSaveStateByDefault())).andReturn(Boolean.TRUE); EasyMock.replay(one, two); names = manager.getModulesThatSaveStateByDefault(); Assert.assertTrue(names.size() == 1 && names.contains(TWO)); EasyMock.verify(one, two); EasyMock.reset(one, two); EasyMock.expect(Boolean.valueOf(one.isSaveStateByDefault())).andReturn(Boolean.TRUE); EasyMock.expect(Boolean.valueOf(two.isSaveStateByDefault())).andReturn(Boolean.TRUE); EasyMock.replay(one, two); names = manager.getModulesThatSaveStateByDefault(); Assert.assertTrue(names.size() == 2 && names.containsAll(Arrays.asList(ONE, TWO))); EasyMock.verify(one, two); }
|
### Question:
StateXML { public static NodeList getChildNodes(Node rootNode, String xpath) throws XPathExpressionException { return (NodeList)newXPath().evaluate(xpath, rootNode, XPathConstants.NODESET); } private StateXML(); static Node createChildNode(Node rootNode, Document doc, Node parent, String childPath, String childName); static Element createElement(Document doc, String qname); static Node getChildNode(Node rootNode, String childPath); static NodeList getChildNodes(Node rootNode, String xpath); static Node getChildStateNode(Node rootNode, String childPathFragment); static boolean anyMatch(Node rootNode, String xpath); static T getStateBean(Node node, String childPathFragment, Class<T> target); static XPath newXPath(); }### Answer:
@Test public void testGetChildNodes() throws ParserConfigurationException, XPathExpressionException { Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Node parent = doc.appendChild(doc.createElement("parent")); NodeList child = StateXML.getChildNodes(parent, "/parent/child"); assertEquals(0, child.getLength()); Node expectedChild1 = parent.appendChild(doc.createElement("child")); Node expectedChild2 = parent.appendChild(doc.createElement("child")); child = StateXML.getChildNodes(parent, "/parent/child"); assertEquals(2, child.getLength()); assertEquals(expectedChild1, child.item(0)); assertEquals(expectedChild2, child.item(1)); }
|
### Question:
DefaultContinuousAnimationPlan extends DefaultAnimationPlan implements ContinuousAnimationPlan { public DefaultContinuousAnimationPlan(List<? extends TimeSpan> sequence, Duration activeWindowDuration, Duration advanceDuration, EndBehavior endBehavior, TimeSpan limitWindow) { super(sequence, endBehavior); for (TimeSpan timeSpan : sequence) { if (!timeSpan.isBounded()) { throw new IllegalArgumentException("Cannot create " + DefaultContinuousAnimationPlan.class.getSimpleName() + " with an indefinite time span: " + timeSpan); } } myActiveWindowDuration = Utilities.checkNull(activeWindowDuration, "activeWindowDuration"); myAdvanceDuration = Utilities.checkNull(advanceDuration, "advanceDuration"); myLimitWindow = limitWindow == null ? TimeSpan.TIMELESS : limitWindow; setUsingProcessingTimeout(true); } DefaultContinuousAnimationPlan(List<? extends TimeSpan> sequence, Duration activeWindowDuration,
Duration advanceDuration, EndBehavior endBehavior, TimeSpan limitWindow); @Override DefaultAnimationState determineNextState(AnimationState state); DefaultContinuousAnimationState determineNextState(DefaultContinuousAnimationState state); @Override DefaultAnimationState determinePreviousState(AnimationState state); DefaultContinuousAnimationState determinePreviousState(DefaultContinuousAnimationState state); @Override boolean equals(Object obj); @Override @Nullable @SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE") DefaultContinuousAnimationState findState(Date time, Direction direction); @Override @SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE") DefaultContinuousAnimationState findState(TimeSpan span, Direction direction); @Override Duration getActiveWindowDuration(); @Override Duration getAdvanceDuration(); @Override DefaultContinuousAnimationState getFinalState(); @Override AnimationState getFinalState(AnimationState state); AnimationState getFinalState(DefaultContinuousAnimationState state); @Override DefaultContinuousAnimationState getInitialState(); @Override TimeSpan getLimitWindow(); @Override TimeSpan getTimeSpanForState(AnimationState state); @Override int hashCode(); @Override String toString(); }### Answer:
@SuppressWarnings("unused") @Test public void testDefaultContinuousAnimationPlan() { List<? extends TimeSpan> sequence = Arrays.asList(TimeSpan.get(0L, 3600000L)); Duration window = Minutes.ONE; Duration advance = new Seconds(10); EndBehavior endBehavior = EndBehavior.STOP; TimeSpan limit = null; Duration fade = null; new DefaultContinuousAnimationPlan(sequence, window, advance, endBehavior, limit); }
|
### Question:
ColumnLabels extends Observable implements Serializable { public void setAlwaysShowLabels(boolean alwaysShowLabels) { myAlwaysShowLabels = alwaysShowLabels; setChanged(); notifyObservers(ALWAYS_SHOW_LABELS_PROP); } ObservableList<ColumnLabel> getColumnsInLabel(); boolean isAlwaysShowLabels(); void setAlwaysShowLabels(boolean alwaysShowLabels); void copyFrom(ColumnLabels other); @Override int hashCode(); @Override boolean equals(Object obj); static final String ALWAYS_SHOW_LABELS_PROP; }### Answer:
@Test public void testUpdate() { EasyMockSupport support = new EasyMockSupport(); Observer alwaysShow = createObserver(support, ColumnLabels.ALWAYS_SHOW_LABELS_PROP); support.replayAll(); ColumnLabels options = new ColumnLabels(); options.addObserver(alwaysShow); options.setAlwaysShowLabels(true); options.deleteObserver(alwaysShow); support.verifyAll(); }
|
### Question:
ColumnsController implements ListDataListener<ColumnLabel> { public void close() { myModel.getColumnsInLabel().removeChangeListener(this); } ColumnsController(ColumnLabels model, List<String> availableColumns); void close(); @Override void elementsAdded(ListDataEvent<ColumnLabel> e); @Override void elementsChanged(ListDataEvent<ColumnLabel> e); @Override void elementsRemoved(ListDataEvent<ColumnLabel> e); }### Answer:
@Test public void test() { List<String> columns = New.list("Name", "Description"); ColumnLabels model = new ColumnLabels(); ColumnsController controller = new ColumnsController(model, columns); ColumnLabel label1 = new ColumnLabel(); model.getColumnsInLabel().add(label1); assertEquals(columns, label1.getAvailableColumns()); assertEquals(columns.get(0), label1.getColumn()); List<String> otherColumns = New.list("some other"); ColumnLabel prePop = new ColumnLabel(); prePop.getAvailableColumns().addAll(otherColumns); prePop.setColumn(otherColumns.get(0)); model.getColumnsInLabel().add(prePop); assertEquals(otherColumns, prePop.getAvailableColumns()); assertEquals(otherColumns.get(0), prePop.getColumn()); model.getColumnsInLabel().remove(prePop); ColumnLabel label2 = new ColumnLabel(); model.getColumnsInLabel().add(label2); assertEquals(columns, label2.getAvailableColumns()); assertEquals(columns.get(1), label2.getColumn()); ColumnLabel label3 = new ColumnLabel(); model.getColumnsInLabel().add(label3); assertEquals(columns, label2.getAvailableColumns()); assertEquals(columns.get(1), label2.getColumn()); controller.close(); ColumnLabel label4 = new ColumnLabel(); model.getColumnsInLabel().add(label4); assertTrue(label4.getAvailableColumns().isEmpty()); assertNull(label4.getColumn()); }
@Test public void testExisting() { List<String> columns = New.list("Name", "Description"); ColumnLabels model = new ColumnLabels(); ColumnLabel label1 = new ColumnLabel(); label1.setColumn(columns.get(1)); model.getColumnsInLabel().add(label1); ColumnsController controller = new ColumnsController(model, columns); controller.close(); assertEquals(columns, label1.getAvailableColumns()); }
@Test public void testDefaultColumns() { List<String> columns = New.list("Name", "Description", "Lat", "Lon"); ColumnLabels model = new ColumnLabels(); ColumnLabel name = new ColumnLabel(); name.setColumn(columns.get(0)); model.getColumnsInLabel().add(name); ColumnLabel description = new ColumnLabel(); description.setColumn(columns.get(1)); model.getColumnsInLabel().add(description); ColumnsController controller = new ColumnsController(model, columns); ColumnLabel added = new ColumnLabel(); model.getColumnsInLabel().add(added); assertEquals(columns.get(2), added.getColumn()); controller.close(); }
|
### Question:
DefaultContinuousAnimationPlan extends DefaultAnimationPlan implements ContinuousAnimationPlan { @Override public DefaultContinuousAnimationState getInitialState() { DefaultAnimationState initialState = super.getInitialState(); return createStateFromParentState(initialState, true); } DefaultContinuousAnimationPlan(List<? extends TimeSpan> sequence, Duration activeWindowDuration,
Duration advanceDuration, EndBehavior endBehavior, TimeSpan limitWindow); @Override DefaultAnimationState determineNextState(AnimationState state); DefaultContinuousAnimationState determineNextState(DefaultContinuousAnimationState state); @Override DefaultAnimationState determinePreviousState(AnimationState state); DefaultContinuousAnimationState determinePreviousState(DefaultContinuousAnimationState state); @Override boolean equals(Object obj); @Override @Nullable @SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE") DefaultContinuousAnimationState findState(Date time, Direction direction); @Override @SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE") DefaultContinuousAnimationState findState(TimeSpan span, Direction direction); @Override Duration getActiveWindowDuration(); @Override Duration getAdvanceDuration(); @Override DefaultContinuousAnimationState getFinalState(); @Override AnimationState getFinalState(AnimationState state); AnimationState getFinalState(DefaultContinuousAnimationState state); @Override DefaultContinuousAnimationState getInitialState(); @Override TimeSpan getLimitWindow(); @Override TimeSpan getTimeSpanForState(AnimationState state); @Override int hashCode(); @Override String toString(); }### Answer:
@Test public void testGetInitialState() { DefaultContinuousAnimationPlan plan = createPlan(); Assert.assertEquals(new DefaultContinuousAnimationState(0, TimeSpan.get(0L, 60000L), Direction.FORWARD), plan.getInitialState()); }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.