Skip to content

Commit

Permalink
Source code formatting changes in sample code.
Browse files Browse the repository at this point in the history
  • Loading branch information
rliesenfeld committed Feb 13, 2018
1 parent 22d5082 commit 9d3c88f
Show file tree
Hide file tree
Showing 47 changed files with 148 additions and 294 deletions.
6 changes: 3 additions & 3 deletions samples/java8testing/pom.xml
Expand Up @@ -18,11 +18,11 @@
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId><artifactId>junit-platform-surefire-provider</artifactId>
<version>1.1.0-M1</version>
<version>1.1.0-RC1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0-M1</version>
<version>5.1.0-RC1</version>
</dependency>
</dependencies>
</plugin>
Expand All @@ -31,7 +31,7 @@

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId><version>5.1.0-M1</version>
<groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId><version>5.1.0-RC1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
6 changes: 2 additions & 4 deletions samples/java8testing/src/java8testing/BusinessService.java
Expand Up @@ -4,15 +4,13 @@ public final class BusinessService
{
private final Collaborator collaborator;

public BusinessService(Collaborator collaborator)
{
public BusinessService(Collaborator collaborator) {
this.collaborator = collaborator;
}

public Collaborator getCollaborator() { return collaborator; }

public String performBusinessOperation(int value)
{
public String performBusinessOperation(int value) {
return collaborator.doSomething(value + 1);
}
}
1 change: 0 additions & 1 deletion samples/java8testing/test/java8testing/TestUtils.java
Expand Up @@ -2,5 +2,4 @@

public final class TestUtils
{

}
3 changes: 1 addition & 2 deletions samples/needle4j/src/main/java/blog/blogEntry/BlogEntry.java
Expand Up @@ -40,8 +40,7 @@ public class BlogEntry extends BaseEntity
public String getContent() { return content; }
public void setContent(String content) { this.content = content; }

public String getShortContent()
{
public String getShortContent() {
if (content != null && content.length() > 200) {
return content.substring(0, 200) + "...";
}
Expand Down
Expand Up @@ -12,14 +12,12 @@ public class BlogEntryDaoBean implements BlogEntryDao
@Inject private Database db;

@Override
public List<BlogEntry> find(int maxResults, int firstResult)
{
public List<BlogEntry> find(int maxResults, int firstResult) {
return db.findWithPaging("select b from BlogEntry b order by b.created desc", maxResults, firstResult);
}

@Override
public Long count()
{
public Long count() {
return db.findSingle("select count(b) from BlogEntry b");
}
}
Expand Up @@ -14,8 +14,7 @@ public class BlogEntryListService
private List<BlogEntry> resultList;
private int firstResult;

public List<BlogEntry> getResultList()
{
public List<BlogEntry> getResultList() {
if (resultList == null) {
resultList = blogEntryDao.find(MAX_RESULTS, firstResult);
}
Expand All @@ -27,8 +26,8 @@ public List<BlogEntry> getResultList()
public int getPreviousFirstResult() { return firstResult <= MAX_RESULTS ? 0 : firstResult - MAX_RESULTS; }

public int getFirstResult() { return firstResult; }
public void setFirstResult(int firstResult)
{

public void setFirstResult(int firstResult) {
this.firstResult = firstResult;
resultList = null;
}
Expand Down
Expand Up @@ -25,17 +25,15 @@ public class BlogEntryService implements Serializable

public Long getId() { return id; }

public void setId(Long id)
{
public void setId(Long id) {
beginConversation();

log.info("set blog entry id " + id);
this.id = id;
}

@Produces
public BlogEntry getInstance()
{
public BlogEntry getInstance() {
if (instance == null || id != null && !id.equals(instance.getId())) {
instance = db.find(BlogEntry.class, id);
}
Expand All @@ -44,8 +42,7 @@ public BlogEntry getInstance()
return instance;
}

public void newInstance()
{
public void newInstance() {
beginConversation();

BlogEntry blogEntry = new BlogEntry();
Expand All @@ -54,28 +51,24 @@ public void newInstance()
id = null;
}

private void beginConversation()
{
private void beginConversation() {
if (conversation.isTransient()) {
conversation.begin();
log.info("beginConversation conversation with id " + conversation.getId());
}
}

private void endConversation()
{
private void endConversation() {
if (!conversation.isTransient()) {
conversation.end();
}
}

public void save()
{
public void save() {
id = db.save(instance);
}

public void delete()
{
public void delete() {
log.info("delete blog entry " + instance);
db.remove(instance);
endConversation();
Expand Down
Expand Up @@ -15,8 +15,7 @@ public class CommentListService implements Serializable
@Inject private BlogEntryService blogEntryService;
@Inject private Database db;

public List<Comment> getResultList()
{
public List<Comment> getResultList() {
BlogEntry blogEntry = blogEntryService.getInstance();
return db.find("select c from Comment c where c.blogEntry = ?1 order by c.created", blogEntry);
}
Expand Down
Expand Up @@ -15,8 +15,7 @@ public class CommentService
@Inject private Database db;
private Comment instance;

public Comment getInstance()
{
public Comment getInstance() {
if (instance == null) {
instance = new Comment();
instance.setAuthor(user);
Expand All @@ -26,8 +25,7 @@ public Comment getInstance()
return instance;
}

public void save()
{
public void save() {
db.save(instance);
instance = null;
}
Expand Down
21 changes: 7 additions & 14 deletions samples/needle4j/src/main/java/blog/common/Database.java
Expand Up @@ -9,8 +9,7 @@ public class Database
{
@PersistenceContext private EntityManager em;

public Long save(BaseEntity instance)
{
public Long save(BaseEntity instance) {
if (instance.getId() == null) {
em.persist(instance);
}
Expand All @@ -22,8 +21,7 @@ public Long save(BaseEntity instance)
return instance.getId();
}

public void remove(BaseEntity instance)
{
public void remove(BaseEntity instance) {
if (em.contains(instance)) {
em.remove(instance);
}
Expand All @@ -36,13 +34,11 @@ public void remove(BaseEntity instance)
}
}

public <E extends BaseEntity> E find(Class<E> entityClass, long id)
{
public <E extends BaseEntity> E find(Class<E> entityClass, long id) {
return em.find(entityClass, id);
}

public <S> S findSingle(String ql, Object... args)
{
public <S> S findSingle(String ql, Object... args) {
Query query = createQuery(ql, args);

try {
Expand All @@ -54,8 +50,7 @@ public <S> S findSingle(String ql, Object... args)
}
}

private Query createQuery(String ql, Object... args)
{
private Query createQuery(String ql, Object... args) {
Query query = em.createQuery(ql);

for (int i = 0; i < args.length; i++) {
Expand All @@ -66,16 +61,14 @@ private Query createQuery(String ql, Object... args)
return query;
}

public <E extends BaseEntity> List<E> find(String ql, Object... args)
{
public <E extends BaseEntity> List<E> find(String ql, Object... args) {
Query query = createQuery(ql, args);

@SuppressWarnings("unchecked") List<E> resultList = query.getResultList();
return resultList;
}

public <E extends BaseEntity> List<E> findWithPaging(String ql, int maxResults, int firstResult, Object... args)
{
public <E extends BaseEntity> List<E> findWithPaging(String ql, int maxResults, int firstResult, Object... args) {
Query query = createQuery(ql, args);
query.setMaxResults(maxResults).setFirstResult(firstResult);

Expand Down
Expand Up @@ -24,8 +24,7 @@ public class Authenticator implements Serializable
public String getPassword() { return password; }
public void setPassword(String password) { this.password = password; }

public boolean login()
{
public boolean login() {
User user = userService.findByUsername(username);

if (user != null && user.verifyPassword(password)) {
Expand All @@ -37,8 +36,7 @@ public boolean login()
return false;
}

public void logout()
{
public void logout() {
session.invalidate();
}
}
6 changes: 2 additions & 4 deletions samples/needle4j/src/main/java/blog/user/User.java
Expand Up @@ -36,13 +36,11 @@ public class User extends BaseEntity
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }

public void setPassword(String password)
{
public void setPassword(String password) {
this.password = new BasicPasswordEncryptor().encryptPassword(password);
}

public boolean verifyPassword(String passwordToVerify)
{
public boolean verifyPassword(String passwordToVerify) {
return new BasicPasswordEncryptor().checkPassword(passwordToVerify, password);
}
}
3 changes: 1 addition & 2 deletions samples/needle4j/src/main/java/blog/user/UserService.java
Expand Up @@ -10,8 +10,7 @@ public class UserService
{
@Inject private Database db;

public User findByUsername(String username)
{
public User findByUsername(String username) {
return db.findSingle("select u from User u where u.username = ?1", username);
}
}
Expand Up @@ -14,8 +14,7 @@ public final class BlogEntryListServiceTest
@ObjectUnderTest BlogEntryListService blogEntryListService;

@Test
public void getResultList()
{
public void getResultList() {
BlogEntry blogEntry = blogEntryData.buildAndSave();

List<BlogEntry> resultList = blogEntryListService.getResultList();
Expand All @@ -24,8 +23,7 @@ public void getResultList()
}

@Test
public void pagination()
{
public void pagination() {
createBlogEntries(MAX_RESULTS + 1);

assertEquals(0, blogEntryListService.getFirstResult());
Expand All @@ -43,16 +41,14 @@ public void pagination()
assertTrue(blogEntryListService.isPreviousExists());
}

void createBlogEntries(int quantity)
{
void createBlogEntries(int quantity) {
for (int i = 0; i < quantity; i++) {
blogEntryData.buildAndSave();
}
}

@Test
public void findEntriesUpToMaximumQuantity()
{
public void findEntriesUpToMaximumQuantity() {
createBlogEntries(MAX_RESULTS + 1);

List<BlogEntry> found = blogEntryListService.getResultList();
Expand All @@ -61,8 +57,7 @@ public void findEntriesUpToMaximumQuantity()
}

@Test
public void previousFirstResult()
{
public void previousFirstResult() {
blogEntryListService.setFirstResult(10);

assertEquals(15, blogEntryListService.getNextFirstResult());
Expand Down

0 comments on commit 9d3c88f

Please sign in to comment.