mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
Change Database.beanState() to throw IllegalArgumentException when bean isn't an entity bean
This commit is contained in:
1 parent
7862648b83
commit
a61c73c62a
4 files changed
+23
-19
No files matched your search
@@ -138,7 +138,6 @@ public interface BeanState {
|
|||||||
/**
|
/**
|
||||||
* Returns a map with load errors.
|
* Returns a map with load errors.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
|
||||||
Map<String, Exception> loadErrors();
|
Map<String, Exception> loadErrors();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,11 +9,7 @@ import javax.persistence.PersistenceException;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
@@ -1164,7 +1160,7 @@ public final class EntityBeanIntercept implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public Map<String, Exception> getLoadErrors() {
|
public Map<String, Exception> getLoadErrors() {
|
||||||
if (loadErrors == null) {
|
if (loadErrors == null) {
|
||||||
return null;
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
Map<String, Exception> ret = null;
|
Map<String, Exception> ret = null;
|
||||||
int len = getPropertyLength();
|
int len = getPropertyLength();
|
||||||
|
|||||||
@@ -497,8 +497,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
|||||||
if (bean instanceof EntityBean) {
|
if (bean instanceof EntityBean) {
|
||||||
return new DefaultBeanState((EntityBean) bean);
|
return new DefaultBeanState((EntityBean) bean);
|
||||||
}
|
}
|
||||||
// Not an entity bean
|
throw new IllegalArgumentException("Bean is not an entity bean");
|
||||||
return null; // throw new IllegalArgumentException("Bean is not an entity bean");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,11 +16,24 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
|
||||||
public class TestBeanState extends BaseTestCase {
|
class TestBeanState extends BaseTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
void invalid() {
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> DB.beanState(new Object()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void loadErrors_when_empty() {
|
||||||
|
ResetBasicData.reset();
|
||||||
|
Customer one = DB.find(Customer.class).setMaxRows(1).findOne();
|
||||||
|
BeanState beanState = DB.beanState(one);
|
||||||
|
|
||||||
|
assertThat(beanState.loadErrors()).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test() {
|
||||||
ResetBasicData.reset();
|
ResetBasicData.reset();
|
||||||
|
|
||||||
List<Customer> custs = DB.find(Customer.class).findList();
|
List<Customer> custs = DB.find(Customer.class).findList();
|
||||||
@@ -55,8 +68,7 @@ public class TestBeanState extends BaseTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setDisableLazyLoad_expect_lazyLoadingDisabled() {
|
void setDisableLazyLoad_expect_lazyLoadingDisabled() {
|
||||||
|
|
||||||
ResetBasicData.reset();
|
ResetBasicData.reset();
|
||||||
|
|
||||||
List<Customer> custs = DB.find(Customer.class).order("id").findList();
|
List<Customer> custs = DB.find(Customer.class).order("id").findList();
|
||||||
@@ -73,8 +85,7 @@ public class TestBeanState extends BaseTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getChangedProps_when_setManyProperty() {
|
void changedProps_when_setManyProperty() {
|
||||||
|
|
||||||
ResetBasicData.reset();
|
ResetBasicData.reset();
|
||||||
|
|
||||||
Customer customer = DB.find(Customer.class).order("id").setMaxRows(1).findOne();
|
Customer customer = DB.find(Customer.class).order("id").setMaxRows(1).findOne();
|
||||||
@@ -87,8 +98,7 @@ public class TestBeanState extends BaseTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getChangedProps_when_setManyProperty_onNewBean() {
|
void changedProps_when_setManyProperty_onNewBean() {
|
||||||
|
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
|
|
||||||
BeanState beanState = DB.beanState(customer);
|
BeanState beanState = DB.beanState(customer);
|
||||||
@@ -107,7 +117,7 @@ public class TestBeanState extends BaseTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readOnly_when_setManyProperty() {
|
void readOnly_when_setManyProperty() {
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
customer.setContacts(new ArrayList<>());
|
customer.setContacts(new ArrayList<>());
|
||||||
|
|
||||||
@@ -120,7 +130,7 @@ public class TestBeanState extends BaseTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readOnly_when_setProperty() {
|
void readOnly_when_setProperty() {
|
||||||
Customer customer = new Customer();
|
Customer customer = new Customer();
|
||||||
customer.setName("a");
|
customer.setName("a");
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user