Java 类org.junit.experimental.theories.FromDataPoints 实例源码

项目:fx-gson    文件:FxGsonTest.java   
@Theory
public void testMapStrProperty(@FromDataPoints("all") Gson gson) {
    CustomObject one = new CustomObject("myObj1");
    CustomObject two = new CustomObject("myObj2");

    ObservableMap<String, CustomObject> mapEmpty = FXCollections.emptyObservableMap();
    ObservableMap<String, CustomObject> mapOne = FXCollections.observableHashMap();
    mapOne.put("key1", one);
    ObservableMap<String, CustomObject> mapTwo = FXCollections.observableHashMap();
    mapTwo.put("key1", one);
    mapTwo.put("key2", two);

    testProperty(WithMapStrProp.class, null, "{\"prop\":null}", o -> o.prop, gson);
    testProperty(WithMapStrProp.class, mapEmpty, "{\"prop\":{}}", o -> o.prop, gson);
    testProperty(WithMapStrProp.class, mapOne, "{\"prop\":{\"key1\":{\"name\":\"myObj1\"}}}", o -> o.prop, gson);
    testProperty(WithMapStrProp.class, mapTwo,
            "{\"prop\":{\"key1\":{\"name\":\"myObj1\"},\"key2\":{\"name\":\"myObj2\"}}}", o -> o.prop, gson);
}
项目:xpath-to-xml    文件:EqualsExprTest.java   
@Theory
public void shouldAssociativelyResolveEqualViewsToTrue(@FromDataPoints("eq left") View<TestNode> left,
                                                       @FromDataPoints("eq left") View<TestNode> right) {
    // given
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(left);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(right);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, false);

    // when
    View<TestNode> leftToRight = new EqualsExpr(leftExpr, rightExpr).resolve(context);
    View<TestNode> rightToLeft = new EqualsExpr(rightExpr, leftExpr).resolve(context);

    // then
    assertThat(leftToRight).isEqualTo(BooleanView.of(true));
    assertThat(rightToLeft).isEqualTo(BooleanView.of(true));
}
项目:xpath-to-xml    文件:EqualsExprTest.java   
@Theory
public void shouldAssociativelyResolveNonEqualViewsToFalse(@FromDataPoints("eq left") View<TestNode> left,
                                                           @FromDataPoints("eq right") View<TestNode> right) {
    // given
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(left);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(right);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, false);

    // when
    View<TestNode> leftToRight = new EqualsExpr(leftExpr, rightExpr).resolve(context);
    View<TestNode> rightToLeft = new EqualsExpr(rightExpr, leftExpr).resolve(context);

    // then
    assertThat(leftToRight).isEqualTo(BooleanView.of(false));
    assertThat(rightToLeft).isEqualTo(BooleanView.of(false));
}
项目:xpath-to-xml    文件:EqualsExprTest.java   
@Theory
public void shouldApplyRightViewToLeftViewWhenShouldCreate(@FromDataPoints("eq left") View<TestNode> left,
                                                           @FromDataPoints("eq right") View<TestNode> right) {
    // given
    if (!(left instanceof NodeView)
            && (!(left instanceof NodeSetView) || !(((NodeSetView) left).iterator().next() instanceof NodeView))) {
        expectedException.expect(XmlBuilderException.class);
    }
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(left);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(right);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, true);

    // when
    View<TestNode> result = new EqualsExpr(leftExpr, rightExpr).resolve(context);

    // then
    assertThat(result).isEqualTo(BooleanView.of(true));
    verify(navigator).setText(any(TestNode.class), eq(right.toString()));
}
项目:xpath-to-xml    文件:NotEqualsExprTest.java   
@Theory
public void shouldAssociativelyResolveEqualViewsToFalse(@FromDataPoints("ne left") View<TestNode> left,
                                                        @FromDataPoints("ne left") View<TestNode> right) {
    // given
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(left);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(right);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, false);

    // when
    View<TestNode> leftToRight = new NotEqualsExpr(leftExpr, rightExpr).resolve(context);
    View<TestNode> rightToLeft = new NotEqualsExpr(rightExpr, leftExpr).resolve(context);

    // then
    assertThat(leftToRight).isEqualTo(BooleanView.of(false));
    assertThat(rightToLeft).isEqualTo(BooleanView.of(false));
}
项目:xpath-to-xml    文件:NotEqualsExprTest.java   
@Theory
public void shouldAssociativelyResolveNonEqualViewsToTrue(@FromDataPoints("ne left") View<TestNode> left,
                                                          @FromDataPoints("ne right") View<TestNode> right) {
    // given
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(left);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(right);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, false);

    // when
    View<TestNode> leftToRight = new NotEqualsExpr(leftExpr, rightExpr).resolve(context);
    View<TestNode> rightToLeft = new NotEqualsExpr(rightExpr, leftExpr).resolve(context);

    // then
    assertThat(leftToRight).isEqualTo(BooleanView.of(true));
    assertThat(rightToLeft).isEqualTo(BooleanView.of(true));
}
项目:xpath-to-xml    文件:NotEqualsExprTest.java   
@Theory
public void shouldApplyRightViewToLeftViewWhenShouldCreate(@FromDataPoints("ne left") View<TestNode> left,
                                                           @FromDataPoints("ne left") View<TestNode> right) {
    // given
    if (!(left instanceof NodeView)
            && (!(left instanceof NodeSetView) || !(((NodeSetView) left).iterator().next() instanceof NodeView))) {
        expectedException.expect(XmlBuilderException.class);
    }
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(left);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(right);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, true);

    // when
    View<TestNode> result = new NotEqualsExpr(leftExpr, rightExpr).resolve(context);

    // then
    assertThat(result).isEqualTo(BooleanView.of(true));
    verify(navigator).setText(any(TestNode.class), eq(Boolean.toString(!right.toBoolean())));
}
项目:spring-credhub    文件:CredHubTemplateSummaryResponseUnitTests.java   
@Theory
public void findByName(@FromDataPoints("responses")
                                                     ResponseEntity<CredentialSummaryData> expectedResponse) {
    when(restTemplate.getForEntity(NAME_LIKE_URL_QUERY, CredentialSummaryData.class, NAME.getName()))
            .thenReturn(expectedResponse);

    if (!expectedResponse.getStatusCode().equals(OK)) {
        try {
            credHubTemplate.findByName(NAME);
            fail("Exception should have been thrown");
        }
        catch (CredHubException e) {
            assertThat(e.getMessage(), containsString(expectedResponse.getStatusCode().toString()));
        }
    }
    else {
        List<CredentialSummary> response = credHubTemplate.findByName(NAME);

        assertResponseContainsExpectedCredentials(expectedResponse, response);
    }
}
项目:spring-credhub    文件:CredHubTemplateSummaryResponseUnitTests.java   
@Theory
public void findByPath(@FromDataPoints("responses")
                                   ResponseEntity<CredentialSummaryData> expectedResponse) {
    when(restTemplate.getForEntity(PATH_URL_QUERY, CredentialSummaryData.class, NAME.getName()))
            .thenReturn(expectedResponse);

    if (!expectedResponse.getStatusCode().equals(OK)) {
        try {
            credHubTemplate.findByPath(NAME.getName());
            fail("Exception should have been thrown");
        }
        catch (CredHubException e) {
            assertThat(e.getMessage(), containsString(expectedResponse.getStatusCode().toString()));
        }
    }
    else {
        List<CredentialSummary> response = credHubTemplate.findByPath(NAME.getName());

        assertResponseContainsExpectedCredentials(expectedResponse, response);
    }
}
项目:fx-gson    文件:FxGsonTest.java   
@Theory
public void testObservableList(@FromDataPoints("all") Gson gson) {
    CustomObject one = new CustomObject("myObj1");
    CustomObject two = new CustomObject("myObj2");

    ObservableList<CustomObject> listEmpty = FXCollections.observableArrayList();
    ObservableList<CustomObject> listOne = FXCollections.observableArrayList(one);
    ObservableList<CustomObject> listTwo = FXCollections.observableArrayList(one, two);

    Function<WithObsList, ObservableList<CustomObject>> getter = o -> o.list;
    BiConsumer<WithObsList, ObservableList<CustomObject>> setter = (o, l) -> o.list = l;

    testValue(WithObsList.class, null, "{\"list\":null}", getter, setter, gson);
    testValue(WithObsList.class, listEmpty, "{\"list\":[]}", getter, setter, gson);
    testValue(WithObsList.class, listOne, "{\"list\":[{\"name\":\"myObj1\"}]}", getter, setter, gson);
    testValue(WithObsList.class, listTwo, "{\"list\":[{\"name\":\"myObj1\"},{\"name\":\"myObj2\"}]}", getter,
            setter, gson);
}
项目:fx-gson    文件:FxGsonTest.java   
@Theory
public void testObservableSet(@FromDataPoints("all") Gson gson) {
    CustomObject one = new CustomObject("myObj1");
    CustomObject two = new CustomObject("myObj2");

    ObservableSet<CustomObject> setEmpty = FXCollections.emptyObservableSet();
    ObservableSet<CustomObject> setOne = FXCollections.observableSet(one);
    ObservableSet<CustomObject> setTwo = FXCollections.observableSet(one, two);

    Function<WithObsSet, ObservableSet<CustomObject>> getter = o -> o.set;
    BiConsumer<WithObsSet, ObservableSet<CustomObject>> setter = (o, s) -> o.set = s;

    testValue(WithObsSet.class, null, "{\"set\":null}", getter, setter, gson);
    testValue(WithObsSet.class, setEmpty, "{\"set\":[]}", getter, setter, gson);
    testValue(WithObsSet.class, setOne, "{\"set\":[{\"name\":\"myObj1\"}]}", getter, setter, gson);
    // do not check a particular JSON because the order is non-deterministic
    testValue(WithObsSet.class, setTwo, null, getter, setter, gson);
}
项目:fx-gson    文件:FxGsonTest.java   
@Theory
public void testObservableMapStr(@FromDataPoints("all") Gson gson) {
    CustomObject one = new CustomObject("myObj1");
    CustomObject two = new CustomObject("myObj2");

    ObservableMap<String, CustomObject> mapEmpty = FXCollections.emptyObservableMap();
    ObservableMap<String, CustomObject> mapOne = FXCollections.observableHashMap();
    mapOne.put("key1", one);
    ObservableMap<String, CustomObject> mapTwo = FXCollections.observableHashMap();
    mapTwo.put("key1", one);
    mapTwo.put("key2", two);

    Function<WithObsMapStr, ObservableMap<String, CustomObject>> getter = o -> o.map;
    BiConsumer<WithObsMapStr, ObservableMap<String, CustomObject>> setter = (o, m) -> o.map = m;

    testValue(WithObsMapStr.class, null, "{\"map\":null}", getter, setter, gson);
    testValue(WithObsMapStr.class, mapEmpty, "{\"map\":{}}", getter, setter, gson);
    testValue(WithObsMapStr.class, mapOne, "{\"map\":{\"key1\":{\"name\":\"myObj1\"}}}", getter, setter, gson);
    testValue(WithObsMapStr.class, mapTwo,
            "{\"map\":{\"key1\":{\"name\":\"myObj1\"},\"key2\":{\"name\":\"myObj2\"}}}", getter, setter, gson);
}
项目:fx-gson    文件:FxGsonTest.java   
@Theory
public void testMapIntProperty(@FromDataPoints("all") Gson gson) {
    CustomObject one = new CustomObject("myObj1");
    CustomObject two = new CustomObject("myObj2");

    ObservableMap<Integer, CustomObject> mapEmpty = FXCollections.emptyObservableMap();
    ObservableMap<Integer, CustomObject> mapOne = FXCollections.observableHashMap();
    mapOne.put(1, one);
    ObservableMap<Integer, CustomObject> mapTwo = FXCollections.observableHashMap();
    mapTwo.put(1, one);
    mapTwo.put(2, two);

    testProperty(WithMapIntProp.class, null, "{\"prop\":null}", o -> o.prop, gson);
    testProperty(WithMapIntProp.class, mapEmpty, "{\"prop\":{}}", o -> o.prop, gson);
    testProperty(WithMapIntProp.class, mapOne, "{\"prop\":{\"1\":{\"name\":\"myObj1\"}}}", o -> o.prop, gson);
    testProperty(WithMapIntProp.class, mapTwo,
            "{\"prop\":{\"1\":{\"name\":\"myObj1\"},\"2\":{\"name\":\"myObj2\"}}}", o -> o.prop, gson);
}
项目:fx-gson    文件:FxGsonTest.java   
@Theory
public void testObservableMapInt(@FromDataPoints("all") Gson gson) {
    CustomObject one = new CustomObject("myObj1");
    CustomObject two = new CustomObject("myObj2");

    ObservableMap<Integer, CustomObject> mapEmpty = FXCollections.emptyObservableMap();
    ObservableMap<Integer, CustomObject> mapOne = FXCollections.observableHashMap();
    mapOne.put(1, one);
    ObservableMap<Integer, CustomObject> mapTwo = FXCollections.observableHashMap();
    mapTwo.put(1, one);
    mapTwo.put(2, two);

    Function<WithObsMapInt, ObservableMap<Integer, CustomObject>> getter = o -> o.map;
    BiConsumer<WithObsMapInt, ObservableMap<Integer, CustomObject>> setter = (o, m) -> o.map = m;

    testValue(WithObsMapInt.class, null, "{\"map\":null}", getter, setter, gson);
    testValue(WithObsMapInt.class, mapEmpty, "{\"map\":{}}", getter, setter, gson);
    testValue(WithObsMapInt.class, mapOne, "{\"map\":{\"1\":{\"name\":\"myObj1\"}}}", getter, setter, gson);
    testValue(WithObsMapInt.class, mapTwo, "{\"map\":{\"1\":{\"name\":\"myObj1\"},\"2\":{\"name\":\"myObj2\"}}}",
            getter, setter, gson);
}
项目:fx-gson    文件:FxGsonTest.java   
@Theory
public void testCustomTreeMapStrProperty(@FromDataPoints("all") Gson gson) {
    CustomObject one = new CustomObject("myObj1");
    CustomObject two = new CustomObject("myObj2");

    Map<String, CustomObject> mapEmpty = new TreeMap<>();
    Map<String, CustomObject> mapOne = new TreeMap<>();
    mapOne.put("key1", one);
    Map<String, CustomObject> mapTwo = new TreeMap<>();
    mapTwo.put("key1", one);
    mapTwo.put("key2", two);

    ObservableMap<String, CustomObject> mapEmptyObs = FXCollections.observableMap(mapEmpty);
    ObservableMap<String, CustomObject> mapOneObs = FXCollections.observableMap(mapOne);
    ObservableMap<String, CustomObject> mapTwoObs = FXCollections.observableMap(mapTwo);

    testProperty(WithMapStrProp.class, null, "{\"prop\":null}", o -> o.prop, gson);
    testProperty(WithMapStrProp.class, mapEmptyObs, "{\"prop\":{}}", o -> o.prop, gson);
    testProperty(WithMapStrProp.class, mapOneObs, "{\"prop\":{\"key1\":{\"name\":\"myObj1\"}}}", o -> o.prop, gson);
    testProperty(WithMapStrProp.class, mapTwoObs,
            "{\"prop\":{\"key1\":{\"name\":\"myObj1\"},\"key2\":{\"name\":\"myObj2\"}}}", o -> o.prop, gson);
}
项目:fx-gson    文件:FxGsonTest.java   
@Theory
public void testCustomObservableTreeMapStr(@FromDataPoints("all") Gson gson) {
    CustomObject one = new CustomObject("myObj1");
    CustomObject two = new CustomObject("myObj2");

    Map<String, CustomObject> mapEmpty = new TreeMap<>();
    Map<String, CustomObject> mapOne = new TreeMap<>();
    mapOne.put("key1", one);
    Map<String, CustomObject> mapTwo = new TreeMap<>();
    mapTwo.put("key1", one);
    mapTwo.put("key2", two);

    ObservableMap<String, CustomObject> mapEmptyObs = FXCollections.observableMap(mapEmpty);
    ObservableMap<String, CustomObject> mapOneObs = FXCollections.observableMap(mapOne);
    ObservableMap<String, CustomObject> mapTwoObs = FXCollections.observableMap(mapTwo);

    Function<WithObsMapStr, ObservableMap<String, CustomObject>> getter = o -> o.map;
    BiConsumer<WithObsMapStr, ObservableMap<String, CustomObject>> setter = (o, m) -> o.map = m;

    testValue(WithObsMapStr.class, null, "{\"map\":null}", getter, setter, gson);
    testValue(WithObsMapStr.class, mapEmptyObs, "{\"map\":{}}", getter, setter, gson);
    testValue(WithObsMapStr.class, mapOneObs, "{\"map\":{\"key1\":{\"name\":\"myObj1\"}}}", getter, setter, gson);
    testValue(WithObsMapStr.class, mapTwoObs,
            "{\"map\":{\"key1\":{\"name\":\"myObj1\"},\"key2\":{\"name\":\"myObj2\"}}}", getter, setter, gson);
}
项目:fx-gson    文件:FxGsonTest.java   
@Theory
public void testCustomTreeMapIntProperty(@FromDataPoints("all") Gson gson) {
    CustomObject one = new CustomObject("myObj1");
    CustomObject two = new CustomObject("myObj2");

    Map<Integer, CustomObject> mapEmpty = new TreeMap<>();
    Map<Integer, CustomObject> mapOne = new TreeMap<>();
    mapOne.put(1, one);
    Map<Integer, CustomObject> mapTwo = new TreeMap<>();
    mapTwo.put(1, one);
    mapTwo.put(2, two);

    ObservableMap<Integer, CustomObject> mapEmptyObs = FXCollections.observableMap(mapEmpty);
    ObservableMap<Integer, CustomObject> mapOneObs = FXCollections.observableMap(mapOne);
    ObservableMap<Integer, CustomObject> mapTwoObs = FXCollections.observableMap(mapTwo);

    testProperty(WithMapIntProp.class, null, "{\"prop\":null}", o -> o.prop, gson);
    testProperty(WithMapIntProp.class, mapEmptyObs, "{\"prop\":{}}", o -> o.prop, gson);
    testProperty(WithMapIntProp.class, mapOneObs, "{\"prop\":{\"1\":{\"name\":\"myObj1\"}}}", o -> o.prop, gson);
    testProperty(WithMapIntProp.class, mapTwoObs,
            "{\"prop\":{\"1\":{\"name\":\"myObj1\"},\"2\":{\"name\":\"myObj2\"}}}", o -> o.prop, gson);
}
项目:fx-gson    文件:FxGsonTest.java   
@Theory
public void testCustomObservableTreeMapInt(@FromDataPoints("all") Gson gson) {
    CustomObject one = new CustomObject("myObj1");
    CustomObject two = new CustomObject("myObj2");

    Map<Integer, CustomObject> mapEmpty = new TreeMap<>();
    Map<Integer, CustomObject> mapOne = new TreeMap<>();
    mapOne.put(1, one);
    Map<Integer, CustomObject> mapTwo = new TreeMap<>();
    mapTwo.put(1, one);
    mapTwo.put(2, two);

    ObservableMap<Integer, CustomObject> mapEmptyObs = FXCollections.observableMap(mapEmpty);
    ObservableMap<Integer, CustomObject> mapOneObs = FXCollections.observableMap(mapOne);
    ObservableMap<Integer, CustomObject> mapTwoObs = FXCollections.observableMap(mapTwo);

    Function<WithObsMapInt, ObservableMap<Integer, CustomObject>> getter = o -> o.map;
    BiConsumer<WithObsMapInt, ObservableMap<Integer, CustomObject>> setter = (o, m) -> o.map = m;

    testValue(WithObsMapInt.class, null, "{\"map\":null}", getter, setter, gson);
    testValue(WithObsMapInt.class, mapEmptyObs, "{\"map\":{}}", getter, setter, gson);
    testValue(WithObsMapInt.class, mapOneObs, "{\"map\":{\"1\":{\"name\":\"myObj1\"}}}", getter, setter, gson);
    testValue(WithObsMapInt.class, mapTwoObs, "{\"map\":{\"1\":{\"name\":\"myObj1\"},\"2\":{\"name\":\"myObj2\"}}}",
            getter, setter, gson);
}
项目:fx-gson    文件:FxGsonTest.java   
@Theory
public void testList(@FromDataPoints("all") Gson gson) {
    CustomObject one = new CustomObject("myObj1");
    CustomObject two = new CustomObject("myObj2");

    List<CustomObject> listEmpty = Collections.emptyList();
    List<CustomObject> listOne = Collections.singletonList(one);
    List<CustomObject> listTwo = Arrays.asList(one, two);

    Function<WithList, List<CustomObject>> getter = o -> o.list;
    BiConsumer<WithList, List<CustomObject>> setter = (o, l) -> o.list = l;

    testValue(WithList.class, null, "{\"list\":null}", getter, setter, gson);
    testValue(WithList.class, listEmpty, "{\"list\":[]}", getter, setter, gson);
    testValue(WithList.class, listOne, "{\"list\":[{\"name\":\"myObj1\"}]}", getter, setter, gson);
    testValue(WithList.class, listTwo, "{\"list\":[{\"name\":\"myObj1\"},{\"name\":\"myObj2\"}]}", getter, setter,
            gson);
}
项目:fx-gson    文件:FxGsonTest.java   
@Theory
public void testSet(@FromDataPoints("all") Gson gson) {
    CustomObject one = new CustomObject("myObj1");
    CustomObject two = new CustomObject("myObj2");

    Set<CustomObject> setEmpty = Collections.emptySet();
    Set<CustomObject> setOne = Collections.singleton(one);
    Set<CustomObject> setTwo = new HashSet<>(Arrays.asList(one, two));

    Function<WithSet, Set<CustomObject>> getter = o -> o.set;
    BiConsumer<WithSet, Set<CustomObject>> setter = (o, s) -> o.set = s;

    testValue(WithSet.class, null, "{\"set\":null}", getter, setter, gson);
    testValue(WithSet.class, setEmpty, "{\"set\":[]}", getter, setter, gson);
    testValue(WithSet.class, setOne, "{\"set\":[{\"name\":\"myObj1\"}]}", getter, setter, gson);
    // do not check a particular JSON because the order is non-deterministic
    testValue(WithSet.class, setTwo, null, getter, setter, gson);
}
项目:fx-gson    文件:FxGsonTest.java   
@Theory
public void testMapStr(@FromDataPoints("all") Gson gson) {
    CustomObject one = new CustomObject("myObj1");
    CustomObject two = new CustomObject("myObj2");

    Map<String, CustomObject> mapEmpty = Collections.emptyMap();
    Map<String, CustomObject> mapOne = Collections.singletonMap("key1", one);
    Map<String, CustomObject> mapTwo = new HashMap<>();
    mapTwo.put("key1", one);
    mapTwo.put("key2", two);

    Function<WithMapStr, Map<String, CustomObject>> getter = o -> o.map;
    BiConsumer<WithMapStr, Map<String, CustomObject>> setter = (o, m) -> o.map = m;

    testValue(WithMapStr.class, null, "{\"map\":null}", getter, setter, gson);
    testValue(WithMapStr.class, mapEmpty, "{\"map\":{}}", getter, setter, gson);
    testValue(WithMapStr.class, mapOne, "{\"map\":{\"key1\":{\"name\":\"myObj1\"}}}", getter, setter, gson);
    testValue(WithMapStr.class, mapTwo, "{\"map\":{\"key1\":{\"name\":\"myObj1\"},\"key2\":{\"name\":\"myObj2\"}}}",
            getter, setter, gson);
}
项目:fx-gson    文件:FxGsonTest.java   
@Theory
public void testMapInt(@FromDataPoints("all") Gson gson) {
    CustomObject one = new CustomObject("myObj1");
    CustomObject two = new CustomObject("myObj2");

    Map<Integer, CustomObject> mapEmpty = Collections.emptyMap();
    Map<Integer, CustomObject> mapOne = Collections.singletonMap(1, one);
    Map<Integer, CustomObject> mapTwo = new HashMap<>();
    mapTwo.put(1, one);
    mapTwo.put(2, two);

    Function<WithMapInt, Map<Integer, CustomObject>> getter = o -> o.map;
    BiConsumer<WithMapInt, Map<Integer, CustomObject>> setter = (o, m) -> o.map = m;

    testValue(WithMapInt.class, null, "{\"map\":null}", getter, setter, gson);
    testValue(WithMapInt.class, mapEmpty, "{\"map\":{}}", getter, setter, gson);
    testValue(WithMapInt.class, mapOne, "{\"map\":{\"1\":{\"name\":\"myObj1\"}}}", getter, setter, gson);
    testValue(WithMapInt.class, mapTwo, "{\"map\":{\"1\":{\"name\":\"myObj1\"},\"2\":{\"name\":\"myObj2\"}}}",
            getter, setter, gson);
}
项目:fast-rng-java    文件:BetaRNGTest.java   
@Theory
public void testGoodnessOfFitByTwoLevelTesting(
        @FromDataPoints("N") final int N,
        @FromDataPoints("K") final int K,
        final BetaDistParam parameters,
        final BetaRNG betaRNG) {

    final double alpha = parameters.alpha;
    final double beta = parameters.beta;

    System.out.printf("%s: alpha = %.2f, beta = %.2f%n", betaRNG.getClass().getSimpleName(), alpha, beta);

    TwoLevelTester tester = new TwoLevelTester(N, K);
    tester.test(
            random -> betaRNG.generate(random, alpha, beta),
            new BetaDistribution(alpha, beta, 1e-15));
    System.out.println(betaRNG);
}
项目:emr-dynamodb-connector    文件:RateControllerTest.java   
@Theory
public void testHappyCase(@FromDataPoints("rates") double rate, @FromDataPoints("sizes") double
    itemSize, @FromDataPoints("windows") int windowSize) {

  RateController rateCtr = new RateController(time, rate, windowSize, itemSize);
  double rcu = 0.0;

  // Consume until we get a zero response
  RateController.RequestLimit lim;
  while ((lim = rateCtr.getNextRequestLimit()) != RateController.RequestLimit.ZERO) {
    rcu += lim.readCapacityUnits;
  }

  // Should not have consumed more IO than rate * bucket window
  double bucketCapacity = Math.max(windowSize * rateCtr.getTargetRate(), RateController
      .MIN_RCU_PER_REQ);
  assertTrue("readCapacityUnits=" + rcu + ", cap=" + bucketCapacity, rcu <= bucketCapacity);

  // Should have consumed at least cap - min_per_request
  assertTrue(rcu > bucketCapacity - RateController.MIN_RCU_PER_REQ);
}
项目:FSDevTools    文件:SchemaUidToNameBasedLayerMapperTest.java   
@Theory
public void testFrom(@FromDataPoints("schemas") String sourceSchemaUID, @FromDataPoints("layers") final String targetLayer)
        throws Exception {

    map.put(sourceSchemaUID, targetLayer);

    if (!"*".equals(sourceSchemaUID)) {
        // if layer is without wild card then add wild card to see that it is not used
        map.put("*", SchemaUidToNameBasedLayerMapper.CREATE_NEW);
    } else {
        // if wild card is added then trigger usage of wild card -> rename source schema
        sourceSchemaUID = "laleleu_schema";
    }

    when(schema.getUid()).thenReturn(sourceSchemaUID);

    final LayerMapper testling = SchemaUidToNameBasedLayerMapper.from(map);

    assertThat(testling, is(notNullValue()));
    if (SchemaUidToNameBasedLayerMapper.CREATE_NEW.equals(targetLayer)) {
        assertThat(testling.getLayer(context), is(LayerMapper.CREATE_NEW_DEFAULT_LAYER));
    } else {
        assertThat(testling.getLayer(context), is(targetLayer));
    }
}
项目:xpath-to-xml    文件:XPathParserTest.java   
@Theory
public void shouldParseSimpleXPath(@FromDataPoints("Positive-Simple") Pair<String, Expr> data,
                                   @FromDataPoints("namespaceContexts") NamespaceContext context)
        throws XPathExpressionException {
    Expr actualExpr = new XPathParser(context).parse(data.getFirst());
    assertThat(actualExpr).hasToString(data.getSecond().toString());
}
项目:xpath-to-xml    文件:XPathParserTest.java   
@Theory
public void shouldParsePrefixedXPath(@FromDataPoints("Positive-Prefixed") Triple<String, Expr, Expr> data,
                                     @FromDataPoints("namespaceContexts") NamespaceContext context)
        throws XPathExpressionException {
    Expr actualExpr = new XPathParser(context).parse(data.getFirst());
    assertThat(actualExpr).hasToString(null == context ? data.getSecond().toString() : data.getThird().toString());
}
项目:xpath-to-xml    文件:XPathParserTest.java   
@Theory
public void shouldThrowExceptionOnParse(@FromDataPoints("Negative") String invalidXPath,
                                        @FromDataPoints("namespaceContexts") NamespaceContext namespaceContext)
        throws XPathExpressionException {
    thrown.expect(XPathExpressionException.class);
    System.err.println(new XPathParser(namespaceContext).parse(invalidXPath));
}
项目:xpath-to-xml    文件:LessThanOrEqualsExprTest.java   
@Theory
public void shouldResolveToTrueWhenLeftIsLessThanRight(@FromDataPoints("less") View<TestNode> less,
                                                       @FromDataPoints("greater") View<TestNode> greater) {
    // given
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(less);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(greater);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, false);

    // when
    View<TestNode> result = new LessThanOrEqualsExpr(leftExpr, rightExpr).resolve(context);

    // then
    assertThat(result).isEqualTo(BooleanView.of(true));
}
项目:xpath-to-xml    文件:LessThanOrEqualsExprTest.java   
@Theory
public void shouldResolveToFalseWhenLeftIsGreaterThanRight(@FromDataPoints("less") View<TestNode> less,
                                                           @FromDataPoints("greater") View<TestNode> greater) {
    // given
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(greater);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(less);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, false);

    // when
    View<TestNode> result = new LessThanOrEqualsExpr(leftExpr, rightExpr).resolve(context);

    // then
    assertThat(result).isEqualTo(BooleanView.of(false));
}
项目:xpath-to-xml    文件:LessThanOrEqualsExprTest.java   
@Theory
public void shouldResolveToTrueWhenLeftIsEqualToRight(@FromDataPoints("less") View<TestNode> left,
                                                      @FromDataPoints("less") View<TestNode> right) {
    // given
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(left);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(right);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, false);

    // when
    View<TestNode> result = new LessThanOrEqualsExpr(leftExpr, rightExpr).resolve(context);

    // then
    assertThat(result).isEqualTo(BooleanView.of(true));
}
项目:xpath-to-xml    文件:LessThanOrEqualsExprTest.java   
@Theory
public void shouldThrowWhenResolveToFalseAndShouldCreate(@FromDataPoints("less") View<TestNode> less,
                                                         @FromDataPoints("greater") View<TestNode> greater) {
    // given
    expectedException.expect(XmlBuilderException.class);
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(greater);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(less);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, true);

    // when
    new LessThanOrEqualsExpr(leftExpr, rightExpr).resolve(context);
}
项目:xpath-to-xml    文件:SubtractionExprTest.java   
@Theory
public void shouldMultiplyLeftViewToRightView(@FromDataPoints("3.0") View<TestNode> left,
                                              @FromDataPoints("3.0") View<TestNode> right) {
    // given
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(left);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(right);
    ViewContext<TestNode> context = new ViewContext<>(navigator, new NodeView<>(node("node")), false);

    // when
    assertThat(new SubtractionExpr(leftExpr, rightExpr).resolve(context)).extracting("number").contains(0.0);
}
项目:xpath-to-xml    文件:UnaryExprTest.java   
@Theory
public void shouldAlwaysReturnNegatedNumberViewNode(
        @FromDataPoints("views") Pair<View<TestNode>, NumberView<TestNode>> data) {
    when(valueExpr.resolve(any(ViewContext.class))).thenReturn(data.getFirst());

    View<TestNode> result = unaryExpr.resolve(new ViewContext<>(navigator,
            new NodeView<>(node("xml")), false));
    assertThat(result.toNumber()).isEqualTo(data.getSecond().toNumber());
}
项目:xpath-to-xml    文件:LessThanExprTest.java   
@Theory
public void shouldResolveToTrueWhenLeftIsLessThanRight(@FromDataPoints("less") View<TestNode> less,
                                                       @FromDataPoints("greater") View<TestNode> greater) {
    // given
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(less);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(greater);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, false);

    // when
    View<TestNode> result = new LessThanExpr(leftExpr, rightExpr).resolve(context);

    // then
    assertThat(result).isEqualTo(BooleanView.of(true));
}
项目:xpath-to-xml    文件:LessThanExprTest.java   
@Theory
public void shouldResolveToFalseWhenLeftIsGreaterThanRight(@FromDataPoints("less") View<TestNode> less,
                                                           @FromDataPoints("greater") View<TestNode> greater) {
    // given
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(greater);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(less);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, false);

    // when
    View<TestNode> result = new LessThanExpr(leftExpr, rightExpr).resolve(context);

    // then
    assertThat(result).isEqualTo(BooleanView.of(false));
}
项目:xpath-to-xml    文件:LessThanExprTest.java   
@Theory
public void shouldResolveToFalseWhenLeftIsEqualToRight(@FromDataPoints("less") View<TestNode> left,
                                                       @FromDataPoints("less") View<TestNode> right) {
    // given
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(left);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(right);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, false);

    // when
    View<TestNode> result = new LessThanExpr(leftExpr, rightExpr).resolve(context);

    // then
    assertThat(result).isEqualTo(BooleanView.of(false));
}
项目:xpath-to-xml    文件:LessThanExprTest.java   
@Theory
public void shouldThrowWhenResolveToFalseAndShouldCreate(@FromDataPoints("less") View<TestNode> less,
                                                         @FromDataPoints("greater") View<TestNode> greater) {
    // given
    expectedException.expect(XmlBuilderException.class);
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(greater);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(less);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, true);

    // when
    new LessThanExpr(leftExpr, rightExpr).resolve(context);
}
项目:xpath-to-xml    文件:GreaterThanOrEqualsExprTest.java   
@Theory
public void shouldResolveToTrueWhenLeftIsGreaterThanRight(@FromDataPoints("less") View<TestNode> less,
                                                          @FromDataPoints("greater") View<TestNode> greater) {
    // given
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(greater);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(less);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, false);

    // when
    View<TestNode> result = new GreaterThanOrEqualsExpr(leftExpr, rightExpr).resolve(context);

    // then
    assertThat(result).isEqualTo(BooleanView.of(true));
}
项目:xpath-to-xml    文件:GreaterThanOrEqualsExprTest.java   
@Theory
public void shouldResolveToFalseWhenLeftIsLessThanRight(@FromDataPoints("less") View<TestNode> less,
                                                        @FromDataPoints("greater") View<TestNode> greater) {
    // given
    when(leftExpr.resolve(any(ViewContext.class))).thenReturn(less);
    when(rightExpr.resolve(any(ViewContext.class))).thenReturn(greater);
    ViewContext<TestNode> context = new ViewContext<>(navigator, parentNode, false);

    // when
    View<TestNode> result = new GreaterThanOrEqualsExpr(leftExpr, rightExpr).resolve(context);

    // then
    assertThat(result).isEqualTo(BooleanView.of(false));
}