我有以下Java类:
public class A
{
@Autowired
private B b;
public int aFn()
{
int something = b.bFn();
}
}
public class B
{
@Autowired
private C c;
public int bFn()
{
int something = c.cFn();
}
}
public class C
{
public int cFn()
{
return 231;
}
}
Run Code Online (Sandbox Code Playgroud)
以下测试使用Mockito测试上面的代码:
public class test
{
@Autowired
private A a;
private C c;
@Test
public void testA()
{
c = mock(C.class);
when(c.cFn(),anyInt()).thenReturn(something);
assertEquals(0, a.aFn());
}
}
Run Code Online (Sandbox Code Playgroud)
当我调试testA时,我发现真正的c.Cfn()被执行,而不是被模拟的.我在这里做错了什么吗?请帮忙!
我的代码工作正常,但是当我点击提交按钮时,它会显示两次凌空基本网络执行请求,并且我的数据库表会更新两次.
这是我的MainActivity代码:
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkError;
import com.android.volley.NetworkResponse;
import com.android.volley.NoConnectionError;
import com.android.volley.ParseError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.ServerError;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import java.util.HashMap;
import java.util.Map;
public class LoginActivity extends AppCompatActivity {
EditText etUsername, etPassword;
Button bLogin;
final String TAG= this.getClass().getSimpleName();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_login);
etUsername = (EditText) findViewById(R.id.etUserName);
etPassword = (EditText) …Run Code Online (Sandbox Code Playgroud) 该文档称,在针对Android 12 或更高版本的应用程序上,Toast 被截断为两行。我观察到的行为是,在运行 Android 12 或更高版本的设备上安装的应用程序上,Toast 被截断为两行。
具体来说,我的手机更新到 Android 12之前安装的一个应用程序的toast 不会被截断,但如果我将其安装在运行 Android 12 的模拟器上,它的 toast 就会被截断。我的手机更新到 Android 12后重建并安装的另一个应用程序的toast 被截断。
更新:
情况实际上似乎更复杂:行为还取决于设备,并且显然还取决于它是调试版本还是发布版本。被截断其 toast 的同一个应用程序可以在我的手机上使用发布版本正确显示它们,但在模拟器上使用相同的版本版本截断它们。
请注意,这与70307699不同,OP 将其更新targetSdk为 31。我的两个应用程序都targetSdk设置为小于 31。
我怎样才能获得记录的行为并恢复我的祝酒词?
I'm trying to get some data from my Cloud Firestore into my Android App, but I'm having problem with enums. I have saved a String in the Cloud Firestore for the value of the enum, but when I convert the DocumentSnaphot I receive to an object, the app crashes because it's trying to convert the String to an enum based on the enum name (which isn't the same as the value).
The error I get is(I'm sending the value "NLD"): …
Xamarin 新手,我正在尝试在我的跨平台应用程序中创建自定义导航栏。经过一些阅读,我发现我可以在我的 xaml 页面文件中使用标题视图组件,如下所示。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="amici.MyGroups">
<NavigationPage.TitleView>
<StackLayout Orientation="Horizontal" VerticalOptions="Center" Spacing="10">
<Label HorizontalOptions="StartAndExpand" Text="Left"/>
<Label HorizontalOptions="CenterAndExpand" Text="Center"/>
<Label HorizontalOptions="EndAndExpand" Text="Right"/>
</StackLayout>
</NavigationPage.TitleView>
<ContentPage.Content>
<ScrollView>
<Grid x:Name="grid1">
<StackLayout>
<Label Text="Welcome"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
<ActivityIndicator x:Name="WaitIcon" IsRunning="{Binding IsBusy}" VerticalOptions="Center" HorizontalOptions="Center" />
</Grid>
</ScrollView>
</ContentPage.Content>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
我导航到我的页面“MyGroups”,如下所示:Navigation.PushAsync(new MyGroups());。
但是,唯一显示的是带有后退图标箭头的默认导航页面?
显然我错过了一些东西,或者我不明白一些东西。这是否需要在应用程序级别完成?
无法连接到此链接中提到的迎宾 grpc 服务 - https://docs.microsoft.com/en-us/aspnet/core/tutorials/grpc/grpc-start?view=aspnetcore-3.0 从迎宾客户端是使用 grpc.core 库(Grpc.Core.2.24.0和Grpc.Core.Api.2.24.0)从 .net 框架应用程序编写。
下面是我的客户端代码。它适用于非 SSL,但不适用于 SSL
具有非 SSL 的客户端代码(这有效)
var channel = new Channel("localhost:5000", ChannelCredentials.Insecure);
var client = new Greeter.GreeterClient(channel);
var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });
channel.ShutdownAsync().Wait();
Run Code Online (Sandbox Code Playgroud)
带有 SSL 的客户端代码(无法连接)
SslCredentials secureChannel = new SslCredentials();
var channel = new Channel("localhost", 5001, secureChannel);
var client = new Greeter.GreeterClient(channel);
var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" });
channel.ShutdownAsync().Wait();
Run Code Online (Sandbox Code Playgroud)
我使用 SSL 遇到的错误是:
Grpc.Core.RpcException: 'Status(StatusCode=Unavailable, …
我有3个班:
public class SomeDAO {
// that method I'd want to catch and change
public void getObj() { ... }
}
public class MainService {
private Service2 service2;
public void doMain() {
service2.doSomethingAnother();
}
}
public class Service2 {
private SomeDAO someDAO
public void doSomethingAnother() {
someDAO.getObj();
}
}
Run Code Online (Sandbox Code Playgroud)
我所需要的-调用doMain时而是使用自定义someDao.getObj()内service2.doSomethingAnother() :
public TestClass {
@InjectMocks
private final MainService mainService = new MainService();
@InjectMocks
private final Service2 service2 = new Service2();
@Mock
private SomeDAO someDao;
@Test …Run Code Online (Sandbox Code Playgroud)