Initial commit
This commit is contained in:
commit
e4c00f10e8
37 changed files with 2512 additions and 0 deletions
63
commons/src/main/java/commons/Person.java
Normal file
63
commons/src/main/java/commons/Person.java
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright 2021 Delft University of Technology
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package commons;
|
||||
|
||||
import static org.apache.commons.lang3.builder.ToStringStyle.MULTI_LINE_STYLE;
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class Person {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
public long id;
|
||||
|
||||
public String firstName;
|
||||
public String lastName;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Person() {
|
||||
// for object mapper
|
||||
}
|
||||
|
||||
public Person(String firstName, String lastName) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this, MULTI_LINE_STYLE);
|
||||
}
|
||||
}
|
||||
66
commons/src/main/java/commons/Quote.java
Normal file
66
commons/src/main/java/commons/Quote.java
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright 2021 Delft University of Technology
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package commons;
|
||||
|
||||
import static org.apache.commons.lang3.builder.ToStringStyle.MULTI_LINE_STYLE;
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
public class Quote {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
public long id;
|
||||
|
||||
@OneToOne(cascade = CascadeType.PERSIST)
|
||||
public Person person;
|
||||
public String quote;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Quote() {
|
||||
// for object mappers
|
||||
}
|
||||
|
||||
public Quote(Person person, String quote) {
|
||||
this.person = person;
|
||||
this.quote = quote;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return EqualsBuilder.reflectionEquals(this, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return HashCodeBuilder.reflectionHashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this, MULTI_LINE_STYLE);
|
||||
}
|
||||
}
|
||||
56
commons/src/test/java/commons/PersonTest.java
Normal file
56
commons/src/test/java/commons/PersonTest.java
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright 2021 Delft University of Technology
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package commons;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class PersonTest {
|
||||
|
||||
@Test
|
||||
public void checkConstructor() {
|
||||
var p = new Person("f", "l");
|
||||
assertEquals("f", p.firstName);
|
||||
assertEquals("l", p.lastName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsHashCode() {
|
||||
var a = new Person("a", "b");
|
||||
var b = new Person("a", "b");
|
||||
assertEquals(a, b);
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notEqualsHashCode() {
|
||||
var a = new Person("a", "b");
|
||||
var b = new Person("a", "c");
|
||||
assertNotEquals(a, b);
|
||||
assertNotEquals(a.hashCode(), b.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasToString() {
|
||||
var actual = new Person("a", "b").toString();
|
||||
assertTrue(actual.contains(Person.class.getSimpleName()));
|
||||
assertTrue(actual.contains("\n"));
|
||||
assertTrue(actual.contains("firstName"));
|
||||
}
|
||||
}
|
||||
58
commons/src/test/java/commons/QuoteTest.java
Normal file
58
commons/src/test/java/commons/QuoteTest.java
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright 2021 Delft University of Technology
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package commons;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class QuoteTest {
|
||||
|
||||
private static final Person SOME_PERSON = new Person("a", "b");
|
||||
|
||||
@Test
|
||||
public void checkConstructor() {
|
||||
var q = new Quote(SOME_PERSON, "q");
|
||||
assertEquals(SOME_PERSON, q.person);
|
||||
assertEquals("q", q.quote);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsHashCode() {
|
||||
var a = new Quote(new Person("a", "b"), "c");
|
||||
var b = new Quote(new Person("a", "b"), "c");
|
||||
assertEquals(a, b);
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notEqualsHashCode() {
|
||||
var a = new Quote(new Person("a", "b"), "c");
|
||||
var b = new Quote(new Person("a", "b"), "d");
|
||||
assertNotEquals(a, b);
|
||||
assertNotEquals(a.hashCode(), b.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasToString() {
|
||||
var actual = new Quote(new Person("a", "b"), "c").toString();
|
||||
assertTrue(actual.contains(Quote.class.getSimpleName()));
|
||||
assertTrue(actual.contains("\n"));
|
||||
assertTrue(actual.contains("person"));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue