Skip to content

Commit e9e3f80

Browse files
committed
Fixed region cloning per #26
1 parent f1e40e5 commit e9e3f80

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/main/java/org/altbeacon/beacon/Region.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,12 @@ protected Region(Region otherRegion) {
208208
super();
209209
mIdentifiers = new ArrayList<Identifier>(otherRegion.mIdentifiers.size());
210210
for (int i = 0; i < otherRegion.mIdentifiers.size(); i++) {
211-
mIdentifiers.add(new Identifier(otherRegion.mIdentifiers.get(i)));
211+
Identifier otherIdentifier = otherRegion.mIdentifiers.get(i);
212+
mIdentifiers.add(otherIdentifier != null ? new Identifier(otherIdentifier) : null);
212213
}
213214
mUniqueId = otherRegion.mUniqueId;
214215
}
216+
215217
protected Region() {
216218
}
217219

src/test/java/org/altbeacon/beacon/RegionTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ public void testToString() {
8282
assertEquals("id1: 1 id2: 2 id3: null", region.toString());
8383
}
8484

85+
@Test
86+
public void testCopyConstructor() {
87+
Region region = new Region("myRegion", Identifier.parse("1"), Identifier.parse("2"), null);
88+
Region region2 = new Region(region);
89+
assertEquals(region, region2);
90+
assertNull(region2.getId3());
91+
}
92+
93+
8594
@Test
8695
public void testConvenienceIdentifierAccessors() {
8796
Region region = new Region("myRegion", Identifier.parse("1"), Identifier.parse("2"), Identifier.parse("3"));

0 commit comments

Comments
 (0)