/*
 * Copyright 2015, Teradata, Inc. All rights reserved.
 */

package com.teradata.test.context;

import static com.google.common.base.Preconditions.checkState;

/**
 * Static helper for holding TestContext in thread local variable.
 *
 * Justification for existence:
 *
 * Using thread local for holding current TestContext is less explicit
 * and a bit hacky. But allows for having less verbose test building blocks.
 *
 * We also do not require users to subclass a common context-aware test class
 * when they write tests.
 */
public class ThreadLocalTestContextHolder
{
    private static ThreadLocal<TestContext> testContextThreadLocal = new ThreadLocal<>();

    public static void assertTestContextNotSet() {
        checkState(testContextThreadLocal.get() == null);
    }

    public static void clearTestContext() {
        testContextThreadLocal.set(null);
    }

    public static void setTestContext(TestContext testContext) {
        testContextThreadLocal.set(testContext);
    }

    public static TestContext testContext() {
        TestContext testContext = testContextThreadLocal.get();
        checkState(testContext != null, "test context not set for current thread");
        return testContext;
    }
}

@@ -229,17 +229,21 @@
 able.%0A *
+ %3Cp%3E
 %0A
-
  * Justi
@@ -268,16 +268,20 @@
 ence:%0A *
+ %3Cp%3E
 %0A * Usin
@@ -423,16 +423,20 @@
 ocks.%0A *
+ %3Cp%3E
 %0A * We a
@@ -543,16 +543,22 @@
 %0Apublic 
+final 
 class Th
@@ -677,16 +677,63 @@
 l%3C%3E();%0A%0A
+    private ThreadLocalTestContextHolder() %7B%7D%0A%0A
     publ
@@ -772,16 +772,20 @@
 NotSet()
+%0A   
  %7B%0A     
@@ -877,32 +877,36 @@
 earTestContext()
+%0A   
  %7B%0A        testC
@@ -1003,16 +1003,20 @@
 Context)
+%0A   
  %7B%0A     
@@ -1058,32 +1058,32 @@
 ontext);%0A    %7D%0A%0A
-
     public stati
@@ -1109,16 +1109,20 @@
 ontext()
+%0A   
  %7B%0A     

Make ThreadLocalTestContextHolder final and not custructable