diff --git a/core/modules/field_ui/tests/modules/field_ui_test/lib/Drupal/field_ui_test/Entity/FieldUITestNoBundle.php b/core/modules/field_ui/tests/modules/field_ui_test/lib/Drupal/field_ui_test/Entity/FieldUITestNoBundle.php
deleted file mode 100644
index ce414ef..0000000
--- a/core/modules/field_ui/tests/modules/field_ui_test/lib/Drupal/field_ui_test/Entity/FieldUITestNoBundle.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\field_ui_test\Entity\FieldUITestNoBundle.
- */
-
-namespace Drupal\field_ui_test\Entity;
-
-use Drupal\Core\Entity\Entity;
-
-/**
- * Defines the test Field UI class.
- *
- * @EntityType(
- *   id = "field_ui_test_no_bundle",
- *   label = @Translation("Test Field UI entity, no bundle"),
- *   controllers = {
- *     "storage" = "Drupal\Core\Entity\DatabaseStorageController"
- *   },
- *   fieldable = TRUE
- * )
- */
-class FieldUITestNoBundle extends Entity {
-
-  /**
-   * The entity ID.
-   *
-   * @var int
-   */
-  public $id;
-
-}
diff --git a/core/modules/views/tests/Drupal/views/Tests/Plugin/argument_validator/EntityTest.php b/core/modules/views/tests/Drupal/views/Tests/Plugin/argument_validator/EntityTest.php
index c6a9104..a0fb0a4 100644
--- a/core/modules/views/tests/Drupal/views/Tests/Plugin/argument_validator/EntityTest.php
+++ b/core/modules/views/tests/Drupal/views/Tests/Plugin/argument_validator/EntityTest.php
@@ -64,10 +64,7 @@ protected function setUp() {
 
     $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
 
-    $mock_entity = $this->getMockBuilder('Drupal\Core\Entity\Entity')
-      ->disableOriginalConstructor()
-      ->setMethods(array('bundle', 'access'))
-      ->getMock();
+    $mock_entity = $this->getMockForAbstractClass('Drupal\Core\Entity\Entity', array(), '', FALSE, TRUE, TRUE, array('bundle', 'access'));
     $mock_entity->expects($this->any())
       ->method('bundle')
       ->will($this->returnValue('test_bundle'));
@@ -79,10 +76,7 @@ protected function setUp() {
         array('test_op_3', NULL, TRUE),
       )));
 
-    $mock_entity_bundle_2 = $this->getMockBuilder('Drupal\Core\Entity\Entity')
-      ->disableOriginalConstructor()
-      ->setMethods(array('bundle', 'access'))
-      ->getMock();
+    $mock_entity_bundle_2 = $this->getMockForAbstractClass('Drupal\Core\Entity\Entity', array(), '', FALSE, TRUE, TRUE, array('bundle', 'access'));
     $mock_entity_bundle_2->expects($this->any())
       ->method('bundle')
       ->will($this->returnValue('test_bundle_2'));
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
index 96f482d..c1938d7 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
@@ -7,10 +7,7 @@
 
 namespace Drupal\Tests\Core\Entity;
 
