diff --git a/core/lib/Drupal/Component/Plugin/Context/Context.php b/core/lib/Drupal/Component/Plugin/Context/Context.php
index f301583..b3f431e 100644
--- a/core/lib/Drupal/Component/Plugin/Context/Context.php
+++ b/core/lib/Drupal/Component/Plugin/Context/Context.php
@@ -37,7 +37,7 @@ class Context implements ContextInterface {
    *   The context definition.
    */
   public function __construct(ContextDefinitionInterface $context_definition) {
-    $this->contextDefinition = $context_definition;
+    $this->setContextDefinition($context_definition);
   }
 
   /**
@@ -78,13 +78,14 @@ public function getContextDefinition() {
   }
 
   /**
-   * Implements \Drupal\Component\Plugin\Context\ContextInterface::getConstraints().
+   * {@inheritdoc}
    */
   public function getConstraints() {
-    if (empty($this->contextDefinition['class'])) {
+    $constraint = $this->getContextDefinition()->getConstraint('class');
+    if (empty($constraint)) {
       throw new ContextException("An error was encountered while trying to validate the context.");
     }
-    return array(new Type($this->contextDefinition['class']));
+    return array(new Type($constraint));
   }
 
   /**
diff --git a/core/lib/Drupal/Component/Plugin/Context/ContextDefinitionInterface.php b/core/lib/Drupal/Component/Plugin/Context/ContextDefinitionInterface.php
index 16fdc8b..07288f6 100644
--- a/core/lib/Drupal/Component/Plugin/Context/ContextDefinitionInterface.php
+++ b/core/lib/Drupal/Component/Plugin/Context/ContextDefinitionInterface.php
@@ -155,6 +155,8 @@ public function addConstraint($constraint_name, $options = NULL);
    * @return array
    *   A validation constraint definition which can be used for instantiating a
    *   \Symfony\Component\Validator\Constraint object.
+   * @throws Drupal\Component\Plugin\Exception\ContextException
+   *   If $constraint_name is not available, this method throws an exception.
    */
   public function getConstraint($constraint_name);
 
diff --git a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php
index 77c78a7..0e996c1 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php
@@ -86,4 +86,55 @@ public function testGetContextValue($expected, $context_value, $is_required, $da
     }
   }
 
+  /**
+   * @return array
+   *   - Number of elements expected in array returned from getConstraints().
+   *   - Value to mock as returned from
+   *     ContextDefinitionInterface::getConstraint('class').
+   */
+  public function providerGetConstraints() {
+    return [
+      [1, '\stdClass'],
+      [0, NULL],
+    ];
+  }
+
+  /**
+   * @covers ::getConstraints
+   * @dataProvider providerGetConstraints
+   */
+  public function testGetConstraints($expected_count, $class_constraint) {
+    // Check whether we're expecting an exception.
+    if (NULL === $class_constraint) {
+      $this->setExpectedException('Drupal\Component\Plugin\Exception\ContextException');
+    }
+
+    // Mock a ContextDefintionInterface object.
+    $context_definition = $this->getMockBuilder('Drupal\Component\Plugin\Context\ContextDefinitionInterface')
+      ->setMethods(array('getConstraint'))
+      ->getMockForAbstractClass();
+    // Set expecations for the context definition object.
+    $context_definition->expects($this->once())
+      ->method('getConstraint')
+      ->with($this->equalTo('class'))
+      ->willReturn($class_constraint);
+
+    // Mock a Context object.
+    $context = $this->getMockBuilder('Drupal\Component\Plugin\Context\Context')
+      ->disableOriginalConstructor()
+      ->setMethods(array('getContextDefinition'))
+      ->getMock();
+    // Set expectations for getContextDefinition().
+    $context->expects($this->once())
+      ->method('getContextDefinition')
+      ->willReturn($context_definition);
+
+    // Exercise getConstraints().
+    $constraints = $context->getConstraints();
+    // Check that getConstraints() returned an array.
+    $this->assertInternalType('array', $constraints);
+    // Check that getConstraints() returned an array of the correct size.
+    $this->assertEquals($expected_count, count($constraints));
+  }
+
 }
