diff --git a/coffee.module b/coffee.module
index e3bc8ae..5d4400b 100644
--- a/coffee.module
+++ b/coffee.module
@@ -8,13 +8,11 @@
 use Drupal\Core;
 
 /**
- * Implements hook_page_build().
+ * Implements hook_page_attachments().
  */
-function coffee_page_build(&$page) {
-  // Access check.
-  $account = \Drupal::currentUser();
-  if ($account->hasPermission('access coffee')) {
-    $page['#attached']['library'][] = 'coffee/drupal.coffee';
+function coffee_page_attachments(&$attachments) {
+  if (\Drupal::currentUser()->hasPermission('access coffee')) {
+    $attachments['#attached']['library'][] = 'coffee/drupal.coffee';
   }
 }
 
diff --git a/src/Tests/CoffeeTest.php b/src/Tests/CoffeeTest.php
new file mode 100644
index 0000000..ce644bf
--- /dev/null
+++ b/src/Tests/CoffeeTest.php
@@ -0,0 +1,72 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\coffee\Tests\CoffeeTest.
+ */
+
+namespace Drupal\coffee\Tests;
+
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Tests Coffee module functionality.
+ *
+ * @group coffee
+ */
+class CoffeeTest extends WebTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = ['coffee'];
+
+  /**
+   * The user for tests.
+   *
+   * @var \Drupal\user\UserInterface
+   */
+  protected $webUser;
+
+  /**
+   * The user for tests.
+   *
+   * @var \Drupal\user\UserInterface
+   */
+  protected $coffeeUser;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp(){
+    parent::setUp();
+
+    $this->webUser = $this->drupalCreateUser();
+    $this->coffeeUser = $this->drupalCreateUser(['access coffee']);
+  }
+
+  /**
+   * Tests that the coffee assets are loaded properly.
+   */
+  public function testCoffeeAssets() {
+    // Ensure that the coffee assets are not loaded for users without the
+    // adequate permission.
+    $this->drupalGet('');
+    $this->assertNoRaw('modules/coffee/js/coffee.js');
+
+    // Ensure that the coffee assets are loaded properly for users with the
+    // adequate permission.
+    $this->drupalLogin($this->coffeeUser);
+    $this->drupalGet('');
+    $this->assertRaw('modules/coffee/js/coffee.js');
+
+    // Ensure that the coffee assets are not loaded for users without the
+    // adequate permission.
+    $this->drupalLogin($this->webUser);
+    $this->drupalGet('');
+    $this->assertNoRaw('modules/coffee/js/coffee.js');
+  }
+
+}
