GoogleSignIn.getClient(this, gso) does not exist - get

I have problem, when i tried to make google authentication .getClient(this, gso) steel red and alt+enter does not help!
I tried to make the same in new, clear project, but nothing changed(
private void CreateRequestGoogleSignIn() {
// Configure Google Sign In
GoogleSignInOptions gso = new GoogleSignInOptions
.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
}```

Declare mGoogleSignInClient as an object of GoogleSignInClient like this before you initialize it
private lateinit var mGoogleSignInClient: GoogleSignInClient
then you can use it as you did, like mGoogleSignInClient = GoogleSignIn.getClient(this, gso)
Also don't forget to import GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInClient

The problem was in this line of code:
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
and i change this line:
mGoogleSignInClient = com.google.android.gms.auth.api.signin.GoogleSignIn.getClient(this, gso);

Add this dependency in the build gradle
implementation 'com.google.android.gms:play-services-auth:20.2.0'

Related

How to Mock GetBlobsByHierarchy() from Azure.Storage.Blobs?

Could anyone please help me to mock GetBlobsByHierarchy() from Azure.Storage.Blobs? I need to create mock for the following code in xUnit:
BlobContainerClient container;
var resultSegment = container.GetBlobsByHierarchy(prefix:prefix, delimiter:"/")
.AsPages(continuationToken, segmentSize);
The details of the code is in this Link from Microsoft site. I tried to mock this GetBlobsByHierarchy() function but failed. Please give me some idea/sample.
I resolved my problems. I have created stub class for BlobContainerClient class and overwrite the required functions..
Below are the code sample,
public sealed class StubBlobContainerClient : BlobContainerClient
{
public override Pageable<BlobHierarchyItem> GetBlobsByHierarchy(BlobTraits traits = BlobTraits.None, BlobStates states = BlobStates.None, string delimiter = null, string prefix = null, CancellationToken cancellationToken = default)
{
//implementation
}
}
You are always welcome to share any other way to resolve the issue.

ModelMapper - NPE when trying to skip destination mapping?

A very simple problem which smoked holes in my case. I'm trying to skip userDTO's setPassword every time when I convert User --> UserDTO.
I get NullPointerException, at this line in ModelMapper -
I understand the 'source' mapping is not present but my question is why does it even care about it since I asked it to not set the password at all.
Sorry, I think I'm lacking some basics here with ModelMapper. Thank you for your time and help.
Got help from ModelMapper skip a field and few other links but no luck.
Below is the code
#Bean
public ModelMapper modelMapper() {
ModelMapper mm = new ModelMapper();
mm.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
TypeMap<User, UserDTO> userEntityToDTOMap = mm.createTypeMap(User.class, UserDTO.class);
userEntityToDTOMap.addMappings(a -> a.skip(UserDTO::setPassword));
return mm;
}
public static void main(String[] args) {
BootstrapConfigurationManager mgr = new BootstrapConfigurationManager();
ModelMapper mm = mgr.modelMapper();
mm.getConfiguration().setPropertyCondition(Conditions.isNotNull());
User user = new User();
user.setId(44L);
user.setPassword("password");
UserDTO userDTO = new UserDTO();
userDTO.setEmailAddress("abc#abc.com");
mm.map(user, userDTO);
System.out.println(userDTO.getId());
System.out.println(userDTO.getEmailAddress());
System.out.println(userDTO.getPassword());
}
Ah !!! It was a bug in v 1.1.0. I just upgraded it to 2.3.2 and I no longer get NPE. I should have thought of upgrading the version before posting this question.

how to get current Cucumber feature file name at runtime using Java

I want get current feature file name at runtime using Java. I have scenario info in hook but unable to get feature file
#Before
public void before(final Scenario scenario) {
this.scenario = scenario;
}
Do we have any similar thing to get current Feature file name ??
i am using cucumber version 1.2.4
UPDATE:
This is my implementation for feature names starting with an uppercase letter like in the example:
private String getFeatureFileNameFromScenarioId(Scenario scenario) {
String featureName = "Feature ";
String rawFeatureName = scenario.getId().split(";")[0].replace("-"," ");
featureName = featureName + rawFeatureName.substring(0, 1).toUpperCase() + rawFeatureName.substring(1);
return featureName;
}
ORIGINAL:
I don't know if this is useful for you, but I would suggest to use scenario.getId()
This will give you the feature file name and scenario name, for example:
Feature: Login to the app
Scenario: Login to the app with password
Given I am on the login screen
When I enter my passcode
Then I press the ok button
with scenario.getId() you would get the following:
login-to-the-app;login-to-the-app-with-password
Hope this helps you!
Kotlin 1.5, cucumber-java 6.10.0:
#Before
fun beforeScenario(scenario: Scenario) {
println(scenario.uri)
}
In my case prints:
file:///C:/Users/K.H/git/JvmClient/src/jvmTest/resources/features/C197544.feature
There is an easier way to extract the feature name (without .feature postfix) from Scenario if you can add Apache commons-io on your classpath:
String featureName = FilenameUtils.getBaseName(scenario.getUri().toString());
If you need the full feature file name with postfix you should use the getName(...) method instead:
String fullFeatureName = FilenameUtils.getName(scenario.getUri().toString());
I used the below method at Hooks class
#Before
public void beforeScenario(Scenario scenario){
// scenarioId = "file:///**/src/test/resources/features/namefeature.feature:99"
String scenarioId=scenario.getId();
int start=scenarioId.indexOf(File.separator+"features"+File.separator);
int end=scenarioId.indexOf(".");
String[] featureName=scenarioId.substring(start,end).split(File.separator+"features"+File.separator);
System.out.println("featureName ="+featureName[1]);
}
You can use Reporter to get the current running instance and then extract our the actual feature name from the feature file like so:
Object[] paramNames = Reporter.getCurrentTestResult().getParameters();
String featureName = paramNames[1].toString().replaceAll("^\"+|\"+$", "");
System.out.println("Feature file name: " + featureName);
Create a listener as below
import io.cucumber.plugin.ConcurrentEventListener;
import io.cucumber.plugin.event.EventHandler;
import io.cucumber.plugin.event.EventPublisher;
import io.cucumber.plugin.event.TestCaseStarted;
public class Listener implements ConcurrentEventListener {
#Override
public void setEventPublisher(EventPublisher eventPublisher) {
eventPublisher.registerHandlerFor(TestCaseStarted.class, testCaseStartedEventHandler);
}
private final EventHandler<TestCaseStarted> testCaseStartedEventHandler = event -> {
System.out.println("Current file fame : " + event.getTestCase().getUri().toString());
};
}
And then supply your listener to cucumber as below
"-p", "com.myProject.listener.Listener"
This will give you feature file name !
maybe like this, its return only filename:
private String getFeatureFileNameFromScenarioId(Scenario scenario) {
String[] tab = scenario.getId().split("/");
int rawFeatureNameLength = tab.length;
String featureName = tab[rawFeatureNameLength - 1].split(":")[0];
System.out.println("featureName: " + featureName);
return featureName;
}

Three20 & MonoTouch: TTTabStrip change color doesn't work

I've created a new class that inherits from TTDefaultStyleSheet.
public class BlackStyleSheet : TTDefaultStyleSheet
{
public BlackStyleSheet() : base()
{
Console.WriteLine("BlackStyleSheet created.");
}
public override UIColor TabBarTintColor
{
get
{
Console.WriteLine("BlackStyleSheet.TabBarTintColor returned.");
return UIColor.Black;
}
}
[Export ("tabTintColor")]
public override UIColor TabTintColor
{
get
{
Console.WriteLine("BlackStyleSheet.TabTintColor returned.");
return UIColor.Black;
}
}
}
And I set this custom style sheet as the default in my FinishedLaunching method.
public override void FinishedLaunching (UIApplication application)
{
Three20.TTStyleSheet.GlobalStyleSheet = new BlackStyleSheet();
Three20.TTDefaultStyleSheet.GlobalStyleSheet = new BlackStyleSheet();
Console.WriteLine("Three20 style sheet set.");
}
Then, I create the actual TTTabStrip and TTTabItem elements within my own custom UIViewController's ViewDidLoad() method. The TTTabItem objects are declared at the class level instead of the method level.
tab1 = new TTTabItem("1");
tab2 = new TTTabItem("2");
tab3 = new TTTabItem("3");
TabStrip = new TTTabStrip();
TabStrip.Frame = new RectangleF(0,0,View.Frame.Width, 44);
TabStrip.TabItems = NSArray.FromNSObjects(tab1,tab2,tab3);
TabStrip.SelectedTabIndex = 0;
View.AddSubview(TabStrip);
When the TTDefaultStyleSheet.GlobalStyleSheet property is set to the new custom stylesheet, the app crashes. When this property setting is removed, the app runs perfectly, but the tab strip remains grey.
In all forums I've read (none seem to be MonoTouch-specific), they all indicate that creating your own stylesheet, then setting it to the global stylesheet is the way to go. But this doesn't seem to work for me with MonoTouch.
Does anyone have any ideas?
Thank you,
John K.
I tried your example in XCode with Objective-C and I can confirm that this this approach does work. I also tried for myself with MonoTouch and saw the same results you report.
I have found several problems in the Three20 binding code in the past that seem to cause aborts like this. You can try and fix up the existing binding code or create only the bindings you need from Three20 manually.
http://docs.xamarin.com/ios/advanced_topics/binding_objective-c_types

Form won't display. . . Dooh!

I could use a little help. I got this program to work right then I found out I had to use the MVC design. It seems pretty simple but, my little toy program won't display my forms. HELP!! See the below snipets:
PART OF MIDLET
public MileageMidlet()
{
// First get a blank user form
form = new Form("Bradford Gas Mileage Calculator");
startPage = new StartPageView();
inputScreen = new InputScreen();
calculateMileage = new CalculateMileage();
startCmd = new Command ("Start",Command.SCREEN,5);
clearCmd = new Command ("Clear",Command.SCREEN,1);
enterCmd = new Command ("Enter",Command.SCREEN,1);
exitCmd = new Command("Exit", Command.EXIT, 1);
// Set up event handlers to process user commands
form.setCommandListener(this);
}
public void startApp() {
startPage.createView(form);
form.addCommand(startCmd);
form.addCommand(exitCmd);
// Display initial form
Display.getDisplay(this).setCurrent(form);
}
START PAGE VIEW CLASS
import javax.microedition.lcdui.*;
public class StartPageView
{
StringItem strgItm, strgItm2;
private Command startCmd, exitCmd;
public StartPageView()
{
}
public void createView(Form form)
{
// First get a blank user form
form.deleteAll();
form = new Form("Bradford Gas Mileage Calculator");
strgItm = new StringItem ("","Welcome to the Bradford Mobile Gas Mileage Calculator!");
strgItm2 = new StringItem ("","To obtain you gas mileage please click the start button.");
form.append(strgItm);
form.append(strgItm2);
}
I got nothing! Really literally a blue screen.
}
The issue has nothing to do with MIDP or J2ME. The problem is of the semantics of how arguments are passed to methods.
It;s important to remember that arguments to method are passed by value in Java. The consequence is that when an object that is passed to a method, a copy of that reference is passed. Any changes to the reference of the object in the method does not have any affect outside of it.
Please see this article for more information.
So in your code,
form.deleteAll();
form = new Form("Bradford Gas Mileage Calculator");
Comment the above two lines. Everything should be fine.

Resources