From d163be3b87f571e2b019fd6588022b11408d9ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezgi=20=C3=87i=C3=A7ek?= Date: Wed, 2 Oct 2019 03:19:04 -0700 Subject: [PATCH] [required-props] Added tests for Component.Builder prop added in the chain of calls. Summary: Component.Builder has its own non-required props that are inherited by the MyComponent.Builder. Add tests where these common props are set in the chain of calls. Reviewed By: Katalune Differential Revision: D17710294 fbshipit-source-id: f3c5ef28c --- .../codetoanalyze/java/litho/Column.java | 5 +++ .../codetoanalyze/java/litho/Component.java | 8 +++- .../java/litho/RequiredProps.java | 37 +++++++++++++++++-- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/infer/tests/codetoanalyze/java/litho/Column.java b/infer/tests/codetoanalyze/java/litho/Column.java index 228a0d10e..b63386004 100644 --- a/infer/tests/codetoanalyze/java/litho/Column.java +++ b/infer/tests/codetoanalyze/java/litho/Column.java @@ -41,5 +41,10 @@ public class Column extends Component { public Column build() { return mColumn; } + + @Override + public Builder getThis() { + return this; + } } } diff --git a/infer/tests/codetoanalyze/java/litho/Component.java b/infer/tests/codetoanalyze/java/litho/Component.java index 593047e3f..a72ae84b9 100644 --- a/infer/tests/codetoanalyze/java/litho/Component.java +++ b/infer/tests/codetoanalyze/java/litho/Component.java @@ -9,8 +9,14 @@ package com.facebook.litho; public class Component { - public abstract static class Builder { + public abstract static class Builder> { public abstract Component build(); + + public abstract T getThis(); + + public T commonProp(Object prop) { + return getThis(); + } } } diff --git a/infer/tests/codetoanalyze/java/litho/RequiredProps.java b/infer/tests/codetoanalyze/java/litho/RequiredProps.java index 900558249..b6218feba 100644 --- a/infer/tests/codetoanalyze/java/litho/RequiredProps.java +++ b/infer/tests/codetoanalyze/java/litho/RequiredProps.java @@ -31,7 +31,7 @@ class MyComponent extends Component { return new Builder(); } - static class Builder extends Component.Builder { + static class Builder extends Component.Builder { MyComponent mMyComponent; public Builder prop1(Object o) { @@ -52,6 +52,11 @@ class MyComponent extends Component { public MyComponent build() { return mMyComponent; } + + @Override + public Builder getThis() { + return this; + } } } @@ -64,7 +69,7 @@ class MyTreeComponent extends Component { return new Builder(); } - static class Builder extends Component.Builder { + static class Builder extends Component.Builder { MyTreeComponent mMyTreeComponent; public Builder prop1(Object o) { @@ -75,6 +80,11 @@ class MyTreeComponent extends Component { public MyTreeComponent build() { return mMyTreeComponent; } + + @Override + public Builder getThis() { + return this; + } } } @@ -91,7 +101,7 @@ class ResPropComponent extends Component { return new Builder(); } - static class Builder extends Component.Builder { + static class Builder extends Component.Builder { ResPropComponent mResPropComponent; @@ -128,6 +138,11 @@ class ResPropComponent extends Component { public ResPropComponent build() { return mResPropComponent; } + + @Override + public Builder getThis() { + return this; + } } } @@ -141,7 +156,7 @@ class VarArgPropComponent extends Component { return new Builder(); } - static class Builder extends Component.Builder { + static class Builder extends Component.Builder { VarArgPropComponent mVarArgPropComponent; @@ -194,6 +209,11 @@ class VarArgPropComponent extends Component { public VarArgPropComponent build() { return mVarArgPropComponent; } + + @Override + public Builder getThis() { + return this; + } } } @@ -227,6 +247,15 @@ public class RequiredProps { return mMyComponent.create().prop1(new Object()).prop2(new Object()).build(); } + public Component buildWithCommonPropOk() { + return mMyComponent + .create() + .prop1(new Object()) + .commonProp(new Object()) + .prop3(new Object()) + .build(); + } + private static MyComponent.Builder setProp1(MyComponent.Builder builder) { return builder.prop1(new Object()); }