Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e7b29847 authored by Yigit Boyar's avatar Yigit Boyar
Browse files

added test for binding to a final field

Change-Id: I0945b0128c390cd6f91337359c16fd9d94735550
parent 49f8a826
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *      http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.databinding.testapp;

import com.android.databinding.testapp.generated.BindToFinalBinder;
import com.android.databinding.testapp.vo.PublicFinalTestVo;

import android.test.UiThreadTest;
import android.widget.TextView;

public class BindToFinalFieldTest extends BaseDataBinderTest<BindToFinalBinder>{

    public BindToFinalFieldTest() {
        super(BindToFinalBinder.class, R.layout.bind_to_final);
    }

    @UiThreadTest
    public void testSimple() {
        final PublicFinalTestVo vo = new PublicFinalTestVo(R.string.app_name);
        mBinder.setObj(vo);
        mBinder.rebindDirty();
        final TextView textView = (TextView) mBinder.getRoot().findViewById(R.id.text_view);
        assertEquals(getActivity().getResources().getString(R.string.app_name), textView.getText().toString());
    }


}
+6 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ public class NotBindableVo {
    private int mBoolValueGetCount;
    private String mStringValue;
    private int mStringValueGetCount;
    private final String mFinalString = "this has final content";
    public final int publicField = 3;

    public NotBindableVo() {
    }
@@ -42,6 +44,10 @@ public class NotBindableVo {
        return mIntValue;
    }

    public String getFinalString() {
        return mFinalString;
    }

    public void setIntValue(int intValue) {
        this.mIntValue = intValue;
    }
+21 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *      http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.databinding.testapp.vo;

public class PublicFinalTestVo {
    public final int myField;
    public PublicFinalTestVo(int field) {
        myField = field;
    }
}
+23 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2015 The Android Open Source Project
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <variable name="obj" type="com.android.databinding.testapp.vo.PublicFinalTestVo"/>
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:id="@+id/text_view"
            android:text="@{obj.myField}"/>
</LinearLayout>
 No newline at end of file