Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Unified Diff: ios/chrome/browser/content_suggestions/content_suggestions_category_wrapper_unittest.mm

Issue 2689953003: Add Category wrapper for ContentSuggestions on iOS (Closed)
Patch Set: Fix title copu Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/content_suggestions/content_suggestions_category_wrapper_unittest.mm
diff --git a/ios/chrome/browser/content_suggestions/content_suggestions_category_wrapper_unittest.mm b/ios/chrome/browser/content_suggestions/content_suggestions_category_wrapper_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..0e18aacf8bdc6201cff8395de9b5a01f0ecfd8fd
--- /dev/null
+++ b/ios/chrome/browser/content_suggestions/content_suggestions_category_wrapper_unittest.mm
@@ -0,0 +1,81 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/content_suggestions/content_suggestions_category_wrapper.h"
+
+#include "components/ntp_snippets/category.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+// Subclass used to test the equality.
+@interface ContentSuggestionsCategoryWrapperSubclassTest
+ : ContentSuggestionsCategoryWrapper
+@end
+
+@implementation ContentSuggestionsCategoryWrapperSubclassTest
+@end
+
+#pragma mark - Tests.
+
+// Tests that the category returned by the wrapper is the one given in the
+// initializer.
+TEST(ContentSuggestionsCategoryWrapperTest, GetCategory) {
+ // Setup.
+ ntp_snippets::Category category = ntp_snippets::Category::FromIDValue(2);
+ ContentSuggestionsCategoryWrapper* wrapper =
+ [[ContentSuggestionsCategoryWrapper alloc] initWithCategory:category];
+
+ // Action/Tests.
+ EXPECT_EQ(category, wrapper.category);
+}
+
+// Tests that two wrappers created with equal categories are equal.
+TEST(ContentSuggestionsCategoryWrapperTest, AreWrappersEqual) {
+ // Setup.
+ ntp_snippets::Category category = ntp_snippets::Category::FromIDValue(2);
+ ContentSuggestionsCategoryWrapper* wrapper =
+ [[ContentSuggestionsCategoryWrapper alloc] initWithCategory:category];
+ ntp_snippets::Category category2 = ntp_snippets::Category::FromIDValue(2);
+ ContentSuggestionsCategoryWrapper* wrapper2 =
+ [[ContentSuggestionsCategoryWrapper alloc] initWithCategory:category2];
+ ASSERT_EQ(category, category2);
+
+ // Action/Tests.
+ EXPECT_TRUE([wrapper isEqual:wrapper2]);
+ EXPECT_EQ(wrapper.hash, wrapper2.hash);
+}
+
+// Tests that two wrappers created with different categories are not equal.
+TEST(ContentSuggestionsCategoryWrapperTest, AreWrappersDifferent) {
+ // Setup.
+ ntp_snippets::Category category = ntp_snippets::Category::FromIDValue(2);
+ ContentSuggestionsCategoryWrapper* wrapper =
+ [[ContentSuggestionsCategoryWrapper alloc] initWithCategory:category];
+ ntp_snippets::Category category2 = ntp_snippets::Category::FromIDValue(3);
+ ContentSuggestionsCategoryWrapper* wrapper2 =
+ [[ContentSuggestionsCategoryWrapper alloc] initWithCategory:category2];
+ ASSERT_NE(category, category2);
+
+ // Action/Test.
+ EXPECT_FALSE([wrapper isEqual:wrapper2]);
+}
+
+// Tests the equality between a wrapper an different type of objects.
+TEST(ContentSuggestionsCategoryWrapperTest, DifferentObject) {
+ // Setup.
+ ntp_snippets::Category category = ntp_snippets::Category::FromIDValue(2);
+ ContentSuggestionsCategoryWrapper* wrapper =
+ [[ContentSuggestionsCategoryWrapper alloc] initWithCategory:category];
+ NSObject* object = [[NSObject alloc] init];
+ ContentSuggestionsCategoryWrapperSubclassTest* subclass =
+ [[ContentSuggestionsCategoryWrapperSubclassTest alloc]
+ initWithCategory:category];
+
+ // Action/Tests.
+ ASSERT_FALSE([wrapper isEqual:object]);
+ ASSERT_TRUE([wrapper isEqual:subclass]);
+}

Powered by Google App Engine
This is Rietveld 408576698