Realm implements Serializable, Comparable<Realm> { public static Realm valueOf(@NonNull String name) throws IllegalArgumentException { final Realm realm; synchronized (KNOWN_REALMS) { realm = KNOWN_REALMS.get(name); } if (realm == null) { throw new IllegalArgumentException("Unknown realm " + name); } return realm; } private  Realm(@NonNull String realmId, @NonNull String secondLevelDomain); int compareTo(Realm other); @Override // For backward compatibility maintain the enum toString behavior String toString(); static Realm[] values(); static Realm valueOf(@NonNull String name); static Realm register(@NonNull String realmId, @NonNull String secondLevelDomain); static final Realm OC1; static final Realm OC2; static final Realm OC3; static final Realm OC4; static final Realm OC8; }
@Test public void withExpectedRealms_shouldContainAllValues() { for (Entry<String, String> expectedRealm : EXPECTED_REALMS.entrySet()) { final Realm actualRealm = Realm.valueOf(expectedRealm.getKey()); assertEquals( "RealmId should be equal", expectedRealm.getValue(), actualRealm.getRealmId()); } }
@Test public void valueOfKnownRealmName() { Realm testRealm = Realm.valueOf("OC1"); assertEquals(Realm.OC1, testRealm); assertSame(Realm.OC1, testRealm); }
@Test(expected = IllegalArgumentException.class) public void valueOfUnknownRealmName() { Realm.valueOf("foobar"); }