Merge pull request #281 from ankurkaushal/master
Reformat according to google style guide
This commit is contained in:
		| @@ -1,20 +1,16 @@ | ||||
| /* | ||||
|  *  Licensed to the Apache Software Foundation (ASF) under one | ||||
|  *  or more contributor license agreements.  See the NOTICE file | ||||
|  *  distributed with this work for additional information | ||||
|  *  regarding copyright ownership.  The ASF licenses this file | ||||
|  *  to you under the Apache License, Version 2.0 (the | ||||
|  *  "License"); you may not use this file except in compliance | ||||
|  *  with the License.  You may obtain a copy of the License at | ||||
|  * | ||||
|  *        http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  *  Unless required by applicable law or agreed to in writing, | ||||
|  *  software distributed under the License is distributed on an | ||||
|  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||
|  *  KIND, either express or implied.  See the License for the | ||||
|  *  specific language governing permissions and limitations | ||||
|  *  under the License. | ||||
|  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license | ||||
|  * agreements. See the NOTICE file distributed with this work for additional information regarding | ||||
|  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the | ||||
|  * "License"); you may not use this file except in compliance with the License. You may obtain a | ||||
|  * copy of the License at | ||||
|  *  | ||||
|  * http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  *  | ||||
|  * Unless required by applicable law or agreed to in writing, software distributed under the License | ||||
|  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||||
|  * or implied. See the License for the specific language governing permissions and limitations under | ||||
|  * the License. | ||||
|  */ | ||||
| package domainapp.dom.app.homepage; | ||||
| 
 | ||||
| @@ -25,27 +21,25 @@ 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 // trick to suppress the actions | ||||
|                                                                 // from the top-level menu | ||||
| ) | ||||
| public class HomePageService { | ||||
| 
 | ||||
|     //region > homePage (action) | ||||
|   // region > homePage (action) | ||||
| 
 | ||||
|     @Action( | ||||
|             semantics = SemanticsOf.SAFE | ||||
|     ) | ||||
|     @HomePage | ||||
|     public HomePageViewModel homePage() { | ||||
|         return container.injectServicesInto(new HomePageViewModel()); | ||||
|     } | ||||
|   @Action(semantics = SemanticsOf.SAFE) | ||||
|   @HomePage | ||||
|   public HomePageViewModel homePage() { | ||||
|     return container.injectServicesInto(new HomePageViewModel()); | ||||
|   } | ||||
| 
 | ||||
|     //endregion | ||||
|   // endregion | ||||
| 
 | ||||
|     //region > injected services | ||||
|   // region > injected services | ||||
| 
 | ||||
|     @javax.inject.Inject | ||||
|     DomainObjectContainer container; | ||||
|   @javax.inject.Inject | ||||
|   DomainObjectContainer container; | ||||
| 
 | ||||
|     //endregion | ||||
|   // endregion | ||||
| } | ||||
|   | ||||
| @@ -1,20 +1,16 @@ | ||||
| /* | ||||
|  *  Licensed to the Apache Software Foundation (ASF) under one | ||||
|  *  or more contributor license agreements.  See the NOTICE file | ||||
|  *  distributed with this work for additional information | ||||
|  *  regarding copyright ownership.  The ASF licenses this file | ||||
|  *  to you under the Apache License, Version 2.0 (the | ||||
|  *  "License"); you may not use this file except in compliance | ||||
|  *  with the License.  You may obtain a copy of the License at | ||||
|  * | ||||
|  *        http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  *  Unless required by applicable law or agreed to in writing, | ||||
|  *  software distributed under the License is distributed on an | ||||
|  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||
|  *  KIND, either express or implied.  See the License for the | ||||
|  *  specific language governing permissions and limitations | ||||
|  *  under the License. | ||||
|  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license | ||||
|  * agreements. See the NOTICE file distributed with this work for additional information regarding | ||||
|  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the | ||||
|  * "License"); you may not use this file except in compliance with the License. You may obtain a | ||||
|  * copy of the License at | ||||
|  *  | ||||
|  * http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  *  | ||||
|  * Unless required by applicable law or agreed to in writing, software distributed under the License | ||||
|  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||||
|  * or implied. See the License for the specific language governing permissions and limitations under | ||||
|  * the License. | ||||
|  */ | ||||
| package domainapp.dom.app.homepage; | ||||
| 
 | ||||
