Exemplo n.º 1
0
  public SerializableModel(Model model) {
    this.repoId = model.getRepoId();
    this.updateSignature = model.getUpdateSignature();

    this.issues =
        model.getIssues().stream().map(SerializableIssue::new).collect(Collectors.toList());
    this.labels =
        model.getLabels().stream().map(SerializableLabel::new).collect(Collectors.toList());
    this.milestones =
        model.getMilestones().stream().map(SerializableMilestone::new).collect(Collectors.toList());
    this.users = model.getUsers().stream().map(SerializableUser::new).collect(Collectors.toList());
  }
Exemplo n.º 2
0
  @Test
  public void immutability() {
    Model other = new Model(modelUpdated);
    other.getIssues().add(new TurboIssue(REPO, 11, ""));
    assertEquals(modelUpdated, other);

    other = new Model(modelUpdated);
    other.getLabels().add(new TurboLabel(REPO, "aksdjl"));
    assertEquals(modelUpdated, other);

    other = new Model(modelUpdated);
    other.getMilestones().add(new TurboMilestone(REPO, 11, ""));
    assertEquals(modelUpdated, other);

    other = new Model(modelUpdated);
    other.getUsers().add(new TurboUser(REPO, ""));
    assertEquals(modelUpdated, other);
  }
Exemplo n.º 3
0
  @Test
  public void equality() {

    assertEquals(modelUpdated, modelUpdated);
    assertNotEquals(modelUpdated, null);
    assertNotEquals(modelUpdated, 1);

    // Empty signature

    assertEquals(modelEmptySig, modelEmptySig2);

    // Copy correctness

    assertEquals(modelCopyUpdated, modelUpdated);
    assertEquals(modelCopyNotUpdated, modelEmptySig);

    // Update signature

    // Tested by changing one element in the model and ensuring inequality

    assertEquals(modelEmptySig.hashCode(), modelEmptySig2.hashCode());
    assertEquals(modelCopyUpdated.hashCode(), modelUpdated.hashCode());
    assertNotEquals(modelEmptySig.hashCode(), modelUpdated.hashCode());

    Model model =
        new Model(
            "something",
            modelUpdated.getIssues(),
            modelUpdated.getLabels(),
            modelUpdated.getMilestones(),
            modelUpdated.getUsers(),
            modelUpdated.getUpdateSignature());
    assertNotEquals(model.hashCode(), modelUpdated.hashCode());
    assertNotEquals(model, modelUpdated);

    List<TurboIssue> issues = new ArrayList<>(modelUpdated.getIssues());
    issues.add(new TurboIssue(REPO, 11, "something"));
    model =
        new Model(
            REPO,
            issues,
            modelUpdated.getLabels(),
            modelUpdated.getMilestones(),
            modelUpdated.getUsers(),
            modelUpdated.getUpdateSignature());
    assertNotEquals(model.hashCode(), modelUpdated.hashCode());
    assertNotEquals(model, modelUpdated);

    List<TurboLabel> labels = new ArrayList<>(modelUpdated.getLabels());
    labels.add(new TurboLabel(REPO, "Label 11"));
    model =
        new Model(
            REPO,
            modelUpdated.getIssues(),
            labels,
            modelUpdated.getMilestones(),
            modelUpdated.getUsers(),
            modelUpdated.getUpdateSignature());
    assertNotEquals(model.hashCode(), modelUpdated.hashCode());
    assertNotEquals(model, modelUpdated);

    List<TurboMilestone> milestones = new ArrayList<>(modelUpdated.getMilestones());
    milestones.add(new TurboMilestone(REPO, 11, "something"));
    model =
        new Model(
            REPO,
            modelUpdated.getIssues(),
            modelUpdated.getLabels(),
            milestones,
            modelUpdated.getUsers(),
            modelUpdated.getUpdateSignature());
    assertNotEquals(model.hashCode(), modelUpdated.hashCode());
    assertNotEquals(model, modelUpdated);

    List<TurboUser> users = new ArrayList<>(modelUpdated.getUsers());
    users.add(new TurboUser(REPO, "someone"));
    model =
        new Model(
            REPO,
            modelUpdated.getIssues(),
            modelUpdated.getLabels(),
            modelUpdated.getMilestones(),
            users,
            modelUpdated.getUpdateSignature());
    assertNotEquals(model.hashCode(), modelUpdated.hashCode());
    assertNotEquals(model, modelUpdated);
  }
Exemplo n.º 4
0
  @Test
  public void getters() {
    // ID
    assertEquals(REPO, modelUpdated.getRepoId());
    assertEquals(modelUpdated.getRepoId(), modelUpdated.getRepoId());

    // Signature
    assertEquals(true, modelEmptySig.getUpdateSignature().isEmpty());
    assertEquals(modelEmptySig.getUpdateSignature(), UpdateSignature.EMPTY);
    assertEquals(modelEmptySig.getUpdateSignature(), modelEmptySig2.getUpdateSignature());

    // Resources
    // Issues
    ArrayList<Integer> issueIds = new ArrayList<>();
    for (int i = 1; i <= DummyRepoState.NO_OF_DUMMY_ISSUES; i++) {
      issueIds.add(i);
    }
    Collections.sort(issueIds); // 1, 2..10
    int issueCount = 1;
    for (TurboIssue issue : modelUpdated.getIssues()) {
      assertEquals(issueCount, modelUpdated.getIssueById(issueCount).get().getId());
      assertEquals(issueIds.get(issueCount - 1).intValue(), issue.getId());
      issueCount++;
    }

    // Labels
    ArrayList<String> labelNames = new ArrayList<>();
    for (int i = 1; i <= DummyRepoState.NO_OF_DUMMY_ISSUES; i++) {
      labelNames.add("Label " + i);
    }
    Collections.sort(labelNames); // Label 1, Label 10..12, Label 2..9
    int labelCount = 1;
    for (TurboLabel label : modelUpdated.getLabels()) {
      if (label.getFullName().startsWith("Label")) {
        assertEquals(labelNames.get(labelCount - 1), label.getFullName());
        assertEquals(
            "Label " + labelCount,
            modelUpdated.getLabelByActualName("Label " + labelCount).get().getFullName());
        labelCount++;
      }
    }

    // Milestones
    ArrayList<Integer> milestoneIds = new ArrayList<>();
    for (int i = 1; i <= DummyRepoState.NO_OF_DUMMY_ISSUES; i++) {
      milestoneIds.add(i);
    }
    Collections.sort(milestoneIds); // 1, 2..10
    int milestoneCount = 1;
    for (TurboMilestone milestone : modelUpdated.getMilestones()) {
      assertEquals(milestoneCount, milestone.getId());
      assertEquals(
          milestoneIds.get(milestoneCount - 1).intValue(),
          modelUpdated.getMilestoneById(milestoneCount).get().getId());
      assertEquals(
          "Milestone " + milestoneCount,
          modelUpdated.getMilestoneByTitle("Milestone " + milestoneCount).get().getTitle());
      milestoneCount++;
    }

    // Users
    ArrayList<String> userLogins = new ArrayList<>();
    for (int i = 1; i <= DummyRepoState.NO_OF_DUMMY_ISSUES; i++) {
      userLogins.add("User " + i);
    }
    Collections.sort(userLogins); // User 1, User 10, User 2..9
    int userCount = 1;
    for (TurboUser user : modelUpdated.getUsers()) {
      assertEquals(userLogins.get(userCount - 1), user.getLoginName());
      assertEquals(
          "User " + userCount,
          modelUpdated.getUserByLogin("User " + userCount).get().getLoginName());
      userCount++;
    }
  }