Loading src/main/java/es/redmic/usersettingslib/dto/SettingsDTO.java 0 → 100644 +230 −0 Original line number Diff line number Diff line package es.redmic.usersettingslib.dto; /*- * #%L * user-settings-lib * %% * Copyright (C) 2019 REDMIC Project / Server * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import java.util.List; import javax.validation.constraints.NotNull; import org.apache.avro.Schema; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import com.fasterxml.jackson.annotation.JsonIgnore; import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaDefault; public class SettingsDTO extends SettingsBaseDTO { // @formatter:off @JsonIgnore public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse( "{\"type\":\"record\",\"name\":\"SettingsDTO\",\"namespace\":\"es.redmic.usersettingslib.dto\",\"fields\":[" + "{\"name\":\"name\",\"type\":[\"string\", \"null\"]}," + "{\"name\":\"shared\",\"type\":\"boolean\", \"default\": \"false\"}," + "{\"name\":\"userId\",\"type\":[\"string\", \"null\"]}," + "{\"name\": \"selection\",\"type\": [{\"type\": \"array\",\"items\":\"string\"},\"null\"]}," + "{\"name\":\"service\",\"type\":\"string\"}," + "{\"name\":\"inserted\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}]," + "\"default\": null}," + "{\"name\":\"updated\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}]," + "\"default\": null}," + "{\"name\":\"accessed\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}]," + "\"default\": null}," + "{\"name\":\"id\",\"type\":\"string\"}]}"); // @formatter:on public SettingsDTO() { super(); } private String name; @JsonSchemaDefault(value = "false") @NotNull private Boolean shared = false; private String userId; private List<String> selection; @NotNull private String service; public String getName() { return name; } public void setName(String name) { this.name = name; } public Boolean getShared() { return shared; } public void setShared(Boolean shared) { this.shared = shared; } public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public List<String> getSelection() { return selection; } public void setSelection(List<String> selection) { this.selection = selection; } public String getService() { return service; } public void setService(String service) { this.service = service; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((selection == null) ? 0 : selection.hashCode()); result = prime * result + ((service == null) ? 0 : service.hashCode()); result = prime * result + ((shared == null) ? 0 : shared.hashCode()); result = prime * result + ((userId == null) ? 0 : userId.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; SettingsDTO other = (SettingsDTO) obj; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (selection == null) { if (other.selection != null) return false; } else if (!selection.equals(other.selection)) return false; if (service == null) { if (other.service != null) return false; } else if (!service.equals(other.service)) return false; if (shared == null) { if (other.shared != null) return false; } else if (!shared.equals(other.shared)) return false; if (userId == null) { if (other.userId != null) return false; } else if (!userId.equals(other.userId)) return false; return true; } @JsonIgnore @Override public Schema getSchema() { return SCHEMA$; } @JsonIgnore @Override public Object get(int field) { switch (field) { case 0: return getName(); case 1: return getShared(); case 2: return getUserId(); case 3: return getSelection(); case 4: return getService(); case 5: return getInserted() != null ? getInserted().getMillis() : null; case 6: return getUpdated() != null ? getUpdated().getMillis() : null; case 7: return getAccessed() != null ? getAccessed().getMillis() : null; case 8: return getId(); default: throw new org.apache.avro.AvroRuntimeException("Bad index"); } } @SuppressWarnings({ "unchecked", "rawtypes" }) @JsonIgnore @Override public void put(int field, Object value) { switch (field) { case 0: setName(value != null ? value.toString() : null); break; case 1: setShared(value != null ? (boolean) value : null); break; case 2: setUserId(value != null ? value.toString() : null); break; case 3: setSelection(value != null ? (java.util.List) value : null); break; case 4: setService(value.toString()); break; case 5: setInserted(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 6: setUpdated(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 7: setAccessed(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 8: setId(value.toString()); break; default: throw new org.apache.avro.AvroRuntimeException("Bad index"); } } } src/test/java/es/redmic/usersettingslib/unit/dto/SettingsCheckAvroSchemaTest.java 0 → 100644 +46 −0 Original line number Diff line number Diff line package es.redmic.usersettingslib.unit.dto; /*- * #%L * user-settings-lib * %% * Copyright (C) 2019 REDMIC Project / Server * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import static org.junit.Assert.assertTrue; import org.json.JSONException; import org.junit.Test; import org.skyscreamer.jsonassert.JSONAssert; import es.redmic.testutils.utils.AvroBaseTest; import es.redmic.usersettingslib.dto.SettingsDTO; import es.redmic.usersettingslib.unit.utils.SettingsDataUtil; public class SettingsCheckAvroSchemaTest extends AvroBaseTest { @Test public void serializeAndDeserialize_IsSuccessful_IfSchemaAndDataAreCorrect() throws JSONException { SettingsDTO dto = SettingsDataUtil.getSettingsDTO(); Object result = serializerAndDeserializer(dto); assertTrue("El objeto obtenido debe ser una instancia de SettingsDTO", SettingsDTO.class.isInstance(result)); JSONAssert.assertEquals(result.toString(), dto.toString(), false); } } src/test/java/es/redmic/usersettingslib/unit/dto/SettingsCheckDTOValidationTest.java 0 → 100644 +61 −0 Original line number Diff line number Diff line package es.redmic.usersettingslib.unit.dto; /*- * #%L * user-settings-lib * %% * Copyright (C) 2019 REDMIC Project / Server * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import org.junit.Before; import org.junit.Test; import es.redmic.testutils.dto.DTOBaseTest; import es.redmic.usersettingslib.dto.SettingsDTO; import es.redmic.usersettingslib.unit.utils.SettingsDataUtil; public class SettingsCheckDTOValidationTest extends DTOBaseTest<SettingsDTO> { private static SettingsDTO dto; @Before public void reset() { dto = SettingsDataUtil.getSettingsDTO(); } @Test public void validationDTO_NoReturnError_IfDTOIsCorrect() { checkDTOHasNoError(dto); } @Test public void validationDTO_ReturnError_IfSharedIsNull() { dto.setShared(null); checkDTOHasError(dto, NOT_NULL_MESSAGE_TEMPLATE); } @Test public void validationDTO_ReturnError_IfServiceIsNull() { dto.setService(null); checkDTOHasError(dto, NOT_NULL_MESSAGE_TEMPLATE); } } src/test/java/es/redmic/usersettingslib/unit/dto/SettingsEqualTest.java 0 → 100644 +239 −0 Original line number Diff line number Diff line package es.redmic.usersettingslib.unit.dto; /*- * #%L * user-settings-lib * %% * Copyright (C) 2019 REDMIC Project / Server * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.joda.time.DateTime; import org.junit.Test; import es.redmic.usersettingslib.dto.SettingsDTO; import es.redmic.usersettingslib.unit.utils.SettingsDataUtil; public class SettingsEqualTest { @Test public void equal_returnTrue_IfSettingsTypeIsEqual() { SettingsDTO dto = SettingsDataUtil.getSettingsDTO(); assertTrue(dto.equals(dto)); } @Test public void equal_returnFalse_IfIdIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setId("111111"); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfIdIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setId(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfNameIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setName("cddd"); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfNameIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setName(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfSharedIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setShared(true); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfSharedIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setShared(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfUserIdIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setUserId("ddd"); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfUserIdIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setUserId(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfSelectionIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.getSelection().add("ddd"); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfSelectionIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setSelection(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfServiceIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setService("ddd"); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfServiceIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setService(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfInsertedIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setInserted(DateTime.now().plus(2)); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfInsertedIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setInserted(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfUpdatedIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setUpdated(DateTime.now().plus(2)); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfUpdatedIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setUpdated(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfAccessedIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setAccessed(DateTime.now().plus(2)); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfAccessedIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setAccessed(null); assertFalse(dto1.equals(dto2)); } } Loading
src/main/java/es/redmic/usersettingslib/dto/SettingsDTO.java 0 → 100644 +230 −0 Original line number Diff line number Diff line package es.redmic.usersettingslib.dto; /*- * #%L * user-settings-lib * %% * Copyright (C) 2019 REDMIC Project / Server * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import java.util.List; import javax.validation.constraints.NotNull; import org.apache.avro.Schema; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import com.fasterxml.jackson.annotation.JsonIgnore; import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaDefault; public class SettingsDTO extends SettingsBaseDTO { // @formatter:off @JsonIgnore public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse( "{\"type\":\"record\",\"name\":\"SettingsDTO\",\"namespace\":\"es.redmic.usersettingslib.dto\",\"fields\":[" + "{\"name\":\"name\",\"type\":[\"string\", \"null\"]}," + "{\"name\":\"shared\",\"type\":\"boolean\", \"default\": \"false\"}," + "{\"name\":\"userId\",\"type\":[\"string\", \"null\"]}," + "{\"name\": \"selection\",\"type\": [{\"type\": \"array\",\"items\":\"string\"},\"null\"]}," + "{\"name\":\"service\",\"type\":\"string\"}," + "{\"name\":\"inserted\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}]," + "\"default\": null}," + "{\"name\":\"updated\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}]," + "\"default\": null}," + "{\"name\":\"accessed\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}]," + "\"default\": null}," + "{\"name\":\"id\",\"type\":\"string\"}]}"); // @formatter:on public SettingsDTO() { super(); } private String name; @JsonSchemaDefault(value = "false") @NotNull private Boolean shared = false; private String userId; private List<String> selection; @NotNull private String service; public String getName() { return name; } public void setName(String name) { this.name = name; } public Boolean getShared() { return shared; } public void setShared(Boolean shared) { this.shared = shared; } public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public List<String> getSelection() { return selection; } public void setSelection(List<String> selection) { this.selection = selection; } public String getService() { return service; } public void setService(String service) { this.service = service; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((selection == null) ? 0 : selection.hashCode()); result = prime * result + ((service == null) ? 0 : service.hashCode()); result = prime * result + ((shared == null) ? 0 : shared.hashCode()); result = prime * result + ((userId == null) ? 0 : userId.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; SettingsDTO other = (SettingsDTO) obj; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (selection == null) { if (other.selection != null) return false; } else if (!selection.equals(other.selection)) return false; if (service == null) { if (other.service != null) return false; } else if (!service.equals(other.service)) return false; if (shared == null) { if (other.shared != null) return false; } else if (!shared.equals(other.shared)) return false; if (userId == null) { if (other.userId != null) return false; } else if (!userId.equals(other.userId)) return false; return true; } @JsonIgnore @Override public Schema getSchema() { return SCHEMA$; } @JsonIgnore @Override public Object get(int field) { switch (field) { case 0: return getName(); case 1: return getShared(); case 2: return getUserId(); case 3: return getSelection(); case 4: return getService(); case 5: return getInserted() != null ? getInserted().getMillis() : null; case 6: return getUpdated() != null ? getUpdated().getMillis() : null; case 7: return getAccessed() != null ? getAccessed().getMillis() : null; case 8: return getId(); default: throw new org.apache.avro.AvroRuntimeException("Bad index"); } } @SuppressWarnings({ "unchecked", "rawtypes" }) @JsonIgnore @Override public void put(int field, Object value) { switch (field) { case 0: setName(value != null ? value.toString() : null); break; case 1: setShared(value != null ? (boolean) value : null); break; case 2: setUserId(value != null ? value.toString() : null); break; case 3: setSelection(value != null ? (java.util.List) value : null); break; case 4: setService(value.toString()); break; case 5: setInserted(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 6: setUpdated(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 7: setAccessed(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null); break; case 8: setId(value.toString()); break; default: throw new org.apache.avro.AvroRuntimeException("Bad index"); } } }
src/test/java/es/redmic/usersettingslib/unit/dto/SettingsCheckAvroSchemaTest.java 0 → 100644 +46 −0 Original line number Diff line number Diff line package es.redmic.usersettingslib.unit.dto; /*- * #%L * user-settings-lib * %% * Copyright (C) 2019 REDMIC Project / Server * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import static org.junit.Assert.assertTrue; import org.json.JSONException; import org.junit.Test; import org.skyscreamer.jsonassert.JSONAssert; import es.redmic.testutils.utils.AvroBaseTest; import es.redmic.usersettingslib.dto.SettingsDTO; import es.redmic.usersettingslib.unit.utils.SettingsDataUtil; public class SettingsCheckAvroSchemaTest extends AvroBaseTest { @Test public void serializeAndDeserialize_IsSuccessful_IfSchemaAndDataAreCorrect() throws JSONException { SettingsDTO dto = SettingsDataUtil.getSettingsDTO(); Object result = serializerAndDeserializer(dto); assertTrue("El objeto obtenido debe ser una instancia de SettingsDTO", SettingsDTO.class.isInstance(result)); JSONAssert.assertEquals(result.toString(), dto.toString(), false); } }
src/test/java/es/redmic/usersettingslib/unit/dto/SettingsCheckDTOValidationTest.java 0 → 100644 +61 −0 Original line number Diff line number Diff line package es.redmic.usersettingslib.unit.dto; /*- * #%L * user-settings-lib * %% * Copyright (C) 2019 REDMIC Project / Server * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import org.junit.Before; import org.junit.Test; import es.redmic.testutils.dto.DTOBaseTest; import es.redmic.usersettingslib.dto.SettingsDTO; import es.redmic.usersettingslib.unit.utils.SettingsDataUtil; public class SettingsCheckDTOValidationTest extends DTOBaseTest<SettingsDTO> { private static SettingsDTO dto; @Before public void reset() { dto = SettingsDataUtil.getSettingsDTO(); } @Test public void validationDTO_NoReturnError_IfDTOIsCorrect() { checkDTOHasNoError(dto); } @Test public void validationDTO_ReturnError_IfSharedIsNull() { dto.setShared(null); checkDTOHasError(dto, NOT_NULL_MESSAGE_TEMPLATE); } @Test public void validationDTO_ReturnError_IfServiceIsNull() { dto.setService(null); checkDTOHasError(dto, NOT_NULL_MESSAGE_TEMPLATE); } }
src/test/java/es/redmic/usersettingslib/unit/dto/SettingsEqualTest.java 0 → 100644 +239 −0 Original line number Diff line number Diff line package es.redmic.usersettingslib.unit.dto; /*- * #%L * user-settings-lib * %% * Copyright (C) 2019 REDMIC Project / Server * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.joda.time.DateTime; import org.junit.Test; import es.redmic.usersettingslib.dto.SettingsDTO; import es.redmic.usersettingslib.unit.utils.SettingsDataUtil; public class SettingsEqualTest { @Test public void equal_returnTrue_IfSettingsTypeIsEqual() { SettingsDTO dto = SettingsDataUtil.getSettingsDTO(); assertTrue(dto.equals(dto)); } @Test public void equal_returnFalse_IfIdIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setId("111111"); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfIdIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setId(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfNameIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setName("cddd"); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfNameIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setName(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfSharedIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setShared(true); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfSharedIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setShared(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfUserIdIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setUserId("ddd"); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfUserIdIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setUserId(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfSelectionIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.getSelection().add("ddd"); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfSelectionIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setSelection(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfServiceIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setService("ddd"); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfServiceIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setService(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfInsertedIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setInserted(DateTime.now().plus(2)); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfInsertedIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setInserted(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfUpdatedIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setUpdated(DateTime.now().plus(2)); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfUpdatedIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setUpdated(null); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfAccessedIsDifferent() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setAccessed(DateTime.now().plus(2)); assertFalse(dto1.equals(dto2)); } @Test public void equal_returnFalse_IfAccessedIsNull() { SettingsDTO dto1 = SettingsDataUtil.getSettingsDTO(); SettingsDTO dto2 = SettingsDataUtil.getSettingsDTO(); dto1.setAccessed(null); assertFalse(dto1.equals(dto2)); } }