|
| 1 | +package io.temporal.client; |
| 2 | + |
| 3 | +import org.junit.Assert; |
| 4 | +import org.junit.Test; |
| 5 | + |
| 6 | +/** |
| 7 | + * Pure unit tests for {@link StartNexusOperationOptions.Builder} input validation. ID is required — |
| 8 | + * callers must supply a non-empty value via {@link StartNexusOperationOptions.Builder#setId} and |
| 9 | + * the SDK does not invent one on their behalf. |
| 10 | + */ |
| 11 | +public class StartNexusOperationOptionsTest { |
| 12 | + |
| 13 | + @Test |
| 14 | + public void buildThrowsWhenIdNotSet() { |
| 15 | + try { |
| 16 | + StartNexusOperationOptions.newBuilder().build(); |
| 17 | + Assert.fail("expected IllegalStateException when id is unset"); |
| 18 | + } catch (IllegalStateException expected) { |
| 19 | + Assert.assertTrue( |
| 20 | + "error message should mention setId, got: " + expected.getMessage(), |
| 21 | + expected.getMessage() != null && expected.getMessage().contains("setId")); |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + public void setIdRejectsNull() { |
| 27 | + try { |
| 28 | + StartNexusOperationOptions.newBuilder().setId(null); |
| 29 | + Assert.fail("expected NullPointerException when setId is called with null"); |
| 30 | + } catch (NullPointerException expected) { |
| 31 | + // expected |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void setIdRejectsEmpty() { |
| 37 | + try { |
| 38 | + StartNexusOperationOptions.newBuilder().setId(""); |
| 39 | + Assert.fail("expected IllegalArgumentException when setId is called with an empty string"); |
| 40 | + } catch (IllegalArgumentException expected) { |
| 41 | + Assert.assertTrue( |
| 42 | + "error message should mention empty, got: " + expected.getMessage(), |
| 43 | + expected.getMessage() != null && expected.getMessage().contains("empty")); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void buildSucceedsWithNonEmptyId() { |
| 49 | + StartNexusOperationOptions options = |
| 50 | + StartNexusOperationOptions.newBuilder().setId("my-id").build(); |
| 51 | + Assert.assertEquals("my-id", options.getId()); |
| 52 | + } |
| 53 | +} |
0 commit comments