2 * Copyright © 2016-2017 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.logging.api;
19 import org.testng.annotations.Test;
21 import java.lang.reflect.Field;
22 import java.util.concurrent.Callable;
24 import static org.testng.Assert.assertEquals;
25 import static org.testng.Assert.assertNull;
26 import static org.testng.Assert.assertTrue;
32 public class LoggingContextTest {
35 public void shouldHoldNoOpWhenNoBinding() throws Exception {
36 Field factory = LoggingContext.class.getDeclaredField("SERVICE");
37 factory.setAccessible(true);
38 Object impl = factory.get(null);
39 assertEquals(impl.getClass().getName(),
40 "org.openecomp.sdc.logging.api.LoggingContext$NoOpLoggingContextService");
44 public void putDoesNotHaveEffectWhenNoBinding() {
45 final String key = "Key";
46 LoggingContext.put(key, "Dummy");
47 assertNull(LoggingContext.get(key));
50 @Test(expectedExceptions = NullPointerException.class)
51 public void throwNpeWhenPutWithKeyNull() {
52 LoggingContext.put(null, "value");
56 public void getAlwaysReturnsNull() {
57 assertNull(LoggingContext.get("GetKey"));
60 @Test(expectedExceptions = NullPointerException.class)
61 public void throwNpeWhenGetWithKeyNull() {
62 LoggingContext.get(null);
66 public void removeDoesNotFail() {
67 LoggingContext.remove("RemoveKey");
70 @Test(expectedExceptions = NullPointerException.class)
71 public void throwNpWhenRemoveWithKeyNull() {
72 LoggingContext.remove(null);
76 public void clearDoesNotFail() {
77 LoggingContext.clear();
81 public void toRunnableReturnsSameInstance() {
82 Runnable test = () -> { /* do nothing */ };
83 assertTrue(test == LoggingContext.copyToRunnable(test));
86 @Test(expectedExceptions = NullPointerException.class)
87 public void throwNpeWhenToRunnableWithNull() {
88 LoggingContext.copyToRunnable(null);
92 public void toCallableReturnsSameInstance() {
93 Callable<String> test = () -> "";
94 assertTrue(test == LoggingContext.copyToCallable(test));
97 @Test(expectedExceptions = NullPointerException.class)
98 public void throwNpeWhenToCallableWithNull() {
99 LoggingContext.copyToCallable(null);