Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@samtstern
Copy link
Contributor

These changes look breaking but they're actually safe, the major version number was to escape the version-range hell created by the previous release.

Change-Id: I4f294892ec3fcac175a567b5fecf6cf7715930a0
@SUPERCILEX
Copy link
Collaborator

Hmmm... "non-breaking" updates but our tests start failing 🤔😂. I'm just messing with you, but yeah, our tests broke for whatever reason.

@samtstern
Copy link
Contributor Author

@SUPERCILEX I am getting some very strange mockito failures on all tests. Fixing...

@samtstern
Copy link
Contributor Author

Ok I have absolutely no idea what is going on. And I don't actually think any of our tests were running before ...

@SUPERCILEX
Copy link
Collaborator

Huh, we are using a dynamic version for mockito so maybe try using a fixed one that we know works?

@samtstern
Copy link
Contributor Author

Oh wait I know what it is.

This beauty definitely stopped working:

    private static void injectMockFirebaseAuth(FirebaseApp app) {
        for (Field field : FirebaseAuth.class.getDeclaredFields()) {
            field.setAccessible(true);

            Object o;
            try {
                o = field.get(null);
            } catch (IllegalAccessException e) {
                throw new IllegalStateException(e);
            } catch (NullPointerException e) {
                continue;
            }

            Type genericType = field.getGenericType();
            if (o instanceof Map && genericType instanceof ParameterizedType) {
                Type[] parameterTypes = ((ParameterizedType) genericType).getActualTypeArguments();
                if (parameterTypes.length != 2 || parameterTypes[0] != String.class
                        || parameterTypes[1] != FirebaseAuth.class) {
                    continue;
                }

                //noinspection unchecked
                Map<String, FirebaseAuth> instances = (Map<String, FirebaseAuth>) o;

                FirebaseAuth.getInstance(app);
                for (String id : instances.keySet()) {
                    instances.put(id, mock(FirebaseAuth.class));
                }

                break;
            }
        }

@SUPERCILEX
Copy link
Collaborator

Ouch, so is FirebaseAuth storing instances of itself differently? Do you want me to take a look or are you good?

Change-Id: I5b5495b15e1a9928eee12b9c05f3fb655b753802
@samtstern
Copy link
Contributor Author

I think I can figure it out. I am now at the point where my tests are green in Android Studio but red on the command line ... man Android testing is a joke!

Change-Id: I5f0bc8c15ea12086e5005965018cd61154e8e661
@SUPERCILEX
Copy link
Collaborator

Haha, it's usually the other way around for me. 😉 Fingers crossed 🤞, right? 😂

@samtstern
Copy link
Contributor Author

samtstern commented May 23, 2018

Ok they are all failing like this:

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Invalid use of argument matchers!
0 matchers expected, 1 recorded:
-> at com.firebase.ui.auth.testhelpers.TestHelper.injectMockFirebaseAuth(TestHelper.java:135)

This exception may occur if matchers are combined with raw values:
    //incorrect:
    someMethod(anyObject(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
    //correct:
    someMethod(anyObject(), eq("String by matcher"));

For more info see javadoc for Matchers class.

Here's the line it doesn't like in TestHelper:

        FirebaseAuth mockAuth = FirebaseAuth.getInstance(app);
        when(mockAuth.setFirebaseUIVersion(anyString()))  // <----- THIS ONE
                .thenReturn(Tasks.<Void>forResult(null));

@SUPERCILEX any ideas?

@SUPERCILEX
Copy link
Collaborator

Yup, as feared, the map is gone:
image

I'm looking into where it went.

@SUPERCILEX
Copy link
Collaborator

Well darn, there's a new ComponentContainer interface which means we have to mess with that instead.

@SUPERCILEX
Copy link
Collaborator

Alright, I think I got it.

@SUPERCILEX
Copy link
Collaborator

@samtstern Ok, so things aren't looking too pretty. After investigating for ages how we could inject auth into the final ComponentContainer implementation, I realized that we don't even need to do it anymore since the setFirebaseUIVersion method is wrapped in a try catch anyway. (So that means you should be able to nuke the entire injectMockFirebaseAuth method.) However, now I can't get FirebaseAuth to not be null... it's kinda hard to understand how the components are added with minified and obfuscated source code. 😢 To me it looks like the component providers should be coming from the manifest, but I'm not sure.

@samtstern
Copy link
Contributor Author

samtstern commented May 24, 2018 via email

Change-Id: I4b4c8aa0c26738bdaa74dac846194c59744ca73a
@samtstern
Copy link
Contributor Author

@SUPERCILEX after looking at how FirebaseAuth.getInstance(FirebaseApp) works now, it's a lot more complicated and not something we really want to be messing with via reflection, especially since a lot of the things we will depend on are obfuscated.

I have put in a very simple (and temporary) hack to get tests to pass: a protected static FirebaseAuth variable on AuthUI that can be overridden for testing.

Given that we really need to ship 4.0 to make the deadline for GDPR, I am inclined to go ahead with this testing hack and fix it in the next release by doing better injection of FirebaseAuth.

@samtstern samtstern merged commit fa4c6ed into version-4.0.0-dev May 24, 2018
@samtstern
Copy link
Contributor Author

Wow squash and merge is very broken.

@SUPERCILEX
Copy link
Collaborator

@samtstern #1337 addresses the testing hacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants