Skip to content

Commit

Permalink
Merge bc6ca62 into 227e4ca
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon6193 committed Jul 2, 2019
2 parents 227e4ca + bc6ca62 commit 7d9c844
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;

import com.usebutton.merchant.module.Features;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -175,6 +177,15 @@ public static void handlePostInstallIntent(@NonNull Context context, @NonNull
context.getPackageName(), getDeviceManager(context));
}

/**
* Button ML features configuration.
*
* @return Button features API
*/
public static Features features() {
return FeaturesImpl.getInstance();
}

private static ButtonRepository getButtonRepository(Context context) {
PersistenceManager persistenceManager =
PersistenceManagerImpl.getInstance(context.getApplicationContext());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* FeaturesImpl.java
*
* Copyright (c) 2019 Button, Inc. (https://usebutton.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

package com.usebutton.merchant;

import com.usebutton.merchant.module.Features;

/**
* Class that handles controls merchant config for features
*/
final class FeaturesImpl implements Features {

private boolean includesIfa = true;

private static Features features;

static Features getInstance() {
if (features == null) {
features = new FeaturesImpl();
}

return features;
}

/**
* Include ifa in api requests
*
* @param includesIfa true or false
*/
@Override
public void setIncludesIfa(boolean includesIfa) {
this.includesIfa = includesIfa;
}

public boolean includesIfa() {
return includesIfa;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Features.java
*
* Copyright (c) 2019 Button, Inc. (https://usebutton.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

package com.usebutton.merchant.module;

/**
* Interface to allow configuration of Merchant Library features
*/
public interface Features {

void setIncludesIfa(boolean includesIfa);

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static junit.framework.TestCase.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
Expand Down Expand Up @@ -149,4 +150,10 @@ public void reportOrder_verifyButtonInternal() {
verify(buttonInternal).reportOrder(any(ButtonRepository.class), any(DeviceManager.class),
eq(order), eq(orderListener));
}

@Test
public void features_verifyInstanceType() {
assertTrue(ButtonMerchant.features() instanceof FeaturesImpl);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* FeaturesImplTest.java
*
* Copyright (c) 2019 Button, Inc. (https://usebutton.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

package com.usebutton.merchant;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class FeaturesImplTest {

private FeaturesImpl features;

@Before
public void setUp() {
features = new FeaturesImpl();
}

@Test
public void setIncludesIfa_verifyIncludesIfa() {
features.setIncludesIfa(false);

assertFalse(features.includesIfa());
}

@Test
public void includesIfa_verifyDefaultValue() {
assertTrue(features.includesIfa());
}
}

0 comments on commit 7d9c844

Please sign in to comment.