@Test
  public void should_load_project_id() throws Exception {
    SnapshotCache snapshotCache = mock(SnapshotCache.class);
    when(snapshotCache.get("struts:Action.java"))
        .thenReturn(new Snapshot().setResourceId(123).setRootProjectId(100));

    ScanIssueStorage storage =
        new ScanIssueStorage(
            getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis()));
    long projectId = storage.projectId(new DefaultIssue().setComponentKey("struts:Action.java"));

    assertThat(projectId).isEqualTo(100);
  }
  @Test
  public void should_load_component_id_from_db() throws Exception {
    setupData("should_load_component_id_from_db");
    SnapshotCache snapshotCache = mock(SnapshotCache.class);
    when(snapshotCache.get("struts:Action.java")).thenReturn(null);

    ScanIssueStorage storage =
        new ScanIssueStorage(
            getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis()));
    long componentId =
        storage.componentId(new DefaultIssue().setComponentKey("struts:Action.java"));

    assertThat(componentId).isEqualTo(123);
  }
  @Test
  public void should_fail_to_load_project_id_if_unknown_component() throws Exception {
    SnapshotCache snapshotCache = mock(SnapshotCache.class);
    when(snapshotCache.get("struts:Action.java")).thenReturn(null);

    ScanIssueStorage storage =
        new ScanIssueStorage(
            getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis()));
    try {
      storage.projectId(new DefaultIssue().setComponentKey("struts:Action.java"));
      fail();
    } catch (Exception e) {
      assertThat(e).hasMessage("Project id not found for: struts:Action.java");
    }
  }