Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ public Worker newWorker(String taskQueue) {
*/
public synchronized Worker newWorker(String taskQueue, WorkerOptions options) {
Preconditions.checkArgument(
!Strings.isNullOrEmpty(taskQueue), "taskQueue should not be an empty string");
!Strings.isNullOrEmpty(taskQueue) && !taskQueue.trim().isEmpty(),
"taskQueue should not be an empty or blank string");
Preconditions.checkState(
state == State.Initial,
String.format(statusErrorMessage, "create new worker", state.name(), State.Initial.name()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.temporal.worker;

import static org.junit.Assert.assertThrows;

import io.temporal.testing.TestWorkflowEnvironment;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class WorkerFactoryValidationTest {

private TestWorkflowEnvironment env;

@Before
public void setUp() {
env = TestWorkflowEnvironment.newInstance();
}

@After
public void tearDown() {
env.close();
}

@Test
public void newWorkerRejectsNullTaskQueue() {
assertThrows(IllegalArgumentException.class, () -> env.getWorkerFactory().newWorker(null));
}

@Test
public void newWorkerRejectsEmptyTaskQueue() {
assertThrows(IllegalArgumentException.class, () -> env.getWorkerFactory().newWorker(""));
}

@Test
public void newWorkerRejectsBlankTaskQueue() {
assertThrows(IllegalArgumentException.class, () -> env.getWorkerFactory().newWorker(" "));
}
}