com.google.android.agera.Function.apply()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中com.google.android.agera.Function.apply()方法的一些代码示例,展示了Function.apply()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Function.apply()方法的具体详情如下:
包路径:com.google.android.agera.Function
类名称:Function
方法名:apply

Function.apply介绍

[英]Returns the result of applying this function to input.
[中]返回将此函数应用于输入的结果。

代码示例

代码示例来源:origin: google/agera

@NonNull
 @Override
 public T get() {
  return function.apply(from);
 }
}

代码示例来源:origin: google/agera

@NonNull
 @Override
 @SuppressWarnings("unchecked")
 public Object apply(@NonNull final Object input) {
  Object item = input;
  for (final Function function : functions) {
   item = function.apply(item);
  }
  return item;
 }
}

代码示例来源:origin: google/agera

@Test
public void shouldPassOnRequestHeaders() throws Throwable {
 assertThat(httpFunction().apply(HTTP_GET_REQUEST_WITH_HEADERS), is(notNullValue()));
 verify(mockHttpURLConnection).addRequestProperty("name", "value");
 verify(mockHttpURLConnection).addRequestProperty("name2", "value2");
 verify(mockHttpURLConnection).disconnect();
}

代码示例来源:origin: google/agera

@Test
public void shouldPassOnPostMethod() throws Throwable {
 assertThat(httpFunction()
     .apply(HTTP_POST_REQUEST),
   is(notNullValue()));
 verify(mockHttpURLConnection).setRequestMethod(POST_METHOD);
 verify(mockHttpURLConnection).disconnect();
}

代码示例来源:origin: google/agera

@Test
public void shouldReturnValueOfSucceededFromAppliedFunctionForFlatMapOfSucceeded() {
 assertThat(SUCCESS_WITH_OTHER_VALUE.ifSucceededAttemptMap(mockSucceededValueFunction),
   equalTo(SUCCESS_WITH_VALUE));
 verify(mockSucceededValueFunction).apply(OTHER_VALUE);
}

代码示例来源:origin: google/agera

@Test
public void shouldGetByteArrayFromGetResponse() throws Throwable {
 final ByteArrayInputStream inputStream = new ByteArrayInputStream(RESPONSE_BODY);
 when(mockHttpURLConnection.getInputStream()).thenReturn(inputStream);
 when(mockHttpURLConnection.getContentLength()).thenReturn(RESPONSE_BODY.length);
 assertThat(httpFunction().apply(HTTP_GET_REQUEST).get().getBody(), is(RESPONSE_BODY));
 verify(mockHttpURLConnection).disconnect();
}

代码示例来源:origin: google/agera

@Test
public void shouldReturnRecoverSuccessForAttemptRecoverOfFailure() {
 assertThat(FAILURE_WITH_THROWABLE.attemptRecover(mockAttemptRecoverValueFunction),
   equalTo(SUCCESS_WITH_VALUE));
 verify(mockAttemptRecoverValueFunction).apply(THROWABLE);
}

代码示例来源:origin: google/agera

@Test
public void shouldReturnObjectFromSupplierForSupplierAsFunction() {
 assertThat(supplierAsFunction(mockSupplier).apply(new Object()),
   is(sameInstance(INPUT_STRING)));
}

代码示例来源:origin: google/agera

@Test
public void shouldReturnEmptyListForFilterOfEmptyList() {
 final Predicate<String> predicate = mock(Predicate.class);
 when(predicate.apply(anyString())).thenReturn(true);
 final Function<List<String>, List<String>> function = functionFromListOf(String.class)
   .thenFilter(predicate);
 assertThat(function.apply(new ArrayList<String>()),
   sameInstance(Collections.<String>emptyList()));
}

代码示例来源:origin: google/agera

@Test
public void shouldReturnFromObject() {
 assertThat(Functions.<String>identityFunction().apply(INPUT_STRING),
   is(sameInstance(INPUT_STRING)));
}

代码示例来源:origin: google/agera