-use Drupal\Core\Config\Entity\ConfigEntityBase;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
-use Drupal\Core\Entity\Entity;
-use Drupal\Core\Routing\UrlGeneratorInterface;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -31,6 +28,13 @@ class EntityUrlTest extends UnitTestCase {
   protected $entityManager;
 
   /**
+   * The mocked URL generator.
+   *
+   * @var \Drupal\Core\Routing\UrlGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $urlGenerator;
+
+  /**
    * {@inheritdoc}
    */
   public static function getInfo() {
@@ -48,9 +52,11 @@ protected function setUp() {
     parent::setUp();
 
     $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
+    $this->urlGenerator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface');
 
     $container = new ContainerBuilder();
     $container->set('entity.manager', $this->entityManager);
+    $container->set('url_generator', $this->urlGenerator);
     \Drupal::setContainer($container);
   }
 
@@ -63,7 +69,7 @@ protected function setUp() {
    */
   public function testUrlInfo($entity_class, $link_template, $expected) {
     /** @var $entity \Drupal\Core\Entity\EntityInterface */
-    $entity = new $entity_class(array('id' => 'test_entity_id'), 'test_entity_type');
+    $entity = $this->getMockForAbstractClass($entity_class, array(array('id' => 'test_entity_id'), 'test_entity_type'));
 
     $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
     $entity_type->expects($this->once())
@@ -100,13 +106,13 @@ public function testUrlInfo($entity_class, $link_template, $expected) {
    */
   public function providerTestUrlInfo() {
     return array(
-      array('Drupal\Tests\Core\Entity\TestEntity', 'canonical', FALSE),
-      array('Drupal\Tests\Core\Entity\TestEntity', 'edit-form', 'test_entity_type.edit'),
-      array('Drupal\Tests\Core\Entity\TestEntity', FALSE, FALSE),
-      array('Drupal\Tests\Core\Entity\TestConfigEntity', 'canonical', FALSE),
-      array('Drupal\Tests\Core\Entity\TestConfigEntity', 'edit-form', 'test_entity_type.edit'),
+      array('Drupal\Core\Entity\Entity', 'canonical', FALSE),
+      array('Drupal\Core\Entity\Entity', 'edit-form', 'test_entity_type.edit'),
+      array('Drupal\Core\Entity\Entity', FALSE, FALSE),
+      array('Drupal\Core\Config\Entity\ConfigEntityBase', 'canonical', FALSE),
+      array('Drupal\Core\Config\Entity\ConfigEntityBase', 'edit-form', 'test_entity_type.edit'),
       // Test that overriding the default $rel parameter works.
-      array('Drupal\Tests\Core\Entity\TestConfigEntity', FALSE, 'test_entity_type.edit'),
+      array('Drupal\Core\Config\Entity\ConfigEntityBase', FALSE, 'test_entity_type.edit'),
     );
   }
 
@@ -120,7 +126,7 @@ public function providerTestUrlInfo() {
    * @expectedException \Drupal\Core\Entity\EntityMalformedException
    */
   public function testUrlInfoForNewEntity() {
-    $entity = new TestEntity(array(), 'test_entity_type');
+    $entity = $this->getMockForAbstractClass('Drupal\Core\Entity\Entity', array(array(), 'test_entity_type'));
     $entity->urlInfo();
   }
 
@@ -143,16 +149,14 @@ public function testUrl() {
       ->with('test_entity_type')
       ->will($this->returnValue($entity_type));
 
-    $invalid_entity = new TestEntity(array(), 'test_entity_type');
+    $invalid_entity = $this->getMockForAbstractClass('Drupal\Core\Entity\Entity', array(array(), 'test_entity_type'));
     $this->assertSame('', $invalid_entity->url());
 
-    $no_link_entity = new TestEntity(array('id' => 'test_entity_id'), 'test_entity_type');
+    $no_link_entity = $this->getMockForAbstractClass('Drupal\Core\Entity\Entity', array(array('id' => 'test_entity_id'), 'test_entity_type'));
     $this->assertSame('', $no_link_entity->url('banana'));
 
-    $valid_entity = new TestEntity(array('id' => 'test_entity_id'), 'test_entity_type');
-    $url_generator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface');
-    $valid_entity->setUrlGenerator($url_generator);
-    $url_generator->expects($this->exactly(2))
+    $valid_entity = $this->getMockForAbstractClass('Drupal\Core\Entity\Entity', array(array('id' => 'test_entity_id'), 'test_entity_type'));
+    $this->urlGenerator->expects($this->exactly(2))
       ->method('generateFromRoute')
       ->will($this->returnValueMap(array(
         array(
@@ -195,17 +199,18 @@ public function testUrlForAdminForm() {
       ->with('test_entity_type')
       ->will($this->returnValue($entity_type));
 
-    $url_generator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface');
-    $url_generator->expects($this->once())
+    $this->urlGenerator->expects($this->once())
       ->method('generateFromRoute')
       ->with('test_entity_type.admin_form', array(
-        'test_entity_type_bundle' => 'test_entity_bundle',
         'test_entity_type' => 'test_entity_id',
+        'test_entity_type_bundle' => 'test_entity_bundle',
       ))
       ->will($this->returnValue('entity/test_entity_type/test_entity_bundle/test_entity_id'));
 
-    $entity = new TestEntityWithBundle(array('id' => 'test_entity_id', 'bundle' => 'test_entity_bundle'), 'test_entity_type');
-    $entity->setUrlGenerator($url_generator);
+    $entity = $this->getMockForAbstractClass('Drupal\Core\Entity\Entity', array(array('id' => 'test_entity_id'), 'test_entity_type'), '', TRUE, TRUE, TRUE, array('bundle'));
+    $entity->expects($this->any())
+      ->method('bundle')
+      ->will($this->returnValue('test_entity_bundle'));
 
     $this->assertSame('entity/test_entity_type/test_entity_bundle/test_entity_id', $entity->url('admin-form'));
   }
@@ -229,17 +234,15 @@ public function testGetSystemPath() {
       ->with('test_entity_type')
       ->will($this->returnValue($entity_type));
 
-    $no_link_entity = new TestEntity(array('id' => 'test_entity_id'), 'test_entity_type');
+    $no_link_entity = $this->getMockForAbstractClass('Drupal\Core\Entity\Entity', array(array('id' => 'test_entity_id'), 'test_entity_type'));
     $this->assertSame('', $no_link_entity->getSystemPath('banana'));
 
-    $url_generator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface');
-    $url_generator->expects($this->once())
+    $this->urlGenerator->expects($this->once())
       ->method('getPathFromRoute')
       ->with('test_entity_type.view', array('test_entity_type' => 'test_entity_id'))
       ->will($this->returnValue('entity/test_entity_type/test_entity_id'));
 
-    $valid_entity = new TestEntity(array('id' => 'test_entity_id'), 'test_entity_type');
-    $valid_entity->setUrlGenerator($url_generator);
+    $valid_entity = $this->getMockForAbstractClass('Drupal\Core\Entity\Entity', array(array('id' => 'test_entity_id'), 'test_entity_type'));
 
     $this->assertSame('entity/test_entity_type/test_entity_id', $valid_entity->getSystemPath());
   }
@@ -252,21 +255,30 @@ public function testGetSystemPath() {
    *
    * @dataProvider providerTestLinkTemplates
    */
-  public function testLinkTemplates($entity_class, $expected) {
+  public function testLinkTemplates($override_templates, $expected) {
     $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
-    $entity_type->expects($this->exactly(2))
+    $entity_type->expects($this->any())
       ->method('getLinkTemplates')
       ->will($this->returnValue(array(
         'canonical' => 'test_entity_type.view',
       )));
 
     $this->entityManager
-      ->expects($this->exactly(2))
+      ->expects($this->any())
       ->method('getDefinition')
       ->with('test_entity_type')
       ->will($this->returnValue($entity_type));
 
-    $entity = new $entity_class(array('id' => 'test_entity_id'), 'test_entity_type');
+    $entity = $this->getMockForAbstractClass('Drupal\Core\Entity\Entity', array(array('id' => 'test_entity_id'), 'test_entity_type'), '', TRUE, TRUE, TRUE, array('linkTemplates'));
+    $entity->expects($this->any())
+      ->method('linkTemplates')
+      ->will($this->returnCallback(function () use ($entity_type, $override_templates) {
+        $templates = $entity_type->getLinkTemplates();
+        if ($override_templates) {
+          $templates['bananas'] = 'test_entity_type.bananas';
+        }
+        return $templates;
+      }));
     $this->assertSame($expected['canonical'], $entity->hasLinkTemplate('canonical'));
     $this->assertSame($expected['bananas'], $entity->hasLinkTemplate('bananas'));
   }
@@ -276,11 +288,11 @@ public function testLinkTemplates($entity_class, $expected) {
    */
   public function providerTestLinkTemplates() {
     return array(
-      array('Drupal\Tests\Core\Entity\TestEntity', array(
+      array(FALSE, array(
         'canonical' => TRUE,
         'bananas' => FALSE,
       )),
-      array('Drupal\Tests\Core\Entity\TestEntityWithTemplates', array(
+      array(TRUE, array(
         'canonical' => TRUE,
         'bananas' => TRUE,
       )),
@@ -288,53 +300,3 @@ public function providerTestLinkTemplates() {
   }
 
 }
-
-class TestConfigEntity extends ConfigEntityBase {
-}
-
-class TestEntity extends Entity {
-
-  /**
-   * Sets the URL generator.
-   *
-   * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
-   *
-   * @return $this
-   */
-  public function setUrlGenerator(UrlGeneratorInterface $url_generator) {
-    $this->urlGenerator = $url_generator;
-    return $this;
-  }
-
-}
-
-class TestEntityWithTemplates extends TestEntity {
-
-  /**
-   * {@inheritdoc}
-   */
-  protected function linkTemplates() {
-    $templates = parent::linkTemplates();
-    $templates['bananas'] = 'test_entity_type.bananas';
-    return $templates;
-  }
-
-}
-
-class TestEntityWithBundle extends TestEntity {
-
-  /**
-   * The entity bundle.
-   *
-   * @var string
-   */
-  protected $bundle;
-
-  /**
-   * {@inheritdoc}
-   */
-  public function bundle() {
-    return $this->bundle;
-  }
-
-}
