Adjust checkstyle rules. Make checkstyle fail the build when violations are found. Correct all current checkstyle violations.

This commit is contained in:
Ilkka Seppala
2015-12-25 23:49:28 +02:00
parent 9fbb085985
commit cec9a99410
167 changed files with 1242 additions and 969 deletions

View File

@ -21,6 +21,9 @@ import org.apache.isis.objectstore.jdo.datanucleus.IsisConfigurationForJdoIntegT
public class SimpleAppSystemInitializer {
/**
* Init test system
*/
public static void initIsft() {
IsisSystemForTest isft = IsisSystemForTest.getElseNull();
if (isft == null) {

View File

@ -29,7 +29,7 @@ import static org.junit.Assert.assertThat;
public class SimpleObjectGlue extends CukeGlueAbstract {
@Given("^there are.* (\\d+) simple objects$")
public void there_are_N_simple_objects(int n) throws Throwable {
public void thereAreNumSimpleObjects(int n) throws Throwable {
try {
final List<SimpleObject> findAll = service(SimpleObjects.class).listAll();
assertThat(findAll.size(), is(n));
@ -41,7 +41,7 @@ public class SimpleObjectGlue extends CukeGlueAbstract {
}
@When("^I create a new simple object$")
public void I_create_a_new_simple_object() throws Throwable {
public void createNewSimpleObject() throws Throwable {
service(SimpleObjects.class).create(UUID.randomUUID().toString());
}

View File

@ -27,13 +27,13 @@ import domainapp.integtests.bootstrap.SimpleAppSystemInitializer;
public abstract class SimpleAppIntegTest extends IntegrationTestAbstract {
@BeforeClass
public static void initClass() {
org.apache.log4j.PropertyConfigurator.configure("logging.properties");
SimpleAppSystemInitializer.initIsft();
@BeforeClass
public static void initClass() {
org.apache.log4j.PropertyConfigurator.configure("logging.properties");
SimpleAppSystemInitializer.initIsft();
// instantiating will install onto ThreadLocal
new ScenarioExecutionForIntegration();
}
// instantiating will install onto ThreadLocal
new ScenarioExecutionForIntegration();
}
}

View File

@ -35,87 +35,86 @@ import static org.assertj.core.api.Assertions.assertThat;
public class SimpleObjectIntegTest extends SimpleAppIntegTest {
@Inject
FixtureScripts fixtureScripts;
RecreateSimpleObjects fs;
SimpleObject simpleObjectPojo;
SimpleObject simpleObjectWrapped;
@Before
public void setUp() throws Exception {
// given
fs = new RecreateSimpleObjects().setNumber(1);
fixtureScripts.runFixtureScript(fs, null);
simpleObjectPojo = fs.getSimpleObjects().get(0);
assertThat(simpleObjectPojo).isNotNull();
simpleObjectWrapped = wrap(simpleObjectPojo);
}
public static class Name extends SimpleObjectIntegTest {
@Test
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");
}
}
public static class UpdateName extends SimpleObjectIntegTest {
@Test
public void happyCase() throws Exception {
// 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!");
}
}
public static class Title extends SimpleObjectIntegTest {
@Inject
FixtureScripts fixtureScripts;
DomainObjectContainer container;
RecreateSimpleObjects fs;
SimpleObject simpleObjectPojo;
SimpleObject simpleObjectWrapped;
@Test
public void interpolatesName() throws Exception {
@Before
public void setUp() throws Exception {
// given
fs = new RecreateSimpleObjects().setNumber(1);
fixtureScripts.runFixtureScript(fs, null);
// given
final String name = simpleObjectWrapped.getName();
simpleObjectPojo = fs.getSimpleObjects().get(0);
// when
final String title = container.titleOf(simpleObjectWrapped);
assertThat(simpleObjectPojo).isNotNull();
simpleObjectWrapped = wrap(simpleObjectPojo);
}
public static class Name extends SimpleObjectIntegTest {
@Test
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");
}
}
public static class UpdateName extends SimpleObjectIntegTest {
@Test
public void happyCase() throws Exception {
// 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!");
}
}
public static class Title extends SimpleObjectIntegTest {
@Inject
DomainObjectContainer container;
@Test
public void interpolatesName() throws Exception {
// given
final String name = simpleObjectWrapped.getName();
// when
final String title = container.titleOf(simpleObjectWrapped);
// then
assertThat(title).isEqualTo("Object: " + name);
}
// then
assertThat(title).isEqualTo("Object: " + name);
}
}
}

View File

@ -42,102 +42,102 @@ import static org.assertj.core.api.Assertions.assertThat;
public class SimpleObjectsIntegTest extends SimpleAppIntegTest {
@Inject
FixtureScripts fixtureScripts;
@Inject
SimpleObjects simpleObjects;
@Inject
FixtureScripts fixtureScripts;
@Inject
SimpleObjects simpleObjects;
public static class ListAll extends SimpleObjectsIntegTest {
public static class ListAll extends SimpleObjectsIntegTest {
@Test
public void happyCase() throws Exception {
@Test
public void happyCase() throws Exception {
// given
RecreateSimpleObjects fs = new RecreateSimpleObjects();
fixtureScripts.runFixtureScript(fs, null);
nextTransaction();
// given
RecreateSimpleObjects fs = new RecreateSimpleObjects();
fixtureScripts.runFixtureScript(fs, null);
nextTransaction();
// when
final List<SimpleObject> all = wrap(simpleObjects).listAll();
// when
final List<SimpleObject> all = wrap(simpleObjects).listAll();
// then
assertThat(all).hasSize(fs.getSimpleObjects().size());
// then
assertThat(all).hasSize(fs.getSimpleObjects().size());
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);
}
SimpleObject simpleObject = wrap(all.get(0));
assertThat(simpleObject.getName()).isEqualTo(fs.getSimpleObjects().get(0).getName());
}
public static class Create extends SimpleObjectsIntegTest {
@Test
public void whenNone() throws Exception {
@Test
public void happyCase() throws Exception {
// given
FixtureScript fs = new SimpleObjectsTearDown();
fixtureScripts.runFixtureScript(fs, null);
nextTransaction();
// given
FixtureScript fs = new SimpleObjectsTearDown();
fixtureScripts.runFixtureScript(fs, null);
nextTransaction();
// when
final List<SimpleObject> all = wrap(simpleObjects).listAll();
// when
wrap(simpleObjects).create("Faz");
// then
final List<SimpleObject> all = wrap(simpleObjects).listAll();
assertThat(all).hasSize(1);
}
@Test
public void whenAlreadyExists() throws Exception {
// given
FixtureScript fs = new SimpleObjectsTearDown();
fixtureScripts.runFixtureScript(fs, null);
nextTransaction();
wrap(simpleObjects).create("Faz");
nextTransaction();
// then
expectedExceptions.expectCause(causalChainContains(SQLIntegrityConstraintViolationException.class));
// when
wrap(simpleObjects).create("Faz");
nextTransaction();
}
private static Matcher<? extends Throwable> causalChainContains(final Class<?> cls) {
return new TypeSafeMatcher<Throwable>() {
@Override
protected boolean matchesSafely(Throwable item) {
final List<Throwable> causalChain = Throwables.getCausalChain(item);
for (Throwable throwable : causalChain) {
if(cls.isAssignableFrom(throwable.getClass())){
return true;
}
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("exception with causal chain containing " + cls.getSimpleName());
}
};
}
// then
assertThat(all).hasSize(0);
}
}
public static class Create extends SimpleObjectsIntegTest {
@Test
public void happyCase() throws Exception {
// given
FixtureScript fs = new SimpleObjectsTearDown();
fixtureScripts.runFixtureScript(fs, null);
nextTransaction();
// when
wrap(simpleObjects).create("Faz");
// then
final List<SimpleObject> all = wrap(simpleObjects).listAll();
assertThat(all).hasSize(1);
}
@Test
public void whenAlreadyExists() throws Exception {
// given
FixtureScript fs = new SimpleObjectsTearDown();
fixtureScripts.runFixtureScript(fs, null);
nextTransaction();
wrap(simpleObjects).create("Faz");
nextTransaction();
// then
expectedExceptions.expectCause(causalChainContains(SQLIntegrityConstraintViolationException.class));
// when
wrap(simpleObjects).create("Faz");
nextTransaction();
}
private static Matcher<? extends Throwable> causalChainContains(final Class<?> cls) {
return new TypeSafeMatcher<Throwable>() {
@Override
protected boolean matchesSafely(Throwable item) {
final List<Throwable> causalChain = Throwables.getCausalChain(item);
for (Throwable throwable : causalChain) {
if (cls.isAssignableFrom(throwable.getClass())) {
return true;
}
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("exception with causal chain containing " + cls.getSimpleName());
}
};
}
}
}