Skip to content

Commit

Permalink
fix: added test coverage for ServiceConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Peterson <[email protected]>
  • Loading branch information
mattp-swirldslabs committed Sep 11, 2024
1 parent 7e1e99c commit d389b6f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@
import com.swirlds.config.api.ConfigProperty;

@ConfigData("service")
public record ServiceConfig(@ConfigProperty(defaultValue = "1000") int delayMillis) {}
public record ServiceConfig(@ConfigProperty(defaultValue = "1000") int delayMillis) {
public ServiceConfig {
if (delayMillis <= 0) {
throw new IllegalArgumentException("Delay milliseconds must be greater than 0");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed 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 com.hedera.block.server.service;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;

public class ServiceConfigTest {
@Test
public void testServiceConfig_happyPath() {
ServiceConfig serviceConfig = new ServiceConfig(2000);
assertEquals(2000, serviceConfig.delayMillis());
}

@Test
public void testServiceConfig_negativeDelayMillis() {
IllegalArgumentException exception =
assertThrows(IllegalArgumentException.class, () -> new ServiceConfig(-1));
assertEquals("Delay milliseconds must be greater than 0", exception.getMessage());
}
}

0 comments on commit d389b6f

Please sign in to comment.