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,9 +21,7 @@ import org.apache.isis.applib.annotation.HomePage;
import org.apache.isis.applib.annotation.NatureOfService;
import org.apache.isis.applib.annotation.SemanticsOf;
@DomainService(nature = NatureOfService.VIEW_CONTRIBUTIONS_ONLY // trick to suppress the actions
// from the top-level menu
)
@DomainService(nature = NatureOfService.VIEW_CONTRIBUTIONS_ONLY)
public class HomePageService {
// region > homePage (action)

View File

@ -69,9 +69,12 @@ public class SimpleObjects {
}
}
/**
* Create simple object
*/
@Action(domainEvent = CreateDomainEvent.class)
@MemberOrder(sequence = "3")
public SimpleObject create(final @ParameterLayout(named = "Name") String name) {
public SimpleObject create(@ParameterLayout(named = "Name") final String name) {
final SimpleObject obj = container.newTransientInstance(SimpleObject.class);
obj.setName(name);
container.persistIfNotAlready(obj);

View File

@ -45,8 +45,6 @@ public class SimpleObjectCreate extends FixtureScript {
/**
* The created simple object (output).
*
* @return
*/
public SimpleObject getSimpleObject() {
return simpleObject;

View File

@ -29,7 +29,7 @@ import domainapp.fixture.modules.simple.SimpleObjectsTearDown;
public class RecreateSimpleObjects extends FixtureScript {
public final List<String> NAMES = Collections.unmodifiableList(Arrays.asList("Foo", "Bar", "Baz",
public final List<String> names = Collections.unmodifiableList(Arrays.asList("Foo", "Bar", "Baz",
"Frodo", "Froyo", "Fizz", "Bip", "Bop", "Bang", "Boo"));
public RecreateSimpleObjects() {
@ -72,9 +72,9 @@ public class RecreateSimpleObjects extends FixtureScript {
final int number = defaultParam("number", ec, 3);
// validate
if (number < 0 || number > NAMES.size()) {
if (number < 0 || number > names.size()) {
throw new IllegalArgumentException(String.format("number must be in range [0,%d)",
NAMES.size()));
names.size()));
}
//
@ -83,7 +83,7 @@ public class RecreateSimpleObjects extends FixtureScript {
ec.executeChild(this, new SimpleObjectsTearDown());
for (int i = 0; i < number; i++) {
final SimpleObjectCreate fs = new SimpleObjectCreate().setName(NAMES.get(i));
final SimpleObjectCreate fs = new SimpleObjectCreate().setName(names.get(i));
ec.executeChild(this, fs.getName(), fs);
simpleObjects.add(fs.getSimpleObject());
}

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());
}
};
}
}
}

View File

@ -74,7 +74,7 @@ public class SimpleApplication extends IsisWicketApplication {
* <p>
* for demos only, obvious.
*/
private final static boolean DEMO_MODE_USING_CREDENTIALS_AS_QUERYARGS = false;
private static final boolean DEMO_MODE_USING_CREDENTIALS_AS_QUERYARGS = false;
@Override
@ -116,6 +116,7 @@ public class SimpleApplication extends IsisWicketApplication {
servletRequest.getSession().invalidate();
}
} catch (Exception e) {
System.out.println(e);
}
WebRequest request = super.newWebRequest(servletRequest, filterPath);
return request;