Android connectycube not working when using proguard - connectycube

When using proguard connectycube user login is not working for video chat connectycube sdk version 1.8.1.
what are the rules for proguard.

try use snippet below to resolve issues related with connectycube-android-sdk, it should help you:
-keepattributes InnerClasses
-keep class com.connectycube.auth.parsers.** { *; }
-keep class com.connectycube.auth.model.** { *; }
-keep class com.connectycube.core.parser.** { *; }
-keep class com.connectycube.core.model.** { *; }
-keep class com.connectycube.core.server.** { *; }
-keep class com.connectycube.core.rest.** { *; }
-keep class com.connectycube.core.error.** { *; }
-keep class com.connectycube.core.Query { *; }
-keep class com.connectycube.users.parsers.** { *; }
-keep class com.connectycube.users.model.** { *; }
-keep class com.connectycube.chat.parser.** { *; }
-keep class com.connectycube.chat.model.** { *; }
-keep class com.connectycube.pushnotifications.parsers.** { *; }
-keep class com.connectycube.pushnotifications.model.** { *; }
-keep class com.connectycube.storage.parsers.** { *; }
-keep class com.connectycube.storage.model.** { *; }
-keep class org.jivesoftware.** { *; }
-dontwarn org.jivesoftware.smackx.**
-keep class org.webrtc.** { *; }

Related

Mockito.mock is not overriding the value of a called class in method

I have the following two classes
public class ClassA {
private String v1;
public String getV1() {
return v1;
}
public void setV1(String v1) {
this.v1 = v1;
}
}
public class ClassB {
public String op1(String val) {
ClassA ca = new ClassA();
ca.setV1(val);
return "Hello->" + ca.getV1();
}
}
Here is my testing code
import org.junit.Test;
import org.mockito.Mockito;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
public class ClassBTest {
#Test
public void testOp1() {
ClassA classA= Mockito.mock(ClassA.class);
when(classA.getV1()).thenReturn("TTT");
ClassB classB = new ClassB();
String out = classB.op1("dd");
System.out.println(out);
assertTrue(out.equalsIgnoreCase("Hello->TTT"));
}
}
I am not sure why the test is failing, the method classB.op1("dd"); is returning Hello->dd as if the mock is not being used, any idea?
I was able to resolve this issue by changing ClassB
public class ClassB {
private ClassA ca;
public String op1(ClassA caa) {
this. ca = caa;
ca.setV1("val");
return "Hello->" + ca.getV1();
}
}
and then for the test code
#Test
public void testOp1() {
ClassA classA= Mockito.mock(ClassA.class);
when(classA.getV1()).thenReturn("TTT");
ClassB classB = new ClassB();
String out = classB.op1(classA);
System.out.println(out);
assertTrue(out.equalsIgnoreCase("Hello->TTT"));
}

Mocking a singleton c# class in nunit

