return null instead of an empty set.

This commit is contained in:
Michael Gerber 2015-10-14 13:46:59 +02:00
parent 2b6fcc05e1
commit f8effaee58
3 changed files with 38 additions and 4 deletions

View file

@ -611,12 +611,16 @@ public class RealmRepresentation {
}
public Set<String> getSupportedLocales() {
if(supportedLocales == null){
supportedLocales = new HashSet<String>();
}
return supportedLocales;
}
public void addSupportedLocales(String locale) {
if(supportedLocales == null){
supportedLocales = new HashSet<>();
}
supportedLocales.add(locale);
}
public void setSupportedLocales(Set<String> supportedLocales) {
this.supportedLocales = supportedLocales;
}

View file

@ -210,7 +210,10 @@ public class ModelToRepresentation {
}
rep.setInternationalizationEnabled(realm.isInternationalizationEnabled());
rep.getSupportedLocales().addAll(realm.getSupportedLocales());
if(realm.getSupportedLocales() != null){
rep.setSupportedLocales(new HashSet<String>());
rep.getSupportedLocales().addAll(realm.getSupportedLocales());
}
rep.setDefaultLocale(realm.getDefaultLocale());
if (internal) {
exportAuthenticationFlows(realm, rep);

View file

@ -15,6 +15,8 @@ import java.io.IOException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.HashSet;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@ -102,6 +104,31 @@ public class RealmTest extends AbstractClientTest {
assertEquals(Boolean.FALSE, rep.isEditUsernameAllowed());
}
@Test
public void updateRealmWithNewRepresentation() {
// first change
RealmRepresentation rep = new RealmRepresentation();
rep.setEditUsernameAllowed(true);
rep.setSupportedLocales(new HashSet<>(Arrays.asList("en", "de")));
realm.update(rep);
rep = realm.toRepresentation();
assertEquals(Boolean.TRUE, rep.isEditUsernameAllowed());
assertEquals(2, rep.getSupportedLocales().size());
// second change
rep = new RealmRepresentation();
rep.setEditUsernameAllowed(false);
realm.update(rep);
rep = realm.toRepresentation();
assertEquals(Boolean.FALSE, rep.isEditUsernameAllowed());
assertEquals(2, rep.getSupportedLocales().size());
}
@Test
public void getRealmRepresentation() {
RealmRepresentation rep = realm.toRepresentation();