Skip to content

Commit 62292a5

Browse files
author
eugenp
committed
general example cleanup
1 parent 14c76d3 commit 62292a5

File tree

4 files changed

+6
-112
lines changed

4 files changed

+6
-112
lines changed

spring-exceptions/src/main/java/org/baeldung/ex/mappingexception/cause1/persistence/model/Foo.java

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.Serializable;
44

5-
import javax.persistence.Column;
65
import javax.persistence.GeneratedValue;
76
import javax.persistence.GenerationType;
87
import javax.persistence.Id;
@@ -13,19 +12,10 @@ public class Foo implements Serializable {
1312
@GeneratedValue(strategy = GenerationType.AUTO)
1413
private long id;
1514

16-
@Column(nullable = false)
17-
private String name;
18-
1915
public Foo() {
2016
super();
2117
}
2218

23-
public Foo(final String name) {
24-
super();
25-
26-
this.name = name;
27-
}
28-
2919
// API
3020

3121
public long getId() {
@@ -36,46 +26,4 @@ public void setId(final long id) {
3626
this.id = id;
3727
}
3828

39-
public String getName() {
40-
return name;
41-
}
42-
43-
public void setName(final String name) {
44-
this.name = name;
45-
}
46-
47-
//
48-
49-
@Override
50-
public int hashCode() {
51-
final int prime = 31;
52-
int result = 1;
53-
result = prime * result + ((name == null) ? 0 : name.hashCode());
54-
return result;
55-
}
56-
57-
@Override
58-
public boolean equals(final Object obj) {
59-
if (this == obj)
60-
return true;
61-
if (obj == null)
62-
return false;
63-
if (getClass() != obj.getClass())
64-
return false;
65-
final Foo other = (Foo) obj;
66-
if (name == null) {
67-
if (other.name != null)
68-
return false;
69-
} else if (!name.equals(other.name))
70-
return false;
71-
return true;
72-
}
73-
74-
@Override
75-
public String toString() {
76-
final StringBuilder builder = new StringBuilder();
77-
builder.append("Foo [name=").append(name).append("]");
78-
return builder.toString();
79-
}
80-
8129
}

spring-exceptions/src/main/java/org/baeldung/ex/mappingexception/cause2/persistence/model/Foo.java

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.Serializable;
44

5-
import javax.persistence.Column;
65
import javax.persistence.Entity;
76
import javax.persistence.GeneratedValue;
87
import javax.persistence.GenerationType;
@@ -15,19 +14,10 @@ public class Foo implements Serializable {
1514
@GeneratedValue(strategy = GenerationType.AUTO)
1615
private long id;
1716

18-
@Column(nullable = false)
19-
private String name;
20-
2117
public Foo() {
2218
super();
2319
}
2420

25-
public Foo(final String name) {
26-
super();
27-
28-
this.name = name;
29-
}
30-
3121
// API
3222

3323
public long getId() {
@@ -38,46 +28,4 @@ public void setId(final long id) {
3828
this.id = id;
3929
}
4030

41-
public String getName() {
42-
return name;
43-
}
44-
45-
public void setName(final String name) {
46-
this.name = name;
47-
}
48-
49-
//
50-
51-
@Override
52-
public int hashCode() {
53-
final int prime = 31;
54-
int result = 1;
55-
result = prime * result + ((name == null) ? 0 : name.hashCode());
56-
return result;
57-
}
58-
59-
@Override
60-
public boolean equals(final Object obj) {
61-
if (this == obj)
62-
return true;
63-
if (obj == null)
64-
return false;
65-
if (getClass() != obj.getClass())
66-
return false;
67-
final Foo other = (Foo) obj;
68-
if (name == null) {
69-
if (other.name != null)
70-
return false;
71-
} else if (!name.equals(other.name))
72-
return false;
73-
return true;
74-
}
75-
76-
@Override
77-
public String toString() {
78-
final StringBuilder builder = new StringBuilder();
79-
builder.append("Foo [name=").append(name).append("]");
80-
return builder.toString();
81-
}
82-
8331
}

spring-exceptions/src/test/java/org/baeldung/ex/mappingexception/Cause1MappingExceptionIntegrationTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.baeldung.ex.mappingexception;
22

3-
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
4-
53
import org.baeldung.ex.mappingexception.cause1.persistence.model.Foo;
64
import org.baeldung.ex.mappingexception.spring.Cause1PersistenceConfig;
5+
import org.hibernate.MappingException;
76
import org.hibernate.SessionFactory;
87
import org.junit.Test;
98
import org.junit.runner.RunWith;
@@ -22,10 +21,10 @@ public class Cause1MappingExceptionIntegrationTest {
2221

2322
// tests
2423

25-
@Test
24+
@Test(expected = MappingException.class)
2625
@Transactional
2726
public final void givenEntityIsPersisted_thenException() {
28-
sessionFactory.getCurrentSession().saveOrUpdate(new Foo(randomAlphabetic(6)));
27+
sessionFactory.getCurrentSession().saveOrUpdate(new Foo());
2928
}
3029

3130
}

spring-exceptions/src/test/java/org/baeldung/ex/mappingexception/Cause2MappingExceptionIntegrationTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.baeldung.ex.mappingexception;
22

3-
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
4-
53
import org.baeldung.ex.mappingexception.cause2.persistence.model.Foo;
64
import org.baeldung.ex.mappingexception.spring.Cause2PersistenceConfig;
5+
import org.hibernate.MappingException;
76
import org.hibernate.SessionFactory;
87
import org.junit.Test;
98
import org.junit.runner.RunWith;
@@ -22,10 +21,10 @@ public class Cause2MappingExceptionIntegrationTest {
2221

2322
// tests
2423

25-
@Test
24+
@Test(expected = MappingException.class)
2625
@Transactional
2726
public final void givenEntityIsPersisted_thenException() {
28-
sessionFactory.getCurrentSession().saveOrUpdate(new Foo(randomAlphabetic(6)));
27+
sessionFactory.getCurrentSession().saveOrUpdate(new Foo());
2928
}
3029

3130
}

0 commit comments

Comments
 (0)