I have a class, something like this:-
namespace CalendarIntegration.Google
{
public sealed class GoogleSyncEventProcessor : ICalendarSyncEventProcessor
{
public void ProcessEventRequest(object events, int soUserId, string calendarId, bool addLogs = false)
{
if (GoogleWatchManager.Instance.IsGoogleTwoWaySynLive)
{
GoogleWatchManager is further a sealed class.
namespace CalendarIntegration.Google
{
public sealed class GoogleWatchManager
{
readonly bool isGoogleTwoWaySyncLive = true;
public GoogleWatchManager()
{
isGoogleTwoWaySyncLive = false;
}
virtual public bool IsGoogleTwoWaySynLive
{
get { return isGoogleTwoWaySyncLive; }
}
I want fake/mock GoogleWatchManager class and make the value of GoogleWatchManager.Instance.IsGoogleTwoWaySynLive in the nunit test cases, by default it is true in GoogleWatchManager class.
I tried the below but it doesn't work-
using EFBL;
using NUnit.Framework;
using EFBL.CalendarIntegration.CalendarSync;
using EFBL.CalendarIntegration.Google;
using Moq;
namespace EFBL.CalendarIntegration.Google
{
[TestFixture]
public class GoogleSyncEventProcessorSpec
{
public GoogleSyncEventProcessor google;
public GoogleWatchManager googleManager;
public void SetUp()
{
}
[Test]
public void ProcessEventRequest_NoEvents_ExceptionThrown()
{
var mock = new Mock<GoogleWatchManager>();
mock.SetupGet(foo => foo.IsGoogleTwoWaySynLive).Returns(true);
// watch.Setup(i => i.IsGoogleTwoWaySynLive).Returns(false);
// var mock = new Mock<GoogleWatchManager>().Object;
GoogleSyncEventProcessor obj = GoogleSyncEventProcessor.Instance;
obj.ProcessEventRequest(null, -1, "");
// isGoogleTwoWaySyncLive
}
}
}
Any help is highly appreciated, thanks in advance.
Here is the solution:-
using System;
using EFBL;
using NUnit.Framework;
using TypeMock.ArrangeActAssert;
using System.Diagnostics;
namespace EFBL.CalendarIntegration.Google
{
[TestFixture]
public class GoogleSyncEventProcessorSpec
{
public GoogleSyncEventProcessor googleSync;
public GoogleWatchManager googleManager;
[SetUp]
public void Init() {
googleManager = Isolate.Fake.Instance<GoogleWatchManager>();
googleSync = GoogleSyncEventProcessor.Instance;
}
[Test]
public void RequiresThatTwoWaySyncLiveBeFalse()
{
Isolate.NonPublic.Property.WhenGetCalled(googleManager, "IsGoogleTwoWaySynLive").WillReturn(false);
Assert.AreEqual(false, googleManager.IsGoogleTwoWaySynLive);
}

How do you pass parameters to the constructor when creating an anonymous class in D

I get how to create an anonymous class
class A {}
class B {
A anonymous = new class A { ... };
}
But if A has a constructor, and no default constructor.
class A {
init(string someArg) {
}
}
class B {
A anonymous = new class A { ... };???
}
How do I pass the parameter to that constructor?
Just implement a default constructor which calls the parent constructor with super:
class A
{
this(string someArg) {}
}
void main()
{
A anonyomus = new class A {
this()
{
super("Hello");
}
};
}
Another option is to not use an anonymous class and instead just define a nested one.
class A {
this(string someArg) {
}
}
void main() {
class not_really_anonymous : A {
this(string a) { super(a); }
}
A anonymous = new not_really_anonymous("arg");
}
Since you can define classes inside functions in D, you should be able to achieve basically the same thing with this technique. Then you define constructors like usual and new it like usual, just refer to the base class/interface when returning it.
class A {
this(string someArg) {}
}
class B {
A anonymous;
this() {
anonymous = new class A {
this() {
super("hello");
}
};
}
}
or
class A {
this(string someArg) { }
}
class B {
A anonymous;
this() {
anonymous = new class("hello") A {
this(T...)(T args) { super(args); }
};
}
}

Failing in Code coverage Test with a simple class constructor

I have a class:
public class SourceServerProvider : ISourceServerProvider
{
private readonly ISourceServer _sourceServer;
public SourceServerProvider()
:this(new SourceServer())
{ }
public SourceServerProvider(ISourceServer sourceServer)
{
_sourceServer = sourceServer;
}
}
MS code coverage test complaints to this block:
public SourceServerProvider()
:this(new SourceServer())
{ }
I don't know how to write a unit test for above block. Please advise..
I just tested it with the followig code:
public class SourceServerProvider : ISourceServerProvider
{
private readonly ISourceServer _sourceServer;
public SourceServerProvider()
: this(new SourceServer())
{ }
public SourceServerProvider(ISourceServer sourceServer)
{
_sourceServer = sourceServer;
}
}
public interface ISourceServer
{
}
public class SourceServer : ISourceServer
{
}
public interface ISourceServerProvider
{
}
and wrote this test
public class Class1
{
[Test]
public void test()
{
var a = new SourceServerProvider();
}
}
Code Coverage says it is fully covered:
so please add the result you are getting or create asimple test that call the default ctor

How to test DAL implemented using linq2sql and Repository pattern?

Here is a part of my DAL.
DataContext interface:
public interface IDataContextFactory
{
System.Data.Linq.DataContext Context { get; }
void SaveAll();
}
Here is my data context class which contains generated classes:
partial class InternetRailwayTicketSalesDataContext: DataContext, IDataContextFactory
{
public System.Data.Linq.DataContext Context
{
get { return this; }
}
public void SaveAll()
{
this.SubmitChanges();
}
}
Here is my Repository interface:
public interface IRepository<T> where T : class
{
/// <summary>
/// Return all instances of type T.
/// </summary>
/// <returns></returns>
IEnumerable<T> GetAll();
}
Here is my Repository interface implementation:
public class Repository<T> : IRepository<T> where T : class
{
protected IDataContextFactory _dataContextFactory;
/// <summary>
/// Return all instances of type T.
/// </summary>
/// <returns></returns>
public IEnumerable<T> GetAll()
{
return GetTable;
}
private System.Data.Linq.Table<T> GetTable
{
get { return _dataContextFactory.Context.GetTable<T>(); }
}
}
Here is an interface for concrete repository class:
interface IPasswayRepository
{
bool IsPasswayExists(int id);
}
And finally here is a concrete repository class implementation:
class PasswayRepository:Repository<Passway>, IPasswayRepository
{
public PasswayRepository(IDataContextFactory context)
: base(context)
{
}
public bool IsPasswayExists(int id)
{
if (GetAll().Where(pass => pass.Id == id && pass.IsDeleted == false).Count() > 0)
return true;
else
return false;
}
}
Can you give me an example of how to test IsPasswayExists method? (you can use any mock framework if you want to).