From 75bcbc06e117199fc9331cd9d8ade92deda4b727 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Fri, 25 Apr 2014 15:19:50 +1200 Subject: [PATCH] #53 - Add test for protected constructor --- .../contructor/TestProtectedConstructor.java | 27 +++++++++++++ .../model/basic/MProtectedConstructBean.java | 38 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/test/java/com/avaje/tests/contructor/TestProtectedConstructor.java create mode 100644 src/test/java/com/avaje/tests/model/basic/MProtectedConstructBean.java diff --git a/src/test/java/com/avaje/tests/contructor/TestProtectedConstructor.java b/src/test/java/com/avaje/tests/contructor/TestProtectedConstructor.java new file mode 100644 index 000000000..c1ad1c224 --- /dev/null +++ b/src/test/java/com/avaje/tests/contructor/TestProtectedConstructor.java @@ -0,0 +1,27 @@ +package com.avaje.tests.contructor; + +import org.junit.Assert; +import org.junit.Test; + +import com.avaje.ebean.BaseTestCase; +import com.avaje.ebean.Ebean; +import com.avaje.ebean.EbeanServer; +import com.avaje.tests.model.basic.MProtectedConstructBean; + +public class TestProtectedConstructor extends BaseTestCase { + + @Test + public void test() { + + EbeanServer server = Ebean.getServer(null); + + // check that we can construc a bean with a protected constructor + MProtectedConstructBean bean = server.createEntityBean(MProtectedConstructBean.class); + Assert.assertNotNull(bean); + + // Note1 that the enhancement ClassAdapterEntity line 239 makes a default constructor publically accessible + // Note2 the ClassAdpater will call DefaultConstructor.add() to add a default constructor if it doesn't exist + + } + +} diff --git a/src/test/java/com/avaje/tests/model/basic/MProtectedConstructBean.java b/src/test/java/com/avaje/tests/model/basic/MProtectedConstructBean.java new file mode 100644 index 000000000..a4bdb94da --- /dev/null +++ b/src/test/java/com/avaje/tests/model/basic/MProtectedConstructBean.java @@ -0,0 +1,38 @@ +package com.avaje.tests.model.basic; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class MProtectedConstructBean { + + @Id + Long id; + + String name; + +// private MProtectedConstructBean() { +// +// } + + public MProtectedConstructBean(String name){ + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +}