package org.altbeacon.beacon;

import org.altbeacon.beacon.logging.LogManager;
import org.altbeacon.beacon.logging.Loggers;
import org.altbeacon.beacon.simulator.BeaconSimulator;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import java.util.Collections;
import java.util.List;

import static org.junit.Assert.*;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 28)
public class BeaconManagerTest {

  @Before
  public void before() {
    org.robolectric.shadows.ShadowLog.stream = System.err;
    LogManager.setLogger(Loggers.verboseLogger());
    LogManager.setVerboseLoggingEnabled(true);
    BeaconManager.setsManifestCheckingDisabled(true);
    BeaconManager.setBeaconSimulator(new BeaconSimulator() {
      @Override
      public List<Beacon> getBeacons() {
        return Collections.emptyList();
      }
    });
  }

  @Test
  public void startRangingBeaconsInRegionMultipleInvocationsTest() throws Exception {
    BeaconManager beaconManager = BeaconManager
        .getInstanceForApplication(RuntimeEnvironment.application);

    String id = "id";
    Region region1 = new Region(id, Collections.<Identifier>emptyList());
    Region region2 = new Region(id, "00:11:22:33:FF:EE");

    beaconManager.startRangingBeaconsInRegion(region1);
    assertEquals(beaconManager.getRangedRegions().size(), 1);
    assertSame(beaconManager.getRangedRegions().iterator().next(), region1);
    assertNotSame(beaconManager.getRangedRegions().iterator().next(), region2);

    beaconManager.startRangingBeaconsInRegion(region2);
    assertEquals(beaconManager.getRangedRegions().size(), 1);
    assertNotSame(beaconManager.getRangedRegions().iterator().next(), region1);
    assertSame(beaconManager.getRangedRegions().iterator().next(), region2);

    Region region3 = new Region(id + "-other", Collections.<Identifier>emptyList());
    beaconManager.startRangingBeaconsInRegion(region3);
    assertEquals(beaconManager.getRangedRegions().size(), 2);
  }

}

@@ -2115,10 +2115,912 @@
 );%0A  %7D%0A%0A
+  @Test%0A  public void stopRangingBeaconsInRegionTest() throws Exception %7B%0A    BeaconManager beaconManager = BeaconManager%0A        .getInstanceForApplication(RuntimeEnvironment.application);%0A%0A    String id = %22id%22;%0A    Region region1 = new Region(id, Collections.%3CIdentifier%3EemptyList());%0A    Region region2 = new Region(id, %2200:11:22:33:FF:EE%22);%0A    Region region3 = new Region(id + %22-other%22, Collections.%3CIdentifier%3EemptyList());%0A%0A    beaconManager.startRangingBeaconsInRegion(region1);%0A    beaconManager.startRangingBeaconsInRegion(region2);%0A    beaconManager.startRangingBeaconsInRegion(region3);%0A    assertEquals(beaconManager.getRangedRegions().size(), 2);%0A%0A    beaconManager.stopRangingBeaconsInRegion(region1);%0A    assertEquals(beaconManager.getRangedRegions().size(), 1);%0A%0A    beaconManager.stopRangingBeaconsInRegion(region3);%0A    assertEquals(beaconManager.getRangedRegions().size(), 0);%0A  %7D%0A%0A
 %7D%0A

Verify stopRangingBeaconsInRegion