title: spring testng: Failed to load ApplicationContext
body: <p>I am getting failed to load applicationcontext.  The class extending AbstractTestNGSpringContextTests which is applicationcontextaware.  Any help what is missing here? It is a simple spring test file.  I am using spring boot. Do i need to set anything for configuration to get applicationcontext. </p>
  
  <pre><code>java.lang.IllegalStateException: Failed to load ApplicationContext
      at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
      at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
      at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
      at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
      at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246)
      at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextPrepareTestInstance(AbstractTestNGSpringContextTests.java:145)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
      at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
      at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
  </code></pre>
  
  <p>Here is the Test class</p>
  
  <pre><code>@SuppressWarnings("unchecked")
  public class AesGcmDynamoCryptoCipherProviderTest extends AbstractTestNGSpringContextTests {
      @Mock
      AwsCrypto awsCrypto;
      @Mock
      DynamoDBProvider dynamoDBProvider;
      @Mock
      MasterKeyProvider masterKeyProvider;
      @Mock
      Table table;
  
      @Autowired
      ApplicationContext applicationContext;
  
      private static &lt;T&gt; CryptoResult&lt;T, ?&gt; mockCryptoResult(T result) {
          CryptoResult&lt;T, ?&gt; cryptoResult = mock(CryptoResult.class);
          when(cryptoResult.getResult()).thenReturn(result);
          return cryptoResult;
      }
  
      @BeforeMethod
      private void init() {
          MockitoAnnotations.initMocks(this);
          when(dynamoDBProvider.getDynamoDB()).thenReturn(mock(DynamoDB.class));
          when(dynamoDBProvider.getDynamoDB().getTable(anyString())).thenReturn(table);
  
          CryptoResult&lt;String, ?&gt; decryptoResult = mockCryptoResult(Base64.getEncoder().encodeToString("*decrypted*".getBytes()));
          when(awsCrypto.decryptString(eq(masterKeyProvider), anyString())).thenReturn(decryptoResult);
          CryptoResult&lt;String, ?&gt; encryptoResult = mockCryptoResult("*encrypted*");
          when(awsCrypto.encryptString(eq(masterKeyProvider), anyString())).thenReturn(encryptoResult);
      }
  
      @Test
      public void testGetCipher() {
          AesGcmDynamoCryptoCipherProvider provider = new AesGcmDynamoCryptoCipherProvider("table", awsCrypto, dynamoDBProvider, masterKeyProvider);
  
          UUID cipherId = UUID.randomUUID();
  
          Item cipherItem = mockCipherItem(cipherId);
          when(table.getItem(eq("KEY_ID"), eq(cipherId.toString()))).thenReturn(cipherItem);
  
          AesGcmCipher cipher = provider.getCipher(cipherId);
  
          assertNotNull(cipher);
          assertEquals(cipher.getCipherId(), cipherId);
      }
  
  }
  </code></pre>