提交 70f6e543 编写于 作者: S staillebois 提交者: Narendra Pathai

Fix blocker issues on Sonar #508 (#810)

* Fix blocker issues on Sonar

* Replace Assertj assertions with JUnit ones
上级 1f1fcae5
...@@ -14,7 +14,8 @@ ...@@ -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;
...@@ -31,23 +32,17 @@ public class SimpleObjectTest { ...@@ -31,23 +32,17 @@ public class SimpleObjectTest {
simpleObject = new SimpleObject(); simpleObject = new SimpleObject();
} }
/**
* Test for Names for SimpleObjects
*/
public static class Name extends SimpleObjectTest {
@Test @Test
public void happyCase() throws Exception { public void testName() throws Exception {
// given // given
String name = "Foobar"; String name = "Foobar";
assertThat(simpleObject.getName()).isNull(); assertNull(simpleObject.getName());
// when // when
simpleObject.setName(name); simpleObject.setName(name);
// then // then
assertThat(simpleObject.getName()).isEqualTo(name); assertEquals(name, simpleObject.getName());
}
} }
} }
...@@ -14,9 +14,10 @@ ...@@ -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;
...@@ -47,13 +48,8 @@ public class SimpleObjectsTest { ...@@ -47,13 +48,8 @@ public class SimpleObjectsTest {
simpleObjects.container = mockContainer; simpleObjects.container = mockContainer;
} }
/**
* Test Creation of Simple Objects
*/
public static class Create extends SimpleObjectsTest {
@Test @Test
public void happyCase() throws Exception { public void testCreate() throws Exception {
// given // given
final SimpleObject simpleObject = new SimpleObject(); final SimpleObject simpleObject = new SimpleObject();
...@@ -71,22 +67,16 @@ public class SimpleObjectsTest { ...@@ -71,22 +67,16 @@ public class SimpleObjectsTest {
}); });
// when // when
final SimpleObject obj = simpleObjects.create("Foobar"); String objectName = "Foobar";
final SimpleObject obj = simpleObjects.create(objectName);
// then // then
assertThat(obj).isEqualTo(simpleObject); assertEquals(simpleObject, obj);
assertThat(obj.getName()).isEqualTo("Foobar"); assertEquals(objectName, obj.getName());
} }
}
/**
* Test Listing of Simple Objects
*/
public static class ListAll extends SimpleObjectsTest {
@Test @Test
public void happyCase() throws Exception { public void testListAll() throws Exception {
// given // given
final List<SimpleObject> all = Lists.newArrayList(); final List<SimpleObject> all = Lists.newArrayList();
...@@ -102,7 +92,7 @@ public class SimpleObjectsTest { ...@@ -102,7 +92,7 @@ public class SimpleObjectsTest {
final List<SimpleObject> list = simpleObjects.listAll(); final List<SimpleObject> list = simpleObjects.listAll();
// then // then
assertThat(list).isEqualTo(all); assertEquals(all, list);
}
} }
} }
...@@ -18,12 +18,11 @@ ...@@ -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; ...@@ -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,11 +41,15 @@ public class SimpleObjectIntegTest extends SimpleAppIntegTest { ...@@ -38,11 +41,15 @@ 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 {
// given // given
...@@ -51,71 +58,51 @@ public class SimpleObjectIntegTest extends SimpleAppIntegTest { ...@@ -51,71 +58,51 @@ 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 Object Name accessibility
*/
public static class Name extends SimpleObjectIntegTest {
@Test @Test
public void accessible() throws Exception { public void testNameAccessible() throws Exception {
// when // when
final String name = simpleObjectWrapped.getName(); final String name = simpleObjectWrapped.getName();
// then // then
assertThat(name).isEqualTo(fs.names.get(0)); assertEquals(fs.names.get(0), name);
} }
@Test @Test
public void cannotBeUpdatedDirectly() throws Exception { public void testNameCannotBeUpdatedDirectly() throws Exception {
// expect // expect
expectedExceptions.expect(DisabledException.class); expectedExceptions.expect(DisabledException.class);
// when // when
simpleObjectWrapped.setName("new name"); simpleObjectWrapped.setName(NEW_NAME);
}
} }
/**
* Test Validation of SimpleObject Names
*/
public static class UpdateName extends SimpleObjectIntegTest {
@Test @Test
public void happyCase() throws Exception { public void testUpdateName() throws Exception {
// when // when
simpleObjectWrapped.updateName("new name"); simpleObjectWrapped.updateName(NEW_NAME);
// then // then
assertThat(simpleObjectWrapped.getName()).isEqualTo("new name"); assertEquals(NEW_NAME, simpleObjectWrapped.getName());
} }
@Test @Test
public void failsValidation() throws Exception { public void testUpdateNameFailsValidation() throws Exception {
// expect // expect
expectedExceptions.expect(InvalidException.class); expectedExceptions.expect(InvalidException.class);
expectedExceptions.expectMessage("Exclamation mark is not allowed"); expectedExceptions.expectMessage("Exclamation mark is not allowed");
// when // when
simpleObjectWrapped.updateName("new name!"); simpleObjectWrapped.updateName(NEW_NAME + "!");
}
} }
/**
* Test ContainerTitle generation based on SimpleObject Name
*/
public static class Title extends SimpleObjectIntegTest {
@Inject
DomainObjectContainer container;
@Test @Test
public void interpolatesName() throws Exception { public void testInterpolatesName() throws Exception {
// given // given
final String name = simpleObjectWrapped.getName(); final String name = simpleObjectWrapped.getName();
...@@ -124,7 +111,6 @@ public class SimpleObjectIntegTest extends SimpleAppIntegTest { ...@@ -124,7 +111,6 @@ public class SimpleObjectIntegTest extends SimpleAppIntegTest {
final String title = container.titleOf(simpleObjectWrapped); final String title = container.titleOf(simpleObjectWrapped);
// then // then
assertThat(title).isEqualTo("Object: " + name); assertEquals("Object: " + name, title);
}
} }
} }
...@@ -18,17 +18,13 @@ ...@@ -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; ...@@ -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,13 +50,8 @@ public class SimpleObjectsIntegTest extends SimpleAppIntegTest { ...@@ -46,13 +50,8 @@ public class SimpleObjectsIntegTest extends SimpleAppIntegTest {
@Inject @Inject
SimpleObjects simpleObjects; SimpleObjects simpleObjects;
/**
* Test Listing of All Simple Objects
*/
public static class ListAll extends SimpleObjectsIntegTest {
@Test @Test
public void happyCase() throws Exception { public void testListAll() throws Exception {
// given // given
RecreateSimpleObjects fs = new RecreateSimpleObjects(); RecreateSimpleObjects fs = new RecreateSimpleObjects();
...@@ -63,14 +62,14 @@ public class SimpleObjectsIntegTest extends SimpleAppIntegTest { ...@@ -63,14 +62,14 @@ public class SimpleObjectsIntegTest extends SimpleAppIntegTest {
final List<SimpleObject> all = wrap(simpleObjects).listAll(); final List<SimpleObject> all = wrap(simpleObjects).listAll();
// then // then
assertThat(all).hasSize(fs.getSimpleObjects().size()); assertEquals(fs.getSimpleObjects().size(), all.size());
SimpleObject simpleObject = wrap(all.get(0)); SimpleObject simpleObject = wrap(all.get(0));
assertThat(simpleObject.getName()).isEqualTo(fs.getSimpleObjects().get(0).getName()); assertEquals(fs.getSimpleObjects().get(0).getName(), simpleObject.getName());
} }
@Test @Test
public void whenNone() throws Exception { public void testListAllWhenNone() throws Exception {
// given // given
FixtureScript fs = new SimpleObjectsTearDown(); FixtureScript fs = new SimpleObjectsTearDown();
...@@ -81,18 +80,11 @@ public class SimpleObjectsIntegTest extends SimpleAppIntegTest { ...@@ -81,18 +80,11 @@ public class SimpleObjectsIntegTest extends SimpleAppIntegTest {
final List<SimpleObject> all = wrap(simpleObjects).listAll(); final List<SimpleObject> all = wrap(simpleObjects).listAll();
// then // then
assertThat(all).hasSize(0); assertEquals(0, all.size());
} }
}
/**
* Test Creation of Simple Objects
*/
public static class Create extends SimpleObjectsIntegTest {
@Test @Test
public void happyCase() throws Exception { public void testCreate() throws Exception {
// given // given
FixtureScript fs = new SimpleObjectsTearDown(); FixtureScript fs = new SimpleObjectsTearDown();
...@@ -104,11 +96,11 @@ public class SimpleObjectsIntegTest extends SimpleAppIntegTest { ...@@ -104,11 +96,11 @@ public class SimpleObjectsIntegTest extends SimpleAppIntegTest {
// 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 @Test
public void whenAlreadyExists() throws Exception { public void testCreateWhenAlreadyExists() throws Exception {
// given // given
FixtureScript fs = new SimpleObjectsTearDown(); FixtureScript fs = new SimpleObjectsTearDown();
...@@ -144,6 +136,4 @@ public class SimpleObjectsIntegTest extends SimpleAppIntegTest { ...@@ -144,6 +136,4 @@ public class SimpleObjectsIntegTest extends SimpleAppIntegTest {
} }
}; };
} }
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册