/**
 * Copyright (c) 2016, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package eu.itesla_project.iidm.network.impl;

import eu.itesla_project.iidm.network.*;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * ArrayIndexOutOfBoundsException fix test
 * @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
 */
public class EmptyCalculatedBusBugTest {

    @Test
    public void test() {
        Network network = NetworkFactory.create("test", "test");
        Substation s = network.newSubstation()
                .setId("S")
                .setCountry(Country.FR)
                .add();
        VoltageLevel vl = s.newVoltageLevel()
                .setId("VL")
                .setNominalV(400f)
                .setTopologyKind(TopologyKind.NODE_BREAKER)
                .add();
        vl.getNodeBreakerView().setNodeCount(2);
        vl.getNodeBreakerView().newBreaker()
                .setId("SW1")
                .setNode1(0)
                .setNode2(1)
                .setOpen(false)
                .setRetained(false)
                .add();
        assertEquals(2, vl.getBusBreakerView().getBusStream().count());
    }
}

@@ -589,35 +589,55 @@
     
-@Test%0A    public void test(
+private Network createNetwork(boolean retainded
 ) %7B%0A
@@ -1277,22 +1277,165 @@
 etained(
+retainded)%0A                .add();%0A%0A        return network;%0A    %7D%0A%0A    @Test%0A    public void test() %7B%0A        Network network = createNetwork(
 false)
+;
 %0A       
@@ -1439,50 +1439,192 @@
     
-        .add();%0A        assertEquals(2, vl
+assertEquals(1, network.getVoltageLevel(%22VL%22).getBusBreakerView().getBusStream().count());%0A%0A        network = createNetwork(true);%0A        assertEquals(2, network.getVoltageLevel(%22VL%22)
 .get

Fix compilation and add another test