| @@ -28,23 +24,25 @@ import domainapp.dom.modules.simple.SimpleObjects; | ||||
| @ViewModel | ||||
| public class HomePageViewModel { | ||||
| 
 | ||||
|     //region > title | ||||
|     public String title() { | ||||
|         return getObjects().size() + " objects"; | ||||
|     } | ||||
|     //endregion | ||||
|   // region > title | ||||
|   public String title() { | ||||
|     return getObjects().size() + " objects"; | ||||
|   } | ||||
| 
 | ||||
|     //region > object (collection) | ||||
|     @org.apache.isis.applib.annotation.HomePage | ||||
|     public List<SimpleObject> getObjects() { | ||||
|         return simpleObjects.listAll(); | ||||
|     } | ||||
|     //endregion | ||||
|   // endregion | ||||
| 
 | ||||
|     //region > injected services | ||||
|   // region > object (collection) | ||||
|   @org.apache.isis.applib.annotation.HomePage | ||||
|   public List<SimpleObject> getObjects() { | ||||
|     return simpleObjects.listAll(); | ||||
|   } | ||||
| 
 | ||||
|     @javax.inject.Inject | ||||
|     SimpleObjects simpleObjects; | ||||
|   // endregion | ||||
| 
 | ||||
|     //endregion | ||||
|   // region > injected services | ||||
| 
 | ||||
|   @javax.inject.Inject | ||||
|   SimpleObjects simpleObjects; | ||||
| 
 | ||||
|   // endregion | ||||
| } | ||||
|   | ||||
| @@ -1,20 +1,16 @@ | ||||
| /* | ||||
|  *  Licensed to the Apache Software Foundation (ASF) under one | ||||
|  *  or more contributor license agreements.  See the NOTICE file | ||||
|  *  distributed with this work for additional information | ||||
|  *  regarding copyright ownership.  The ASF licenses this file | ||||
|  *  to you under the Apache License, Version 2.0 (the | ||||
|  *  "License"); you may not use this file except in compliance | ||||
|  *  with the License.  You may obtain a copy of the License at | ||||
|  * | ||||
|  *        http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  *  Unless required by applicable law or agreed to in writing, | ||||
|  *  software distributed under the License is distributed on an | ||||
|  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||
|  *  KIND, either express or implied.  See the License for the | ||||
|  *  specific language governing permissions and limitations | ||||
|  *  under the License. | ||||
|  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license | ||||
|  * agreements. See the NOTICE file distributed with this work for additional information regarding | ||||
|  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the | ||||
|  * "License"); you may not use this file except in compliance with the License. You may obtain a | ||||
|  * copy of the License at | ||||
|  *  | ||||
|  * http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  *  | ||||
|  * Unless required by applicable law or agreed to in writing, software distributed under the License | ||||
|  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||||
|  * or implied. See the License for the specific language governing permissions and limitations under | ||||
|  * the License. | ||||
|  */ | ||||
| package domainapp.dom.modules.simple; | ||||
| 
 | ||||
| @@ -37,113 +33,95 @@ import org.apache.isis.applib.services.eventbus.ActionDomainEvent; | ||||
| import org.apache.isis.applib.services.i18n.TranslatableString; | ||||
| import org.apache.isis.applib.util.ObjectContracts; | ||||
| 
 | ||||
