general example cleanup

This commit is contained in:
eugenp 2013-08-12 23:23:33 +03:00
parent 14c76d379a
commit 62292a5e5a
4 changed files with 6 additions and 112 deletions

View File

@ -2,7 +2,6 @@ package org.baeldung.ex.mappingexception.cause1.persistence.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@ -13,19 +12,10 @@ public class Foo implements Serializable {
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(nullable = false)
private String name;
public Foo() {
super();
}
public Foo(final String name) {
super();
this.name = name;
}
// API
public long getId() {
@ -36,46 +26,4 @@ public class Foo implements Serializable {
this.id = id;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
//
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Foo other = (Foo) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("Foo [name=").append(name).append("]");
return builder.toString();
}
}

View File

@ -2,7 +2,6 @@ package org.baeldung.ex.mappingexception.cause2.persistence.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@ -15,19 +14,10 @@ public class Foo implements Serializable {
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(nullable = false)
private String name;
public Foo() {
super();
}
public Foo(final String name) {
super();
this.name = name;
}
// API
public long getId() {
@ -38,46 +28,4 @@ public class Foo implements Serializable {
this.id = id;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
//
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Foo other = (Foo) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("Foo [name=").append(name).append("]");
return builder.toString();
}
}

View File

@ -1,9 +1,8 @@
package org.baeldung.ex.mappingexception;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import org.baeldung.ex.mappingexception.cause1.persistence.model.Foo;
import org.baeldung.ex.mappingexception.spring.Cause1PersistenceConfig;
import org.hibernate.MappingException;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -22,10 +21,10 @@ public class Cause1MappingExceptionIntegrationTest {
// tests
@Test
@Test(expected = MappingException.class)
@Transactional
public final void givenEntityIsPersisted_thenException() {
sessionFactory.getCurrentSession().saveOrUpdate(new Foo(randomAlphabetic(6)));
sessionFactory.getCurrentSession().saveOrUpdate(new Foo());
}
}

View File

@ -1,9 +1,8 @@
package org.baeldung.ex.mappingexception;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import org.baeldung.ex.mappingexception.cause2.persistence.model.Foo;
import org.baeldung.ex.mappingexception.spring.Cause2PersistenceConfig;
import org.hibernate.MappingException;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -22,10 +21,10 @@ public class Cause2MappingExceptionIntegrationTest {
// tests
@Test
@Test(expected = MappingException.class)
@Transactional
public final void givenEntityIsPersisted_thenException() {
sessionFactory.getCurrentSession().saveOrUpdate(new Foo(randomAlphabetic(6)));
sessionFactory.getCurrentSession().saveOrUpdate(new Foo());
}
}