|
1 | | -// Copyright 2018 Google LLC |
2 | | -// |
3 | | -// Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | -// you may not use this file except in compliance with the License. |
5 | | -// You may obtain a copy of the License at |
6 | | -// |
7 | | -// https://www.apache.org/licenses/LICENSE-2.0 |
8 | | -// |
9 | | -// Unless required by applicable law or agreed to in writing, software |
10 | | -// distributed under the License is distributed on an "AS IS" BASIS, |
11 | | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | -// See the License for the specific language governing permissions and |
13 | | -// limitations under the License. |
14 | | - |
15 | 1 | package com.google.ads.googleads.lib.utils; |
16 | 2 |
|
17 | | -import com.google.ads.googleads.test.Resource; |
18 | | -import com.google.ads.googleads.test.TestCase; |
19 | | -import com.google.ads.googleads.test.TestSuite; |
20 | | -import com.google.common.base.Charsets; |
21 | | -import com.google.common.truth.Truth; |
22 | | -import com.google.protobuf.FieldMask; |
23 | | -import com.google.protobuf.TextFormat; |
24 | | -import java.io.IOException; |
25 | | -import java.io.InputStream; |
26 | | -import java.io.InputStreamReader; |
27 | | -import java.util.ArrayList; |
28 | | -import java.util.Collection; |
29 | | -import java.util.List; |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | + |
| 5 | +import com.google.ads.googleads.v5.resources.Campaign; |
| 6 | +import com.google.common.collect.ImmutableList; |
30 | 7 | import org.junit.Test; |
31 | 8 | import org.junit.runner.RunWith; |
32 | | -import org.junit.runners.Parameterized; |
33 | | -import org.junit.runners.Parameterized.Parameters; |
| 9 | +import org.junit.runners.JUnit4; |
34 | 10 |
|
35 | | -/** |
36 | | - * Tests the {@link FieldMasks} utility. |
37 | | - */ |
38 | | -@RunWith(Parameterized.class) |
| 11 | +@RunWith(JUnit4.class) |
39 | 12 | public class FieldMasksTest { |
40 | | - @Parameters(name = "{index}: {0}") |
41 | | - public static Collection<Object[]> data() throws IOException { |
42 | | - InputStream stream = FieldMasksTest.class.getResourceAsStream("/testdata/test_cases.textproto"); |
43 | | - Readable readable = new InputStreamReader(stream, Charsets.UTF_8); |
44 | | - |
45 | | - TestSuite.Builder builder = TestSuite.newBuilder(); |
46 | | - TextFormat.merge(readable, builder); |
47 | | - TestSuite testSuite = builder.build(); |
48 | | - |
49 | | - List<Object[]> result = new ArrayList<>(); |
50 | | - for (TestCase testCase : testSuite.getTestCasesList()) { |
51 | | - result.add(new Object[] {testCase.getDescription(), testCase}); |
52 | | - } |
53 | | - return result; |
54 | | - } |
55 | | - |
56 | | - private final TestCase testCase; |
57 | | - |
58 | | - public FieldMasksTest(String description, TestCase testCase) { |
59 | | - this.testCase = testCase; |
60 | | - } |
61 | | - |
62 | | - @Test |
63 | | - public void testFieldMaskCompare() { |
64 | | - FieldMask actual = |
65 | | - FieldMasks.compare(testCase.getOriginalResource(), testCase.getModifiedResource()); |
66 | | - Truth.assertThat(testCase.getExpectedMask()).isEqualTo(actual); |
67 | | - } |
68 | 13 |
|
| 14 | + // Regression test for https://github.com/googleads/google-ads-java/issues/344. |
69 | 15 | @Test |
70 | | - public void testFieldMaskAllSetFieldsOf() { |
71 | | - Resource resource = testCase.getModifiedResource(); |
72 | | - FieldMask actual = FieldMasks.allSetFieldsOf(resource); |
73 | | - FieldMask expected = FieldMasks.compare(resource.getDefaultInstanceForType(), resource); |
74 | | - Truth.assertThat(expected).isEqualTo(actual); |
| 16 | + public void optionalField_withDefaultValue_detectsChange() { |
| 17 | + Campaign.Builder builder = Campaign.newBuilder(); |
| 18 | + builder.getManualCpcBuilder().setEnhancedCpcEnabled(false); |
| 19 | + Campaign campaign = builder.build(); |
| 20 | + assertEquals( |
| 21 | + ImmutableList.of("manual_cpc.enhanced_cpc_enabled"), |
| 22 | + FieldMasks.allSetFieldsOf(campaign).getPathsList()); |
75 | 23 | } |
76 | 24 | } |
0 commit comments