diff --git a/core/lib/Drupal/Component/Plugin/Context/Context.php b/core/lib/Drupal/Component/Plugin/Context/Context.php
index f301583..9c6b93c 100644
--- a/core/lib/Drupal/Component/Plugin/Context/Context.php
+++ b/core/lib/Drupal/Component/Plugin/Context/Context.php
@@ -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..25a3dfe 100644
--- a/core/lib/Drupal/Component/Plugin/Context/ContextDefinitionInterface.php
+++ b/core/lib/Drupal/Component/Plugin/Context/ContextDefinitionInterface.php
@@ -155,6 +155,9 @@ 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..c673607 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php
@@ -86,4 +86,104 @@ public function testGetContextValue($expected, $context_value, $is_required, $da
     }
   }
 
+  /**
+   * Helper to build a mocked Drupal\Component\Plugin\Context\Context object.
+   *
+   * @param int $expected_count
+   *   The number of Constraint objects we expect.
+   * @param string $class_constraint
+   *   Value to mock as returned from
+   *   ContextDefinitionInterface::getConstraint('class').
+   *
+   * @return Drupal\Component\Plugin\Context\Context|mock
+   *   A mocked Drupal\Component\Plugin\Context\Context with all expectations
+   *   set.
+   */
+  protected function mockGetConstraintsContext($expected_count, $class_constraint) {
+    // 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);
+
+    return $context;
+  }
+
+  /**
+   * @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'],
+    ];
+  }
+
+  /**
+   * @return array
+   *   - Number of elements expected in array returned from getConstraints().
+   *   - Value to mock as returned from
+   *     ContextDefinitionInterface::getConstraint('class'). NULL here, which
+   *     should trigger an exception.
+   */
+  public function providerGetConstraintsException() {
+    return [
+      [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_context = $this->mockGetConstraintsContext($expected_count, $class_constraint);
+
+    // Exercise getConstraints().
+    $constraints = $mock_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));
+    // Check that all the constraints returned are Context objects as per the
+    // interface documentation.
+    foreach ($constraints as $constraint) {
+      $this->assertInstanceOf('Drupal\Component\Plugin\Context\Context', $constraint);
+    }
+  }
+
+
+  /**
+   * @covers ::getConstraints
+   * @expectedException Drupal\Component\Plugin\Exception\ContextException
+   * @dataProvider providerGetConstraintsException
+   */
+  public function testGetConstraintsException($expected_count, $class_constraint) {
+    $mock_context = $this->mockGetConstraintsContext($expected_count, $class_constraint);
+
+    // Exercise getConstraints().
+    $constraints = $mock_context->getConstraints();
+  }
+
 }
