@Override
  public void execute(Context context) {
    long count = 0;
    try (StreamWriter<ProjectDump.Rule> writer = dumpWriter.newStreamWriter(DumpElement.RULES)) {
      ProjectDump.Rule.Builder ruleBuilder = ProjectDump.Rule.newBuilder();
      for (Rule rule : ruleRepository.getAll()) {
        ProjectDump.Rule ruleMessage = toRuleMessage(ruleBuilder, rule);
        writer.write(ruleMessage);
        count++;
      }
      LoggerFactory.getLogger(getClass()).debug("{} rules exported", count);
    } catch (Exception e) {
      throw new IllegalStateException(format("Rule Export failed after processing %d rules successfully", count), e);
    }
  }
@Test
  public void excuse_throws_ISE_exception_with_number_of_successfully_exported_rules() {
    ruleRepository.add("A").add("B").add("C")
      // will cause NPE
      .addNull();

    assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext()))
      .isInstanceOf(IllegalStateException.class)
      .hasMessage("Rule Export failed after processing 3 rules successfully");
  }