| @javax.jdo.annotations.PersistenceCapable( | ||||
|         identityType=IdentityType.DATASTORE, | ||||
|         schema = "simple", | ||||
|         table = "SimpleObject" | ||||
| ) | ||||
| @javax.jdo.annotations.PersistenceCapable(identityType = IdentityType.DATASTORE, schema = "simple", | ||||
|     table = "SimpleObject") | ||||
| @javax.jdo.annotations.DatastoreIdentity( | ||||
|         strategy=javax.jdo.annotations.IdGeneratorStrategy.IDENTITY, | ||||
|          column="id") | ||||
| @javax.jdo.annotations.Version( | ||||
|         strategy=VersionStrategy.VERSION_NUMBER,  | ||||
|         column="version") | ||||
|     strategy = javax.jdo.annotations.IdGeneratorStrategy.IDENTITY, column = "id") | ||||
| @javax.jdo.annotations.Version(strategy = VersionStrategy.VERSION_NUMBER, column = "version") | ||||
| @javax.jdo.annotations.Queries({ | ||||
|         @javax.jdo.annotations.Query( | ||||
|                 name = "find", language = "JDOQL", | ||||
|                 value = "SELECT " | ||||
|                         + "FROM domainapp.dom.modules.simple.SimpleObject "), | ||||
|         @javax.jdo.annotations.Query( | ||||
|                 name = "findByName", language = "JDOQL", | ||||
|                 value = "SELECT " | ||||
|                         + "FROM domainapp.dom.modules.simple.SimpleObject " | ||||
|                         + "WHERE name.indexOf(:name) >= 0 ") | ||||
| }) | ||||
| @javax.jdo.annotations.Unique(name="SimpleObject_name_UNQ", members = {"name"}) | ||||
|     @javax.jdo.annotations.Query(name = "find", language = "JDOQL", value = "SELECT " | ||||
|         + "FROM domainapp.dom.modules.simple.SimpleObject "), | ||||
|     @javax.jdo.annotations.Query(name = "findByName", language = "JDOQL", value = "SELECT " | ||||
|         + "FROM domainapp.dom.modules.simple.SimpleObject " + "WHERE name.indexOf(:name) >= 0 ")}) | ||||
| @javax.jdo.annotations.Unique(name = "SimpleObject_name_UNQ", members = {"name"}) | ||||
| @DomainObject | ||||
| @DomainObjectLayout( | ||||
|         bookmarking = BookmarkPolicy.AS_ROOT, | ||||
|         cssClassFa = "fa-flag" | ||||
| ) | ||||
| @DomainObjectLayout(bookmarking = BookmarkPolicy.AS_ROOT, cssClassFa = "fa-flag") | ||||
| public class SimpleObject implements Comparable<SimpleObject> { | ||||
| 
 | ||||
| 
 | ||||
|     //region > identificatiom | ||||
|     public TranslatableString title() { | ||||
|         return TranslatableString.tr("Object: {name}", "name", getName()); | ||||
|   // region > identificatiom | ||||
|   public TranslatableString title() { | ||||
|     return TranslatableString.tr("Object: {name}", "name", getName()); | ||||
|   } | ||||
| 
 | ||||
|   // endregion | ||||
| 
 | ||||
|   // region > name (property) | ||||
| 
 | ||||
|   private String name; | ||||
| 
 | ||||
|   @javax.jdo.annotations.Column(allowsNull = "false", length = 40) | ||||
|   @Title(sequence = "1") | ||||
|   @Property(editing = Editing.DISABLED) | ||||
|   public String getName() { | ||||
|     return name; | ||||
|   } | ||||
| 
 | ||||
|   public void setName(final String name) { | ||||
|     this.name = name; | ||||
|   } | ||||
| 
 | ||||
|   // endregion | ||||
| 
 | ||||
|   // region > updateName (action) | ||||
| 
 | ||||
|   public static class UpdateNameDomainEvent extends ActionDomainEvent<SimpleObject> { | ||||
|     public UpdateNameDomainEvent(final SimpleObject source, final Identifier identifier, | ||||
|         final Object... arguments) { | ||||
|       super(source, identifier, arguments); | ||||
|     } | ||||
|     //endregion | ||||
|   } | ||||
| 
 | ||||
|     //region > name (property) | ||||
|   @Action(domainEvent = UpdateNameDomainEvent.class) | ||||
|   public SimpleObject updateName( | ||||
|       @Parameter(maxLength = 40) @ParameterLayout(named = "New name") final String name) { | ||||
|     setName(name); | ||||
|     return this; | ||||
|   } | ||||
| 
 | ||||
|     private String name; | ||||
|   public String default0UpdateName() { | ||||
|     return getName(); | ||||
|   } | ||||
| 
 | ||||
|     @javax.jdo.annotations.Column(allowsNull="false", length = 40) | ||||
|     @Title(sequence="1") | ||||
|     @Property( | ||||
|             editing = Editing.DISABLED | ||||
|     ) | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
|   public TranslatableString validateUpdateName(final String name) { | ||||
|     return name.contains("!") ? TranslatableString.tr("Exclamation mark is not allowed") : null; | ||||
|   } | ||||
| 
 | ||||
|     public void setName(final String name) { | ||||
|         this.name = name; | ||||
|     } | ||||
|   // endregion | ||||
| 
 | ||||
|     // endregion | ||||
|   // region > version (derived property) | ||||
|   public Long getVersionSequence() { | ||||
|     return (Long) JDOHelper.getVersion(this); | ||||
|   } | ||||
| 
 | ||||
|     //region > updateName (action) | ||||
|   // endregion | ||||
| 
 | ||||
|     public static class UpdateNameDomainEvent extends ActionDomainEvent<SimpleObject> { | ||||
|         public UpdateNameDomainEvent(final SimpleObject source, final Identifier identifier, final Object... arguments) { | ||||
|             super(source, identifier, arguments); | ||||
|         } | ||||
|     } | ||||
|   // region > compareTo | ||||
| 
 | ||||
|     @Action( | ||||
|             domainEvent = UpdateNameDomainEvent.class | ||||
|     ) | ||||
|     public SimpleObject updateName( | ||||
|             @Parameter(maxLength = 40) | ||||
|             @ParameterLayout(named = "New name") | ||||
|             final String name) { | ||||
|         setName(name); | ||||
|         return this; | ||||
|     } | ||||
|   @Override | ||||
|   public int compareTo(final SimpleObject other) { | ||||
|     return ObjectContracts.compare(this, other, "name"); | ||||
|   } | ||||
| 
 | ||||
|     public String default0UpdateName() { | ||||
|         return getName(); | ||||
|     } | ||||
|   // endregion | ||||
| 
 | ||||
|     public TranslatableString validateUpdateName(final String name) { | ||||
|         return name.contains("!")? TranslatableString.tr("Exclamation mark is not allowed"): null; | ||||
|     } | ||||
|   // region > injected services | ||||
| 
 | ||||
|     //endregion | ||||
|   @javax.inject.Inject | ||||
|   @SuppressWarnings("unused") | ||||
|   private DomainObjectContainer container; | ||||
| 
 | ||||
|     //region > version (derived property) | ||||
|     public Long getVersionSequence() { | ||||
|         return (Long) JDOHelper.getVersion(this); | ||||
|     } | ||||
|     //endregion | ||||
| 
 | ||||
|     //region > compareTo | ||||
| 
 | ||||
|     @Override | ||||
|     public int compareTo(final SimpleObject other) { | ||||
|         return ObjectContracts.compare(this, other, "name"); | ||||
|     } | ||||
| 
 | ||||
|     //endregion | ||||
| 
 | ||||
|     //region > injected services | ||||
| 
 | ||||
|     @javax.inject.Inject | ||||
|     @SuppressWarnings("unused") | ||||
|     private DomainObjectContainer container; | ||||
| 
 | ||||
|     //endregion | ||||
|   // endregion | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|   | ||||
| @@ -1,20 +1,16 @@ | ||||
| /* | ||||
|  *  Licensed to the Apache Software Foundation (ASF) under one | ||||
|  *  or more contributor license agreements.  See the NOTICE file | ||||
|  *  distributed with this work for additional information | ||||
|  *  regarding copyright ownership.  The ASF licenses this file | ||||
|  *  to you under the Apache License, Version 2.0 (the | ||||
|  *  "License"); you may not use this file except in compliance | ||||
|  *  with the License.  You may obtain a copy of the License at | ||||
|  * | ||||
|  *        http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  *  Unless required by applicable law or agreed to in writing, | ||||
|  *  software distributed under the License is distributed on an | ||||
|  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||
|  *  KIND, either express or implied.  See the License for the | ||||
|  *  specific language governing permissions and limitations | ||||
|  *  under the License. | ||||
|  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license | ||||
|  * agreements. See the NOTICE file distributed with this work for additional information regarding | ||||
|  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the | ||||
|  * "License"); you may not use this file except in compliance with the License. You may obtain a | ||||
|  * copy of the License at | ||||
|  *  | ||||
|  * http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  *  | ||||
|  * Unless required by applicable law or agreed to in writing, software distributed under the License | ||||
|  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||||
|  * or implied. See the License for the specific language governing permissions and limitations under | ||||
|  * the License. | ||||
|  */ | ||||
| package domainapp.dom.modules.simple; | ||||
| 
 | ||||
| @@ -38,70 +34,56 @@ import org.apache.isis.applib.services.i18n.TranslatableString; | ||||
| @DomainServiceLayout(menuOrder = "10") | ||||
| public class SimpleObjects { | ||||
| 
 | ||||
|     //region > title | ||||
|     public TranslatableString title() { | ||||
|         return TranslatableString.tr("Simple Objects"); | ||||
|   // region > title | ||||
|   public TranslatableString title() { | ||||
|     return TranslatableString.tr("Simple Objects"); | ||||
|   } | ||||
| 
 | ||||
|   // endregion | ||||
| 
 | ||||
|   // region > listAll (action) | ||||
|   @Action(semantics = SemanticsOf.SAFE) | ||||
|   @ActionLayout(bookmarking = BookmarkPolicy.AS_ROOT) | ||||
|   @MemberOrder(sequence = "1") | ||||
|   public List<SimpleObject> listAll() { | ||||
|     return container.allInstances(SimpleObject.class); | ||||
|   } | ||||
| 
 | ||||
|   // endregion | ||||
| 
 | ||||
|   // region > findByName (action) | ||||
|   @Action(semantics = SemanticsOf.SAFE) | ||||
|   @ActionLayout(bookmarking = BookmarkPolicy.AS_ROOT) | ||||
|   @MemberOrder(sequence = "2") | ||||
|   public List<SimpleObject> findByName(@ParameterLayout(named = "Name") final String name) { | ||||
|     return container.allMatches(new QueryDefault<>(SimpleObject.class, "findByName", "name", name)); | ||||
|   } | ||||
| 
 | ||||
|   // endregion | ||||
| 
 | ||||
|   // region > create (action) | ||||
|   public static class CreateDomainEvent extends ActionDomainEvent<SimpleObjects> { | ||||
|     public CreateDomainEvent(final SimpleObjects source, final Identifier identifier, | ||||
|         final Object... arguments) { | ||||
|       super(source, identifier, arguments); | ||||
|     } | ||||
|     //endregion | ||||
|   } | ||||
| 
 | ||||
|     //region > listAll (action) | ||||
|     @Action( | ||||
|             semantics = SemanticsOf.SAFE | ||||
|     ) | ||||
|     @ActionLayout( | ||||
|             bookmarking = BookmarkPolicy.AS_ROOT | ||||
|     ) | ||||
|     @MemberOrder(sequence = "1") | ||||
|     public List<SimpleObject> listAll() { | ||||
|         return container.allInstances(SimpleObject.class); | ||||
|     } | ||||
|     //endregion | ||||
|   @Action(domainEvent = CreateDomainEvent.class) | ||||
|   @MemberOrder(sequence = "3") | ||||
|   public SimpleObject create(final @ParameterLayout(named = "Name") String name) { | ||||
|     final SimpleObject obj = container.newTransientInstance(SimpleObject.class); | ||||
|     obj.setName(name); | ||||
|     container.persistIfNotAlready(obj); | ||||
|     return obj; | ||||
|   } | ||||
| 
 | ||||
|     //region > findByName (action) | ||||
|     @Action( | ||||
|             semantics = SemanticsOf.SAFE | ||||
|     ) | ||||
|     @ActionLayout( | ||||
|             bookmarking = BookmarkPolicy.AS_ROOT | ||||
|     ) | ||||
|     @MemberOrder(sequence = "2") | ||||
|     public List<SimpleObject> findByName( | ||||
|             @ParameterLayout(named="Name") | ||||
|             final String name | ||||
|     ) { | ||||
|         return container.allMatches( | ||||
|                 new QueryDefault<>( | ||||
|                         SimpleObject.class, | ||||
|                         "findByName", | ||||
|                         "name", name)); | ||||
|     } | ||||
|     //endregion | ||||
|   // endregion | ||||
| 
 | ||||
|     //region > create (action) | ||||
|     public static class CreateDomainEvent extends ActionDomainEvent<SimpleObjects> { | ||||
|         public CreateDomainEvent(final SimpleObjects source, final Identifier identifier, final Object... arguments) { | ||||
|             super(source, identifier, arguments); | ||||
|         } | ||||
|     } | ||||
|   // region > injected services | ||||
| 
 | ||||
|     @Action( | ||||
|             domainEvent = CreateDomainEvent.class | ||||
|     ) | ||||
|     @MemberOrder(sequence = "3") | ||||
|     public SimpleObject create( | ||||
|             final @ParameterLayout(named="Name") String name) { | ||||
|         final SimpleObject obj = container.newTransientInstance(SimpleObject.class); | ||||
|         obj.setName(name); | ||||
|         container.persistIfNotAlready(obj); | ||||
|         return obj; | ||||
|     } | ||||
|   @javax.inject.Inject | ||||
|   DomainObjectContainer container; | ||||
| 
 | ||||
|     //endregion | ||||
| 
 | ||||
|     //region > injected services | ||||
| 
 | ||||
|     @javax.inject.Inject  | ||||
|     DomainObjectContainer container; | ||||
| 
 | ||||
|     //endregion | ||||
|   // endregion | ||||
| } | ||||
|   | ||||
| @@ -1,18 +1,16 @@ | ||||
| /** | ||||
|  *  Licensed to the Apache Software Foundation (ASF) under one or more | ||||
|  *  contributor license agreements.  See the NOTICE file distributed with | ||||
|  *  this work for additional information regarding copyright ownership. | ||||
|  *  The ASF licenses this file to You under the Apache License, Version 2.0 | ||||
|  *  (the "License"); you may not use this file except in compliance with | ||||
|  *  the License.  You may obtain a copy of the License at | ||||
|  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license | ||||
|  * agreements. See the NOTICE file distributed with this work for additional information regarding | ||||
|  * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the | ||||
|  * "License"); you may not use this file except in compliance with the License. You may obtain a | ||||
|  * copy of the License at | ||||
|  * | ||||
|  *     http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  *  Unless required by applicable law or agreed to in writing, software | ||||
|  *  distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  *  See the License for the specific language governing permissions and | ||||
|  *  limitations under the License. | ||||
|  * Unless required by applicable law or agreed to in writing, software distributed under the License | ||||
|  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||||
|  * or implied. See the License for the specific language governing permissions and limitations under | ||||
|  * the License. | ||||
|  */ | ||||
| package domainapp.dom.modules.simple; | ||||
| 
 | ||||
| @@ -23,27 +21,27 @@ import static org.assertj.core.api.Assertions.assertThat; | ||||
| 
 | ||||
| public class SimpleObjectTest { | ||||
| 
 | ||||
|     SimpleObject simpleObject; | ||||
|   SimpleObject simpleObject; | ||||
| 
 | ||||
|     @Before | ||||
|     public void setUp() throws Exception { | ||||
|         simpleObject = new SimpleObject(); | ||||
|     } | ||||
| 
 | ||||
|     public static class Name extends SimpleObjectTest { | ||||
| 
 | ||||
|         @Test | ||||
|         public void happyCase() throws Exception { | ||||
|             // given | ||||
|             String name = "Foobar"; | ||||
|             assertThat(simpleObject.getName()).isNull(); | ||||
| 
 | ||||
|             // when | ||||
|             simpleObject.setName(name); | ||||
| 
 | ||||
|             // then | ||||
|             assertThat(simpleObject.getName()).isEqualTo(name); | ||||
|         } | ||||
|   @Before | ||||
|   public void setUp() throws Exception { | ||||
|     simpleObject = new SimpleObject(); | ||||
|   } | ||||
| 
 | ||||
|   public static class Name extends SimpleObjectTest { | ||||
| 
 | ||||
|     @Test | ||||
|     public void happyCase() throws Exception { | ||||
|       // given | ||||
|       String name = "Foobar"; | ||||
|       assertThat(simpleObject.getName()).isNull(); | ||||
| 
 | ||||
|       // when | ||||
|       simpleObject.setName(name); | ||||
| 
 | ||||
|       // then | ||||
|       assertThat(simpleObject.getName()).isEqualTo(name); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
| } | ||||
|   | ||||
| @@ -1,18 +1,16 @@ | ||||
| /** | ||||
|  *  Licensed to the Apache Software Foundation (ASF) under one or more | ||||
|  *  contributor license agreements.  See the NOTICE file distributed with | ||||
|  *  this work for additional information regarding copyright ownership. | ||||
|  *  The ASF licenses this file to You under the Apache License, Version 2.0 | ||||
|  *  (the "License"); you may not use this file except in compliance with | ||||
|  *  the License.  You may obtain a copy of the License at | ||||
|  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license | ||||
|  * agreements. See the NOTICE file distributed with this work for additional information regarding | ||||
|  * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the | ||||
|  * "License"); you may not use this file except in compliance with the License. You may obtain a | ||||
|  * copy of the License at | ||||
|  * | ||||
|  *     http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  *  Unless required by applicable law or agreed to in writing, software | ||||
|  *  distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  *  See the License for the specific language governing permissions and | ||||
|  *  limitations under the License. | ||||
|  * Unless required by applicable law or agreed to in writing, software distributed under the License | ||||
|  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||||
|  * or implied. See the License for the specific language governing permissions and limitations under | ||||
|  * the License. | ||||
|  */ | ||||
| package domainapp.dom.modules.simple; | ||||
| 
 | ||||
| @@ -35,70 +33,70 @@ import static org.assertj.core.api.Assertions.assertThat; | ||||
| 
 | ||||
| public class SimpleObjectsTest { | ||||
| 
 | ||||
|     @Rule | ||||
|     public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); | ||||
|   @Rule | ||||
|   public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES); | ||||
| 
 | ||||
|     @Mock | ||||
|     DomainObjectContainer mockContainer; | ||||
|      | ||||
|     SimpleObjects simpleObjects; | ||||
|   @Mock | ||||
|   DomainObjectContainer mockContainer; | ||||
| 
 | ||||
|     @Before | ||||
|     public void setUp() throws Exception { | ||||
|         simpleObjects = new SimpleObjects(); | ||||
|         simpleObjects.container = mockContainer; | ||||
|     } | ||||
|   SimpleObjects simpleObjects; | ||||
| 
 | ||||
|     public static class Create extends SimpleObjectsTest { | ||||
|   @Before | ||||
|   public void setUp() throws Exception { | ||||
|     simpleObjects = new SimpleObjects(); | ||||
|     simpleObjects.container = mockContainer; | ||||
|   } | ||||
| 
 | ||||
|         @Test | ||||
|         public void happyCase() throws Exception { | ||||
|   public static class Create extends SimpleObjectsTest { | ||||
| 
 | ||||
|             // given | ||||
|             final SimpleObject simpleObject = new SimpleObject(); | ||||
|     @Test | ||||
|     public void happyCase() throws Exception { | ||||
| 
 | ||||
|             final Sequence seq = context.sequence("create"); | ||||
|             context.checking(new Expectations() { | ||||
|                 { | ||||
|                     oneOf(mockContainer).newTransientInstance(SimpleObject.class); | ||||
|                     inSequence(seq); | ||||
|                     will(returnValue(simpleObject)); | ||||
|       // given | ||||
|       final SimpleObject simpleObject = new SimpleObject(); | ||||
| 
 | ||||
|                     oneOf(mockContainer).persistIfNotAlready(simpleObject); | ||||
|                     inSequence(seq); | ||||
|                 } | ||||
|             }); | ||||
|       final Sequence seq = context.sequence("create"); | ||||
|       context.checking(new Expectations() { | ||||
|         { | ||||
|           oneOf(mockContainer).newTransientInstance(SimpleObject.class); | ||||
|           inSequence(seq); | ||||
|           will(returnValue(simpleObject)); | ||||
| 
 | ||||
|             // when | ||||
|             final SimpleObject obj = simpleObjects.create("Foobar"); | ||||
| 
 | ||||
|             // then | ||||
|             assertThat(obj).isEqualTo(simpleObject); | ||||
|             assertThat(obj.getName()).isEqualTo("Foobar"); | ||||
|           oneOf(mockContainer).persistIfNotAlready(simpleObject); | ||||
|           inSequence(seq); | ||||
|         } | ||||
|       }); | ||||
| 
 | ||||
|       // when | ||||
|       final SimpleObject obj = simpleObjects.create("Foobar"); | ||||
| 
 | ||||
|       // then | ||||
|       assertThat(obj).isEqualTo(simpleObject); | ||||
|       assertThat(obj.getName()).isEqualTo("Foobar"); | ||||
|     } | ||||
| 
 | ||||
|     public static class ListAll extends SimpleObjectsTest { | ||||
|   } | ||||
| 
 | ||||
|         @Test | ||||
|         public void happyCase() throws Exception { | ||||
|   public static class ListAll extends SimpleObjectsTest { | ||||
| 
 | ||||
|             // given | ||||
|             final List<SimpleObject> all = Lists.newArrayList(); | ||||
|     @Test | ||||
|     public void happyCase() throws Exception { | ||||
| 
 | ||||
|             context.checking(new Expectations() { | ||||
|                 { | ||||
|                     oneOf(mockContainer).allInstances(SimpleObject.class); | ||||
|                     will(returnValue(all)); | ||||
|                 } | ||||
|             }); | ||||
|       // given | ||||
|       final List<SimpleObject> all = Lists.newArrayList(); | ||||
| 
 | ||||
|             // when | ||||
|             final List<SimpleObject> list = simpleObjects.listAll(); | ||||
| 
 | ||||
|             // then | ||||
|             assertThat(list).isEqualTo(all); | ||||
|       context.checking(new Expectations() { | ||||
|         { | ||||
|           oneOf(mockContainer).allInstances(SimpleObject.class); | ||||
|           will(returnValue(all)); | ||||
|         } | ||||
|       }); | ||||
| 
 | ||||
|       // when | ||||
|       final List<SimpleObject> list = simpleObjects.listAll(); | ||||
| 
 | ||||
|       // then | ||||
|       assertThat(list).isEqualTo(all); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user