コード例 #1
0
  public void testFindByParent() throws Exception {
    final FundsMutationSubjectRepository subjectRepository = bundle.fundsMutationSubjects();

    try {
      FundsMutationSubject food =
          FundsMutationSubject.builder(subjectRepository)
              .setName("Food")
              .setType(FundsMutationSubject.Type.PRODUCT)
              .build();
      subjectRepository.addSubject(food);
    } catch (Exception ignore) {
    }
    final FundsMutationSubject food1 = subjectRepository.findByName("Food").get();
    final FundsMutationSubject meat =
        FundsMutationSubject.builder(subjectRepository)
            .setName("Meat")
            .setType(FundsMutationSubject.Type.PRODUCT)
            .setParentId(food1.id.getAsLong())
            .build();
    final FundsMutationSubject vegs =
        FundsMutationSubject.builder(subjectRepository)
            .setName("Vegs")
            .setType(FundsMutationSubject.Type.PRODUCT)
            .setParentId(food1.id.getAsLong())
            .build();
    subjectRepository.addSubject(meat);
    subjectRepository.addSubject(vegs);
    subjectRepository
        .findByParent(food1.id.getAsLong())
        .forEach(
            new Consumer<FundsMutationSubject>() {
              @Override
              public void accept(FundsMutationSubject subject) {
                assertTrue(
                    "Wrong byParent stream: " + subject.name,
                    subject.equals(meat) || subject.equals(vegs));
              }
            });
  }