2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.controlloop.actorserviceprovider;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotEquals;
26 import static org.junit.Assert.assertTrue;
28 import org.junit.Before;
29 import org.junit.Test;
31 public class DelayedIdentStringTest {
33 private int countToStringCalls;
34 private Object object;
35 private DelayedIdentString delay;
38 * Initializes fields, including {@link #delay}.
42 countToStringCalls = 0;
44 object = new Object() {
46 public String toString() {
48 return super.toString();
52 delay = new DelayedIdentString(object);
56 public void testToString() {
57 String delayed = delay.toString();
58 assertEquals(1, countToStringCalls);
60 String real = object.toString();
61 assertNotEquals(real, delayed);
63 assertThat(delayed).startsWith("@");
64 assertTrue(delayed.length() > 1);
66 // test case where the object is null
67 assertEquals(DelayedIdentString.NULL_STRING, new DelayedIdentString(null).toString());
69 // test case where the object returns null from toString()
70 object = new Object() {
72 public String toString() {
76 assertEquals(DelayedIdentString.NULL_STRING, new DelayedIdentString(object).toString());
78 // test case where the object's toString() does not include "@"
79 object = new Object() {
81 public String toString() {
85 assertEquals(object.toString(), new DelayedIdentString(object).toString());
89 public void testDelayedIdentString() {
90 // should not have called the object's toString() method yet
91 assertEquals(0, countToStringCalls);