@Test
public void shouldProduceFunctionResultIfFunctionSucceeds() {
 when(mockAttemptSupplier.get()).thenReturn(SUPPLIER_FAILED_RESULT);
 when(mockAttemptMerger.merge(SUPPLIER_FAILED_RESULT.getFailure(), SECOND_SUPPLIER.get()))
   .thenReturn(MERGER_FAILED_RESULT);
 when(mockAttemptFunction.apply(MERGER_FAILED_RESULT.getFailure()))
   .thenReturn(FUNCTION_SUCCESSFUL_RESULT);
 updatable.addToObservable(repository);
 assertThat(repository, has(FUNCTION_SUCCESSFUL_RESULT.get()));
 verifyNoMoreInteractions(mockRecoveryFunction);
}

代码示例来源:origin: google/agera

@Test
public void shouldReturnFailureForInvalidDelete() {
 assertThat(databaseDeleteFunction(databaseSupplier)
     .apply(sqlDeleteRequest()
       .table(INVALID_TABLE)
       .compile()).getFailure(),
   instanceOf(SQLException.class));
}

代码示例来源:origin: google/agera

@Test
public void shouldClearTableForDeleteWithoutArguments() throws Throwable {
 assertThat(databaseDeleteFunction(databaseSupplier)
     .apply(sqlDeleteRequest()
       .table(TABLE)
       .compile()).get(),
   is(3));
 assertDatabaseEmpty();
}

代码示例来源:origin: google/agera

@Test
public void shouldReturnFailureForInvalidUpdate() {
 assertThat(databaseUpdateFunction(databaseSupplier)
     .apply(sqlUpdateRequest()
       .table(INVALID_TABLE)
       .emptyColumn("column")
       .compile()).getFailure(),
   instanceOf(SQLException.class));
}

代码示例来源:origin: google/agera

@Test
public void shouldCreateFunctionFromListToItem() {
 final Function<List<String>, Integer> function = functionFromListOf(String.class)
   .limit(3)
   .map(new StringLength())
   .thenApply(new SumOfIntegersInList());
 assertThat(function.apply(INPUT_LIST), is(14));
}

代码示例来源:origin: google/agera

@Test
public void shouldUpdateTableForUpdateWithoutArguments() throws Throwable {
 assertThat(databaseUpdateFunction(databaseSupplier)
     .apply(sqlUpdateRequest()
       .table(TABLE)
       .column("column", "value4")
       .compile()).get(),
   is(3));
}

代码示例来源:origin: google/agera

@Test
public void shouldReturnFailureForInvalidInsert() {
 assertThat(databaseInsertFunction(databaseSupplier)
     .apply(sqlInsertRequest()
       .table(INVALID_TABLE)
       .emptyColumn("column")
       .compile()).getFailure(),
   instanceOf(SQLException.class));
}

代码示例来源:origin: google/agera

@Test
public void shouldCreateFunctionFromListToListWithZeroLimit() {
 final Function<List<String>, List<Integer>> function = functionFromListOf(String.class)
   .limit(0)
   .thenMap(new StringLength());
 assertThat(function.apply(INPUT_LIST), Matchers.<Integer>emptyIterable());
}

代码示例来源:origin: google/agera

@Test
public void shouldReturnErrorForFailedDatabaseCreationInDelete() throws Throwable {
 assertThat(databaseDeleteFunction(FAILURE)
     .apply(sqlDeleteRequest()
       .table(TABLE)
       .where("column=?")
       .arguments("value2")
       .compile()).failed(),
   is(true));
}

代码示例来源:origin: google/agera

@Test
public void shouldReturnErrorForFailedDatabaseCreationInUpdate() throws Throwable {
 assertThat(databaseUpdateFunction(FAILURE)
     .apply(sqlUpdateRequest()
       .table(TABLE)
       .column("column", "value4")
       .where("column=?")
       .arguments("value3")
       .compile()).failed(),
   is(true));
}

相关文章