Skip to content

Commit

Permalink
removed code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed Nov 25, 2024
1 parent 609e032 commit 9a6f3a7
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class LockManager {
*
* @return the lists of transactions
*/
@SuppressWarnings("unchecked")
public List<String> getAllTransactions() {
try {
return genericDao.queryForList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ protected void runTask() throws TaskException {
errors = 0;
indexed = 0;
indexingTime = 0;
parsingTime = 0;
try {
Integer max = getMax();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ protected Collection<Long> getAccessibleFolderIds() throws SearchException {
*
* @throws SearchException error in the data layer
*/
@SuppressWarnings("unchecked")
protected Set<Long> getDeniedDocIds(List<Hit> hits, Collection<Long> accessibleFolderIds) throws SearchException {
HashSet<Long> denied = new HashSet<>();
if (searchUser.isAdmin() || hits.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class TagSearch extends Search {
protected TagSearch() {
}

@SuppressWarnings("unchecked")
@Override
public void internalSearch() throws SearchException {
DocumentDAO dao = Context.get().getBean(DocumentDAO.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class FolderSearch extends Search {

private String query;

@SuppressWarnings("unchecked")
@Override
public void internalSearch() throws SearchException {
UserDAO userDAO = Context.get().getBean(UserDAO.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.logicaldoc.util.junit;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;

import java.io.File;
Expand All @@ -14,8 +13,6 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import javax.sql.DataSource;

Expand All @@ -34,6 +31,7 @@
import com.logicaldoc.util.io.FileUtil;
import com.logicaldoc.util.plugin.PluginException;
import com.logicaldoc.util.plugin.PluginRegistry;
import com.logicaldoc.util.time.Pause;

/**
* Abstract test case that of database and context initialization.
Expand Down Expand Up @@ -218,8 +216,6 @@ protected Connection getConnection() throws SQLException {
}

protected void waiting() throws InterruptedException {
final int secondsToWait = 5;
CountDownLatch latch = new CountDownLatch(1);
assertFalse(latch.await(secondsToWait, TimeUnit.SECONDS));
Pause.doPause(5000L);
}
}
23 changes: 23 additions & 0 deletions logicaldoc-util/src/main/java/com/logicaldoc/util/time/Pause.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.logicaldoc.util.time;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
* A simple class to pause the current thread
*
* @author Marco Meschieri - LogicalDOC
* @since 9.0.1
*/
public abstract class Pause {

private Pause() {
// Empty
}

public static void doPause(long ms) throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
if (latch.await(ms, TimeUnit.MILLISECONDS))
throw new IllegalStateException("Unexpected latch status");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.logicaldoc.util.time;

import static org.junit.Assert.assertEquals;

import java.util.Date;

import org.junit.Test;

import com.logicaldoc.util.junit.AbstractTestCase;
import com.logicaldoc.util.time.TimeDiff.TimeField;

public class PauseTest extends AbstractTestCase {

@Test
public void testDoPause() throws InterruptedException {
Date date1 = new Date();
Pause.doPause(2000);
Date date2 = new Date();

assertEquals(2L, TimeDiff.getTimeDifference(date1, date2, TimeField.SECOND));
}
}

0 comments on commit 9a6f3a7

Please sign in to comment.