BranchTripping extends AbstractTrippingTask { @Override public void traverse(Network network, ComputationManager computationManager, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect) { Objects.requireNonNull(network); Branch branch = network.getBranch(branchId); if (branch == null) { throw new PowsyblException("Branch '" + branchId + "' not found"); } if (voltageLevelId != null) { if (voltageLevelId.equals(branch.getTerminal1().getVoltageLevel().getId())) { ContingencyTopologyTraverser.traverse(branch.getTerminal1(), switchesToOpen, terminalsToDisconnect); } else if (voltageLevelId.equals(branch.getTerminal2().getVoltageLevel().getId())) { ContingencyTopologyTraverser.traverse(branch.getTerminal2(), switchesToOpen, terminalsToDisconnect); } else { throw new PowsyblException("VoltageLevel '" + voltageLevelId + "' not connected to branch '" + branchId + "'"); } } else { ContingencyTopologyTraverser.traverse(branch.getTerminal1(), switchesToOpen, terminalsToDisconnect); ContingencyTopologyTraverser.traverse(branch.getTerminal2(), switchesToOpen, terminalsToDisconnect); } } BranchTripping(String branchId);  BranchTripping(String branchId, String voltageLevelId); @Override void traverse(Network network, ComputationManager computationManager, Set<Switch> switchesToOpen, Set<Terminal> terminalsToDisconnect);  }
@Test public void fictitiousSwitchTest() { Set<String> switchIds = Sets.newHashSet("BD", "BL"); Network network = FictitiousSwitchFactory.create(); List<Boolean> expectedSwitchStates = getSwitchStates(network, switchIds); BranchTripping tripping = new BranchTripping("CJ", "C"); Set<Switch> switchesToOpen = new HashSet<>(); Set<Terminal> terminalsToDisconnect = new HashSet<>(); tripping.traverse(network, null, switchesToOpen, terminalsToDisconnect); assertEquals(switchIds, switchesToOpen.stream().map(Switch::getId).collect(Collectors.toSet())); assertEquals(Collections.emptySet(), terminalsToDisconnect); tripping.modify(network, null); assertTrue(network.getSwitch("BD").isOpen()); assertTrue(network.getSwitch("BL").isOpen()); List<Boolean> switchStates = getSwitchStates(network, switchIds); assertEquals(expectedSwitchStates, switchStates); }