org.hamcrest.core.AnyOf Java Examples

The following examples show how to use org.hamcrest.core.AnyOf. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BasicCredentialsTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void throwsWhenBothParamsAreNull() {

    // given
    BasicCredentials.Builder builder = createTestBuilder()
            .withUsername(null)
            .withPassword(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(AnyOf.anyOf(
            StringContains.containsString("username"),
            StringContains.containsString("password"))
    );

    // when
    builder.build();

}
 
Example #2
Source File: BasicCredentialsTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void throwsWhenBothParamsAreNull() {

    // given
    BasicCredentials.Builder builder = createTestBuilder()
            .withUsername(null)
            .withPassword(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(AnyOf.anyOf(
            StringContains.containsString("username"),
            StringContains.containsString("password"))
    );

    // when
    builder.build();

}
 
Example #3
Source File: BasicCredentialsTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void throwsWhenBothParamsAreNull() {

    // given
    BasicCredentials.Builder builder = createTestBuilder()
            .withUsername(null)
            .withPassword(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(AnyOf.anyOf(
            StringContains.containsString("username"),
            StringContains.containsString("password"))
    );

    // when
    builder.build();

}
 
Example #4
Source File: BasicCredentialsTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void throwsWhenBothParamsAreNull() {

    // given
    BasicCredentials.Builder builder = createTestBuilder()
            .withUsername(null)
            .withPassword(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(AnyOf.anyOf(
            StringContains.containsString("username"),
            StringContains.containsString("password"))
    );

    // when
    builder.build();

}
 
Example #5
Source File: BasicCredentialsTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void throwsWhenBothParamsAreNull() {

    // given
    BasicCredentials.Builder builder = createTestBuilder()
            .withUsername(null)
            .withPassword(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(AnyOf.anyOf(
            StringContains.containsString("username"),
            StringContains.containsString("password"))
    );

    // when
    builder.build();

}
 
Example #6
Source File: AbstractDiscoverabilityLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenInvalidPOSTIsSentToValidURIOfResource_thenAllowHeaderListsTheAllowedActions() {
    // Given
    final String uriOfExistingResource = createAsUri();

    // When
    final Response res = RestAssured.post(uriOfExistingResource);

    // Then
    final String allowHeader = res.getHeader(HttpHeaders.ALLOW);
    assertThat(allowHeader, AnyOf.anyOf(containsString("GET"), containsString("PUT"), containsString("DELETE")));
}
 
Example #7
Source File: Linker_Tests.java    From cortado with Apache License 2.0 5 votes vote down vote up
@Test
public void or_returns_instanceOf_AnyOf() {
    //given
    List<Matcher<? super View>> matchers = new ArrayList<>();
    Matcher<View> matcher = new SimpleWrappingViewMatcher<>(null);
    matchers.add(matcher);

    //when
    Matcher<? super View> link = OR.link(matchers);

    //then
    assertThat(link).isInstanceOf(AnyOf.class);
}
 
Example #8
Source File: ModeAggregatorTest.java    From mrgeo with Apache License 2.0 5 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testFloat()
{
  float[] values = {0.21f, 0.32f, 0.32f, 0.54f};
  float nodata = -9999.0f;
  float result;
  Aggregator agg = new ModeAggregator();

  //Test normal case
  result = agg.aggregate(values, nodata);
  assertEquals(0.32, result, epsilon);

  //Test nodata cases
  values[0] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(0.32, result, epsilon);

  values[1] = nodata;
  result = agg.aggregate(values, nodata);
  //assertEquals(0.54, result, epsilon);
  assertThat((double) result, AnyOf.anyOf(IsCloseTo.closeTo(0.32f, epsilon), IsCloseTo.closeTo(0.54f, epsilon)));

  values[2] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(0.54, result, epsilon);

  values[3] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(nodata, result, epsilon);

}
 
Example #9
Source File: ModeAggregatorTest.java    From mrgeo with Apache License 2.0 5 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testDouble()
{
  double[] values = {0.21, 0.32, 0.32, 0.54};
  double nodata = Double.NaN;
  double result;
  Aggregator agg = new ModeAggregator();

  //Test normal case
  result = agg.aggregate(values, nodata);
  assertEquals(0.32, result, epsilon);

  //Test nodata cases
  values[0] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(0.32, result, epsilon);

  values[1] = nodata;
  result = agg.aggregate(values, nodata);
  assertThat((double) result, AnyOf.anyOf(IsCloseTo.closeTo(0.32f, epsilon), IsCloseTo.closeTo(0.54f, epsilon)));

  values[2] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(0.54, result, epsilon);

  values[3] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(nodata, result, epsilon);

}
 
Example #10
Source File: RemoteHamcrestCoreMatcher13Test.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Test
public void anyOf_transformationFromProto() {
  Matcher isEqualInteger = new IsEqual<>(5);
  Matcher isEqualInteger2 = new IsEqual<>(3);

  AnyOf<Matcher> anyOfMatcher =
      new AnyOf<Matcher>(Lists.newArrayList(isEqualInteger, isEqualInteger2));
  GenericRemoteMessage anyOfMatcherRemoteMessage = new GenericRemoteMessage(anyOfMatcher);
  AnyOfProto anyOfMatcherMatcherProto = (AnyOfProto) anyOfMatcherRemoteMessage.toProto();
  Matcher<Integer> anyOfMatcherFromProto =
      (Matcher<Integer>) GenericRemoteMessage.FROM.fromProto(anyOfMatcherMatcherProto);

  assertThat(5, anyOfMatcherFromProto);
  assertThat(3, anyOfMatcherFromProto);
}
 
Example #11
Source File: RemoteHamcrestCoreMatcher13Test.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Test
public void anyOf_transformationToProto() {
  Matcher isEqualInteger = new IsEqual<>(5);
  Matcher isEqualInteger2 = new IsEqual<>(3);

  AnyOf<Matcher> anyOfMatcher =
      new AnyOf<Matcher>(Lists.newArrayList(isEqualInteger, isEqualInteger2));
  GenericRemoteMessage anyOfMatcherRemoteMessage = new GenericRemoteMessage(anyOfMatcher);
  AnyOfProto anyOfMatcherMatcherProto = (AnyOfProto) anyOfMatcherRemoteMessage.toProto();

  assertThat(anyOfMatcherMatcherProto.getMatchersCount(), equalTo(2));
  assertThat(anyOfMatcherMatcherProto.getMatchersList(), notNullValue());
}
 
Example #12
Source File: TestFieldMapperProcessorByValue.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private static Field assertAndReturnValues(Record record, AnyOf<Field.Type> valuesTypeMatcher) {
  assertThat(record, notNullValue());
  final Field rootField = record.get();
  assertThat(rootField, notNullValue());
  assertThat(rootField.getType(), TestFieldMapperProcessorByName.IS_A_MAP);
  final Field inputs = rootField.getValueAsMap().get("values");
  assertThat(inputs, notNullValue());
  assertThat(inputs.getType(), valuesTypeMatcher);
  return inputs;
}
 
Example #13
Source File: RemoteHamcrestCoreMatchers13.java    From android-test with Apache License 2.0 4 votes vote down vote up
public static void init(RemoteDescriptorRegistry remoteDescriptorRegistry) {
  remoteDescriptorRegistry.registerRemoteTypeArgs(
      Arrays.asList(
          new RemoteDescriptor.Builder()
              .setInstanceType(IsEqual.class)
              .setInstanceFieldDescriptors(FieldDescriptor.of(Object.class, "expectedValue", 0))
              .setRemoteType(GenericRemoteMessage.class)
              .setRemoteConstrTypes(Object.class)
              .setProtoType(IsEqualProto.class)
              .build(),
          new RemoteDescriptor.Builder()
              .setInstanceType(Is.class)
              .setInstanceFieldDescriptors(FieldDescriptor.of(Matcher.class, "matcher", 0))
              .setRemoteType(GenericRemoteMessage.class)
              .setRemoteConstrTypes(Matcher.class)
              .setProtoType(IsProto.class)
              .build(),
          new RemoteDescriptor.Builder()
              .setInstanceType(AnyOf.class)
              .setInstanceFieldDescriptors(FieldDescriptor.of(Iterable.class, "matchers", 0))
              .setRemoteType(GenericRemoteMessage.class)
              .setRemoteConstrTypes(Iterable.class)
              .setProtoType(AnyOfProto.class)
              .build(),
          new RemoteDescriptor.Builder()
              .setInstanceType(AllOf.class)
              .setInstanceFieldDescriptors(FieldDescriptor.of(Iterable.class, "matchers", 0))
              .setRemoteType(GenericRemoteMessage.class)
              .setRemoteConstrTypes(Iterable.class)
              .setProtoType(AllOfProto.class)
              .build(),
          new RemoteDescriptor.Builder()
              .setInstanceType(IsInstanceOf.class)
              .setInstanceFieldDescriptors(FieldDescriptor.of(Class.class, "expectedClass", 0))
              .setRemoteType(GenericRemoteMessage.class)
              .setRemoteConstrTypes(Class.class)
              .setProtoType(IsInstanceOfProto.class)
              .build(),
          new RemoteDescriptor.Builder()
              .setInstanceType(IsNull.class)
              .setRemoteType(GenericRemoteMessage.class)
              .setRemoteConstrTypes(Class.class)
              .setProtoType(IsNullProto.class)
              .build(),
          new RemoteDescriptor.Builder()
              .setInstanceType(IsNot.class)
              .setInstanceFieldDescriptors(FieldDescriptor.of(Matcher.class, "matcher", 0))
              .setRemoteType(GenericRemoteMessage.class)
              .setRemoteConstrTypes(Class.class)
              .setProtoType(IsNotProto.class)
              .build(),
          new RemoteDescriptor.Builder()
              .setInstanceType(StringContains.class)
              .setInstanceFieldDescriptors(FieldDescriptor.of(String.class, "substring", 0))
              .setRemoteType(GenericRemoteMessage.class)
              .setRemoteConstrTypes(String.class)
              .setProtoType(StringContainsProto.class)
              .build()));
}
 
Example #14
Source File: YearMatcher.java    From lib-recur with Apache License 2.0 4 votes vote down vote up
public static Matcher<DateTime> inYear(Integer... years)
{
    return new YearMatcher(new AnyOf<>(new Mapped<>(Matchers::equalTo, new Seq<>(years))));
}
 
Example #15
Source File: MonthMatcher.java    From lib-recur with Apache License 2.0 4 votes vote down vote up
public static Matcher<DateTime> inMonth(Integer... months)
{
    return new MonthMatcher(new AnyOf<>(new Mapped<>(Matchers::equalTo, new Seq<>(months))));
}
 
Example #16
Source File: WeekOfYearMatcher.java    From lib-recur with Apache License 2.0 4 votes vote down vote up
public static Matcher<DateTime> inWeekOfYear(Integer... weekOfYear)
{
    return new WeekOfYearMatcher(new AnyOf<>(new Mapped<>(Matchers::equalTo, new Seq<>(weekOfYear))));
}
 
Example #17
Source File: DayOfMonthMatcher.java    From lib-recur with Apache License 2.0 4 votes vote down vote up
public static Matcher<DateTime> onDayOfMonth(Integer... days)
{
    return new DayOfMonthMatcher(new AnyOf<>(new Mapped<>(Matchers::equalTo, new Seq<>(days))));
}
 
Example #18
Source File: WeekDayMatcher.java    From lib-recur with Apache License 2.0 4 votes vote down vote up
public static Matcher<DateTime> onWeekDay(Weekday... weekdays)
{
    return new WeekDayMatcher(new AnyOf<>(new Mapped<>(Matchers::equalTo, new Seq<>(weekdays))));
}
 
Example #19
Source File: DayOfYearMatcher.java    From lib-recur with Apache License 2.0 4 votes vote down vote up
public static Matcher<DateTime> onDayOfYear(Integer... days)
{
    return new DayOfYearMatcher(new AnyOf<>(new Mapped<>(Matchers::equalTo, new Seq<>(days))));
}
 
Example #20
Source File: OutputMatchers.java    From flink-spector with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.
 */
@SafeVarargs
public static <T> OutputMatcher<T> anyOf(OutputMatcher<T>... matchers) {
    return OutputMatcherFactory.create(AnyOf.anyOf(matchers));
}