Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Mono.Android/Android.Runtime/JavaList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,7 @@ public virtual bool Add (Java.Lang.Object? item)

public virtual bool Add (int index, Java.Lang.Object? item)
{
if (Contains (item))
return false;
Add ((object?) item);
Insert (index, (object?) item);
return true;
}

Expand Down
32 changes: 32 additions & 0 deletions tests/Mono.Android-Tests/Java.Interop/JavaListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,38 @@ namespace Java.InteropTests
[SetUp]
public void Setup () => list = new T ();

[Test]
public void Add ()
{
list.Add ("foo");
Assert.AreEqual ("foo", list [0]);

// Ensure duplicates are allowed.
list.Add ("foo");
Assert.AreEqual (2, list.Count);
Assert.AreEqual ("foo", list [1]);
}

[Test]
public void AddWithIndex ()
{
list.Add ("Apple");
list.Add ("Banana");
list.Add ("Cherry");

// Ensure index is respected.
list.Add (3, "Grape");
list.Add (2, "Blueberry");
list.Add (4, "Fig");

Assert.AreEqual ("Apple", list [0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new test is failing on CI:

Expected is <System.String>, actual is <Java.Lang.ICharSequenceInvoker>
Values differ at index [0]
Expected: 'A'
But was:  'C'

The SubList() test is also failing:

Expected is <System.String>, actual is <Java.Lang.ICharSequenceInvoker>
Values differ at index [0]
Expected: 'f'
But was:  'b'

Very odd. :-(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Assert.AreEqual ("Banana", list [1]);
Assert.AreEqual ("Blueberry", list [2]);
Assert.AreEqual ("Cherry", list [3]);
Assert.AreEqual ("Fig", list [4]);
Assert.AreEqual ("Grape", list [5]);
}

[Test]
public void Count ()
{
Expand Down
Loading