kirklund commented on code in PR #7662: URL: https://github.com/apache/geode/pull/7662#discussion_r890409212
########## geode-core/src/test/java/org/apache/geode/distributed/ServerStateTest.java: ########## @@ -0,0 +1,204 @@ +/* + * 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 org.apache.geode.distributed; + +import static org.apache.geode.distributed.AbstractLauncher.ServiceState.TO_STRING_STATUS_MESSAGE; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * Unit tests for {@link ServerLauncher.ServerState}. + */ +public class ServerStateTest { + + private String classpath; + private String gemFireVersion; + private String host; + private String javaVersion; + private String jvmArguments; + private String serviceLocation; + private String logFile; + private String memberName; + private Integer pid; + private String port; + private String statusDescription; + private String statusMessage; + private Long timestampTime; + private Long uptime; + private String workingDirectory; + + @BeforeEach + public void setUp() { + classpath = "test_classpath"; + gemFireVersion = "test_gemfireVersion"; + host = "test_host"; + javaVersion = "test_javaVersion"; + jvmArguments = "test_jvmArguments"; + serviceLocation = "test_location"; + logFile = "test_logfile"; + memberName = "test_memberName"; + pid = 6398; + port = "test_port"; + statusDescription = AbstractLauncher.Status.NOT_RESPONDING.getDescription(); + statusMessage = "test_statusMessage"; + timestampTime = 1450728233024L; + uptime = 16291L; + workingDirectory = "test_workingDirectory"; + } + + + @Test + public void fromJsonWithEmptyStringThrowsIllegalArgumentException() { + // given: empty string + String emptyString = ""; + + // when: passed to fromJson + Throwable thrown = catchThrowable(() -> fromJson(emptyString)); + + assertThat(thrown).isInstanceOf(IllegalArgumentException.class) + .hasCauseInstanceOf(NullPointerException.class); + assertThat(thrown.getCause()).isInstanceOf(NullPointerException.class).hasNoCause(); Review Comment: AssertJ added in some more methods like `hasRootCauseInstanceOf` that help a lot in these cases. I'm coding this off of memory but I think it ends up looking like: ``` assertThat(thrown) .isInstanceOf(IllegalArgumentException.class) .hasRootCauseInstanceOf(NullPointerException.class); ``` You probably wouldn't need any sort of assertion about there not being any intermediate causes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@geode.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org