* Fix blocker issues on Sonar * Replace Assertj assertions with JUnit ones
This commit is contained in:
parent
1f1fcae513
commit
70f6e54353
@ -14,7 +14,8 @@
|
|||||||
*/
|
*/
|
||||||
package domainapp.dom.modules.simple;
|
package domainapp.dom.modules.simple;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -30,24 +31,18 @@ public class SimpleObjectTest {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
simpleObject = new SimpleObject();
|
simpleObject = new SimpleObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testName() throws Exception {
|
||||||
|
// given
|
||||||
|
String name = "Foobar";
|
||||||
|
assertNull(simpleObject.getName());
|
||||||
|
|
||||||
/**
|
// when
|
||||||
* Test for Names for SimpleObjects
|
simpleObject.setName(name);
|
||||||
*/
|
|
||||||
public static class Name extends SimpleObjectTest {
|
|
||||||
|
|
||||||
@Test
|
// then
|
||||||
public void happyCase() throws Exception {
|
assertEquals(name, simpleObject.getName());
|
||||||
// given
|
|
||||||
String name = "Foobar";
|
|
||||||
assertThat(simpleObject.getName()).isNull();
|
|
||||||
|
|
||||||
// when
|
|
||||||
simpleObject.setName(name);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(simpleObject.getName()).isEqualTo(name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,10 @@
|
|||||||
*/
|
*/
|
||||||
package domainapp.dom.modules.simple;
|
package domainapp.dom.modules.simple;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.isis.applib.DomainObjectContainer;
|
import org.apache.isis.applib.DomainObjectContainer;
|
||||||
import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
|
import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
|
||||||
@ -46,63 +47,52 @@ public class SimpleObjectsTest {
|
|||||||
simpleObjects = new SimpleObjects();
|
simpleObjects = new SimpleObjects();
|
||||||
simpleObjects.container = mockContainer;
|
simpleObjects.container = mockContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreate() throws Exception {
|
||||||
|
|
||||||
/**
|
// given
|
||||||
* Test Creation of Simple Objects
|
final SimpleObject simpleObject = new SimpleObject();
|
||||||
*/
|
|
||||||
public static class Create extends SimpleObjectsTest {
|
|
||||||
|
|
||||||
@Test
|
final Sequence seq = context.sequence("create");
|
||||||
public void happyCase() throws Exception {
|
context.checking(new Expectations() {
|
||||||
|
{
|
||||||
|
oneOf(mockContainer).newTransientInstance(SimpleObject.class);
|
||||||
|
inSequence(seq);
|
||||||
|
will(returnValue(simpleObject));
|
||||||
|
|
||||||
// given
|
oneOf(mockContainer).persistIfNotAlready(simpleObject);
|
||||||
final SimpleObject simpleObject = new SimpleObject();
|
inSequence(seq);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
final Sequence seq = context.sequence("create");
|
// when
|
||||||
context.checking(new Expectations() {
|
String objectName = "Foobar";
|
||||||
{
|
final SimpleObject obj = simpleObjects.create(objectName);
|
||||||
oneOf(mockContainer).newTransientInstance(SimpleObject.class);
|
|
||||||
inSequence(seq);
|
|
||||||
will(returnValue(simpleObject));
|
|
||||||
|
|
||||||
oneOf(mockContainer).persistIfNotAlready(simpleObject);
|
// then
|
||||||
inSequence(seq);
|
assertEquals(simpleObject, obj);
|
||||||
}
|
assertEquals(objectName, obj.getName());
|
||||||
});
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListAll() throws Exception {
|
||||||
|
|
||||||
// when
|
// given
|
||||||
final SimpleObject obj = simpleObjects.create("Foobar");
|
final List<SimpleObject> all = Lists.newArrayList();
|
||||||
|
|
||||||
// then
|
context.checking(new Expectations() {
|
||||||
assertThat(obj).isEqualTo(simpleObject);
|
{
|
||||||
assertThat(obj.getName()).isEqualTo("Foobar");
|
oneOf(mockContainer).allInstances(SimpleObject.class);
|
||||||
}
|
will(returnValue(all));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// when
|
||||||
|
final List<SimpleObject> list = simpleObjects.listAll();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertEquals(all, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test Listing of Simple Objects
|
|
||||||
*/
|
|
||||||
public static class ListAll extends SimpleObjectsTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void happyCase() throws Exception {
|
|
||||||
|
|
||||||
// given
|
|
||||||
final List<SimpleObject> all = Lists.newArrayList();
|
|
||||||
|
|
||||||
context.checking(new Expectations() {
|
|
||||||
{
|
|
||||||
oneOf(mockContainer).allInstances(SimpleObject.class);
|
|
||||||
will(returnValue(all));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// when
|
|
||||||
final List<SimpleObject> list = simpleObjects.listAll();
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(list).isEqualTo(all);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
package domainapp.integtests.tests.modules.simple;
|
package domainapp.integtests.tests.modules.simple;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import domainapp.dom.modules.simple.SimpleObject;
|
|
||||||
import domainapp.fixture.scenarios.RecreateSimpleObjects;
|
|
||||||
import domainapp.integtests.tests.SimpleAppIntegTest;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.apache.isis.applib.DomainObjectContainer;
|
import org.apache.isis.applib.DomainObjectContainer;
|
||||||
import org.apache.isis.applib.fixturescripts.FixtureScripts;
|
import org.apache.isis.applib.fixturescripts.FixtureScripts;
|
||||||
import org.apache.isis.applib.services.wrapper.DisabledException;
|
import org.apache.isis.applib.services.wrapper.DisabledException;
|
||||||
@ -31,6 +30,10 @@ import org.apache.isis.applib.services.wrapper.InvalidException;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import domainapp.dom.modules.simple.SimpleObject;
|
||||||
|
import domainapp.fixture.scenarios.RecreateSimpleObjects;
|
||||||
|
import domainapp.integtests.tests.SimpleAppIntegTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Fixtures with Simple Objects
|
* Test Fixtures with Simple Objects
|
||||||
*/
|
*/
|
||||||
@ -38,10 +41,14 @@ public class SimpleObjectIntegTest extends SimpleAppIntegTest {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FixtureScripts fixtureScripts;
|
FixtureScripts fixtureScripts;
|
||||||
|
@Inject
|
||||||
|
DomainObjectContainer container;
|
||||||
|
|
||||||
RecreateSimpleObjects fs;
|
RecreateSimpleObjects fs;
|
||||||
SimpleObject simpleObjectPojo;
|
SimpleObject simpleObjectPojo;
|
||||||
SimpleObject simpleObjectWrapped;
|
SimpleObject simpleObjectWrapped;
|
||||||
|
|
||||||
|
private static final String NEW_NAME = "new name";
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@ -51,80 +58,59 @@ public class SimpleObjectIntegTest extends SimpleAppIntegTest {
|
|||||||
|
|
||||||
simpleObjectPojo = fs.getSimpleObjects().get(0);
|
simpleObjectPojo = fs.getSimpleObjects().get(0);
|
||||||
|
|
||||||
assertThat(simpleObjectPojo).isNotNull();
|
assertNotNull(simpleObjectPojo);
|
||||||
simpleObjectWrapped = wrap(simpleObjectPojo);
|
simpleObjectWrapped = wrap(simpleObjectPojo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Test
|
||||||
* Test Object Name accessibility
|
public void testNameAccessible() throws Exception {
|
||||||
*/
|
// when
|
||||||
public static class Name extends SimpleObjectIntegTest {
|
final String name = simpleObjectWrapped.getName();
|
||||||
|
// then
|
||||||
@Test
|
assertEquals(fs.names.get(0), name);
|
||||||
public void accessible() throws Exception {
|
|
||||||
// when
|
|
||||||
final String name = simpleObjectWrapped.getName();
|
|
||||||
// then
|
|
||||||
assertThat(name).isEqualTo(fs.names.get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void cannotBeUpdatedDirectly() throws Exception {
|
|
||||||
|
|
||||||
// expect
|
|
||||||
expectedExceptions.expect(DisabledException.class);
|
|
||||||
|
|
||||||
// when
|
|
||||||
simpleObjectWrapped.setName("new name");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNameCannotBeUpdatedDirectly() throws Exception {
|
||||||
|
|
||||||
/**
|
// expect
|
||||||
* Test Validation of SimpleObject Names
|
expectedExceptions.expect(DisabledException.class);
|
||||||
*/
|
|
||||||
public static class UpdateName extends SimpleObjectIntegTest {
|
|
||||||
|
|
||||||
@Test
|
// when
|
||||||
public void happyCase() throws Exception {
|
simpleObjectWrapped.setName(NEW_NAME);
|
||||||
|
|
||||||
// when
|
|
||||||
simpleObjectWrapped.updateName("new name");
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(simpleObjectWrapped.getName()).isEqualTo("new name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void failsValidation() throws Exception {
|
|
||||||
|
|
||||||
// expect
|
|
||||||
expectedExceptions.expect(InvalidException.class);
|
|
||||||
expectedExceptions.expectMessage("Exclamation mark is not allowed");
|
|
||||||
|
|
||||||
// when
|
|
||||||
simpleObjectWrapped.updateName("new name!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateName() throws Exception {
|
||||||
|
|
||||||
/**
|
// when
|
||||||
* Test ContainerTitle generation based on SimpleObject Name
|
simpleObjectWrapped.updateName(NEW_NAME);
|
||||||
*/
|
|
||||||
public static class Title extends SimpleObjectIntegTest {
|
|
||||||
|
|
||||||
@Inject
|
// then
|
||||||
DomainObjectContainer container;
|
assertEquals(NEW_NAME, simpleObjectWrapped.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateNameFailsValidation() throws Exception {
|
||||||
|
|
||||||
@Test
|
// expect
|
||||||
public void interpolatesName() throws Exception {
|
expectedExceptions.expect(InvalidException.class);
|
||||||
|
expectedExceptions.expectMessage("Exclamation mark is not allowed");
|
||||||
|
|
||||||
// given
|
// when
|
||||||
final String name = simpleObjectWrapped.getName();
|
simpleObjectWrapped.updateName(NEW_NAME + "!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInterpolatesName() throws Exception {
|
||||||
|
|
||||||
// when
|
// given
|
||||||
final String title = container.titleOf(simpleObjectWrapped);
|
final String name = simpleObjectWrapped.getName();
|
||||||
|
|
||||||
// then
|
// when
|
||||||
assertThat(title).isEqualTo("Object: " + name);
|
final String title = container.titleOf(simpleObjectWrapped);
|
||||||
}
|
|
||||||
|
// then
|
||||||
|
assertEquals("Object: " + name, title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,17 +18,13 @@
|
|||||||
*/
|
*/
|
||||||
package domainapp.integtests.tests.modules.simple;
|
package domainapp.integtests.tests.modules.simple;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import domainapp.dom.modules.simple.SimpleObject;
|
|
||||||
import domainapp.dom.modules.simple.SimpleObjects;
|
|
||||||
import domainapp.fixture.modules.simple.SimpleObjectsTearDown;
|
|
||||||
import domainapp.fixture.scenarios.RecreateSimpleObjects;
|
|
||||||
import domainapp.integtests.tests.SimpleAppIntegTest;
|
|
||||||
import java.sql.SQLIntegrityConstraintViolationException;
|
import java.sql.SQLIntegrityConstraintViolationException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.apache.isis.applib.fixturescripts.FixtureScript;
|
import org.apache.isis.applib.fixturescripts.FixtureScript;
|
||||||
import org.apache.isis.applib.fixturescripts.FixtureScripts;
|
import org.apache.isis.applib.fixturescripts.FixtureScripts;
|
||||||
import org.hamcrest.Description;
|
import org.hamcrest.Description;
|
||||||
@ -36,6 +32,14 @@ import org.hamcrest.Matcher;
|
|||||||
import org.hamcrest.TypeSafeMatcher;
|
import org.hamcrest.TypeSafeMatcher;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
|
||||||
|
import domainapp.dom.modules.simple.SimpleObject;
|
||||||
|
import domainapp.dom.modules.simple.SimpleObjects;
|
||||||
|
import domainapp.fixture.modules.simple.SimpleObjectsTearDown;
|
||||||
|
import domainapp.fixture.scenarios.RecreateSimpleObjects;
|
||||||
|
import domainapp.integtests.tests.SimpleAppIntegTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fixture Pattern Integration Test
|
* Fixture Pattern Integration Test
|
||||||
*/
|
*/
|
||||||
@ -46,104 +50,90 @@ public class SimpleObjectsIntegTest extends SimpleAppIntegTest {
|
|||||||
@Inject
|
@Inject
|
||||||
SimpleObjects simpleObjects;
|
SimpleObjects simpleObjects;
|
||||||
|
|
||||||
/**
|
@Test
|
||||||
* Test Listing of All Simple Objects
|
public void testListAll() throws Exception {
|
||||||
*/
|
|
||||||
public static class ListAll extends SimpleObjectsIntegTest {
|
|
||||||
|
|
||||||
@Test
|
// given
|
||||||
public void happyCase() throws Exception {
|
RecreateSimpleObjects fs = new RecreateSimpleObjects();
|
||||||
|
fixtureScripts.runFixtureScript(fs, null);
|
||||||
|
nextTransaction();
|
||||||
|
|
||||||
// given
|
// when
|
||||||
RecreateSimpleObjects fs = new RecreateSimpleObjects();
|
final List<SimpleObject> all = wrap(simpleObjects).listAll();
|
||||||
fixtureScripts.runFixtureScript(fs, null);
|
|
||||||
nextTransaction();
|
|
||||||
|
|
||||||
// when
|
// then
|
||||||
final List<SimpleObject> all = wrap(simpleObjects).listAll();
|
assertEquals(fs.getSimpleObjects().size(), all.size());
|
||||||
|
|
||||||
// then
|
SimpleObject simpleObject = wrap(all.get(0));
|
||||||
assertThat(all).hasSize(fs.getSimpleObjects().size());
|
assertEquals(fs.getSimpleObjects().get(0).getName(), simpleObject.getName());
|
||||||
|
|
||||||
SimpleObject simpleObject = wrap(all.get(0));
|
|
||||||
assertThat(simpleObject.getName()).isEqualTo(fs.getSimpleObjects().get(0).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenNone() throws Exception {
|
|
||||||
|
|
||||||
// given
|
|
||||||
FixtureScript fs = new SimpleObjectsTearDown();
|
|
||||||
fixtureScripts.runFixtureScript(fs, null);
|
|
||||||
nextTransaction();
|
|
||||||
|
|
||||||
// when
|
|
||||||
final List<SimpleObject> all = wrap(simpleObjects).listAll();
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(all).hasSize(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListAllWhenNone() throws Exception {
|
||||||
|
|
||||||
|
// given
|
||||||
|
FixtureScript fs = new SimpleObjectsTearDown();
|
||||||
|
fixtureScripts.runFixtureScript(fs, null);
|
||||||
|
nextTransaction();
|
||||||
|
|
||||||
/**
|
// when
|
||||||
* Test Creation of Simple Objects
|
final List<SimpleObject> all = wrap(simpleObjects).listAll();
|
||||||
*/
|
|
||||||
public static class Create extends SimpleObjectsIntegTest {
|
|
||||||
|
|
||||||
@Test
|
// then
|
||||||
public void happyCase() throws Exception {
|
assertEquals(0, all.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreate() throws Exception {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
FixtureScript fs = new SimpleObjectsTearDown();
|
FixtureScript fs = new SimpleObjectsTearDown();
|
||||||
fixtureScripts.runFixtureScript(fs, null);
|
fixtureScripts.runFixtureScript(fs, null);
|
||||||
nextTransaction();
|
nextTransaction();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
wrap(simpleObjects).create("Faz");
|
wrap(simpleObjects).create("Faz");
|
||||||
|
|
||||||
// then
|
// then
|
||||||
final List<SimpleObject> all = wrap(simpleObjects).listAll();
|
final List<SimpleObject> all = wrap(simpleObjects).listAll();
|
||||||
assertThat(all).hasSize(1);
|
assertEquals(1, all.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateWhenAlreadyExists() throws Exception {
|
||||||
|
|
||||||
@Test
|
// given
|
||||||
public void whenAlreadyExists() throws Exception {
|
FixtureScript fs = new SimpleObjectsTearDown();
|
||||||
|
fixtureScripts.runFixtureScript(fs, null);
|
||||||
|
nextTransaction();
|
||||||
|
wrap(simpleObjects).create("Faz");
|
||||||
|
nextTransaction();
|
||||||
|
|
||||||
// given
|
// then
|
||||||
FixtureScript fs = new SimpleObjectsTearDown();
|
expectedExceptions.expectCause(causalChainContains(SQLIntegrityConstraintViolationException.class));
|
||||||
fixtureScripts.runFixtureScript(fs, null);
|
|
||||||
nextTransaction();
|
|
||||||
wrap(simpleObjects).create("Faz");
|
|
||||||
nextTransaction();
|
|
||||||
|
|
||||||
// then
|
// when
|
||||||
expectedExceptions.expectCause(causalChainContains(SQLIntegrityConstraintViolationException.class));
|
wrap(simpleObjects).create("Faz");
|
||||||
|
nextTransaction();
|
||||||
// when
|
}
|
||||||
wrap(simpleObjects).create("Faz");
|
|
||||||
nextTransaction();
|
private static Matcher<? extends Throwable> causalChainContains(final Class<?> cls) {
|
||||||
}
|
return new TypeSafeMatcher<Throwable>() {
|
||||||
|
@Override
|
||||||
private static Matcher<? extends Throwable> causalChainContains(final Class<?> cls) {
|
protected boolean matchesSafely(Throwable item) {
|
||||||
return new TypeSafeMatcher<Throwable>() {
|
final List<Throwable> causalChain = Throwables.getCausalChain(item);
|
||||||
@Override
|
for (Throwable throwable : causalChain) {
|
||||||
protected boolean matchesSafely(Throwable item) {
|
if (cls.isAssignableFrom(throwable.getClass())) {
|
||||||
final List<Throwable> causalChain = Throwables.getCausalChain(item);
|
return true;
|
||||||
for (Throwable throwable : causalChain) {
|
|
||||||
if (cls.isAssignableFrom(throwable.getClass())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void describeTo(Description description) {
|
public void describeTo(Description description) {
|
||||||
description.appendText("exception with causal chain containing " + cls.getSimpleName());
|
description.appendText("exception with causal chain containing " + cls.getSimpleName());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user